@copilotkit/vue 1.83.0 → 1.84.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 (46) hide show
  1. package/PARITY.md +2 -2
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.mjs +2 -2
  4. package/dist/{use-render-activity-message-mQvByEYF.js → use-render-activity-message-CZKwtSEV.js} +5008 -5334
  5. package/dist/use-render-activity-message-CZKwtSEV.js.map +1 -0
  6. package/dist/use-render-activity-message-OOUHRzkd.cjs +66 -0
  7. package/dist/use-render-activity-message-OOUHRzkd.cjs.map +1 -0
  8. package/dist/v2/components/a2ui/A2UICatalogContext.d.ts.map +1 -1
  9. package/dist/v2/components/chat/CopilotChat.vue.d.ts +1 -1
  10. package/dist/v2/components/chat/CopilotChatView.vue.d.ts +1 -1
  11. package/dist/v2/components/chat/CopilotPopup.vue.d.ts +7 -2
  12. package/dist/v2/components/chat/CopilotPopup.vue.d.ts.map +1 -1
  13. package/dist/v2/components/chat/CopilotPopupView.vue.d.ts +4 -2
  14. package/dist/v2/components/chat/CopilotPopupView.vue.d.ts.map +1 -1
  15. package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts +4 -2
  16. package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts.map +1 -1
  17. package/dist/v2/components/chat/CopilotSidebar.vue.d.ts +7 -2
  18. package/dist/v2/components/chat/CopilotSidebar.vue.d.ts.map +1 -1
  19. package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts +4 -2
  20. package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts.map +1 -1
  21. package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts +4 -2
  22. package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts.map +1 -1
  23. package/dist/v2/components/chat/forwarded-slots.d.ts +12 -0
  24. package/dist/v2/components/chat/forwarded-slots.d.ts.map +1 -0
  25. package/dist/v2/components/chat/index.d.ts +16 -12
  26. package/dist/v2/components/chat/index.d.ts.map +1 -1
  27. package/dist/v2/components/chat/types.d.ts +7 -1
  28. package/dist/v2/components/chat/types.d.ts.map +1 -1
  29. package/dist/v2/index.cjs +1 -1
  30. package/dist/v2/index.mjs +1 -1
  31. package/dist/v2/providers/CopilotKitProvider.vue.d.ts +1 -1
  32. package/package.json +6 -6
  33. package/src/v2/components/a2ui/A2UICatalogContext.ts +14 -100
  34. package/src/v2/components/chat/CopilotPopup.vue +23 -25
  35. package/src/v2/components/chat/CopilotPopupView.vue +10 -39
  36. package/src/v2/components/chat/CopilotPopupViewInternal.vue +14 -34
  37. package/src/v2/components/chat/CopilotSidebar.vue +23 -25
  38. package/src/v2/components/chat/CopilotSidebarView.vue +10 -39
  39. package/src/v2/components/chat/CopilotSidebarViewInternal.vue +14 -34
  40. package/src/v2/components/chat/__tests__/CopilotPopup.test.ts +90 -1
  41. package/src/v2/components/chat/__tests__/CopilotSidebar.test.ts +90 -1
  42. package/src/v2/components/chat/forwarded-slots.ts +17 -0
  43. package/src/v2/components/chat/types.ts +8 -0
  44. package/dist/use-render-activity-message-B7sDGUl4.cjs +0 -70
  45. package/dist/use-render-activity-message-B7sDGUl4.cjs.map +0 -1
  46. package/dist/use-render-activity-message-mQvByEYF.js.map +0 -1
@@ -1,9 +1,11 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, useAttrs } from "vue";
3
3
  import CopilotChatConfigurationProvider from "../../providers/CopilotChatConfigurationProvider.vue";
4
+ import { forwardedSlotNames } from "./forwarded-slots";
4
5
  import CopilotSidebarViewInternal from "./CopilotSidebarViewInternal.vue";
5
6
  import type {
6
7
  CopilotChatFeatherSlotProps,
8
+ CopilotChatInterruptSlotProps,
7
9
  CopilotChatWelcomeScreenSlotProps,
8
10
  CopilotChatMessageViewSlotProps,
9
11
  CopilotChatScrollToBottomButtonSlotProps,
@@ -48,12 +50,16 @@ defineSlots<{
48
50
  "scroll-to-bottom-button"?: (
49
51
  props: CopilotChatScrollToBottomButtonSlotProps,
50
52
  ) => unknown;
53
+ interrupt?: (props: CopilotChatInterruptSlotProps) => unknown;
51
54
  input?: (props: CopilotSidebarWelcomeScreenInputSlotProps) => unknown;
52
55
  "suggestion-view"?: (
53
56
  props: CopilotSidebarWelcomeScreenSuggestionViewSlotProps,
54
57
  ) => unknown;
55
58
  "welcome-screen"?: (props: CopilotChatWelcomeScreenSlotProps) => unknown;
56
59
  "welcome-message"?: () => unknown;
60
+ // Any other slot goes to the chat view, as on CopilotChat.
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+ [key: string]: ((props: any) => unknown) | undefined;
57
63
  }>();
58
64
 
59
65
  const emit = defineEmits<{
@@ -115,47 +121,12 @@ const forwardedEventListeners = computed(() => {
115
121
  <template>
116
122
  <CopilotChatConfigurationProvider :is-modal-default-open="defaultOpen">
117
123
  <CopilotSidebarViewInternal v-bind="internalBindings">
118
- <template v-if="$slots.header" #header="slotProps">
119
- <slot name="header" v-bind="slotProps" />
120
- </template>
121
-
122
- <template v-if="$slots['toggle-button']" #toggle-button="slotProps">
123
- <slot name="toggle-button" v-bind="slotProps" />
124
- </template>
125
-
126
- <template v-if="$slots['message-view']" #message-view="slotProps">
127
- <slot name="message-view" v-bind="slotProps" />
128
- </template>
129
-
130
- <template v-if="$slots['scroll-view']" #scroll-view="slotProps">
131
- <slot name="scroll-view" v-bind="slotProps" />
132
- </template>
133
-
134
- <template v-if="$slots.feather" #feather="slotProps">
135
- <slot name="feather" v-bind="slotProps" />
136
- </template>
137
-
138
124
  <template
139
- v-if="$slots['scroll-to-bottom-button']"
140
- #scroll-to-bottom-button="slotProps"
125
+ v-for="slotName in forwardedSlotNames($slots)"
126
+ :key="slotName"
127
+ #[slotName]="slotProps"
141
128
  >
142
- <slot name="scroll-to-bottom-button" v-bind="slotProps" />
143
- </template>
144
-
145
- <template v-if="$slots.input" #input="slotProps">
146
- <slot name="input" v-bind="slotProps" />
147
- </template>
148
-
149
- <template v-if="$slots['suggestion-view']" #suggestion-view="slotProps">
150
- <slot name="suggestion-view" v-bind="slotProps" />
151
- </template>
152
-
153
- <template v-if="$slots['welcome-screen']" #welcome-screen="slotProps">
154
- <slot name="welcome-screen" v-bind="slotProps" />
155
- </template>
156
-
157
- <template v-if="$slots['welcome-message']" #welcome-message>
158
- <slot name="welcome-message" />
129
+ <slot :name="slotName" v-bind="slotProps" />
159
130
  </template>
160
131
  </CopilotSidebarViewInternal>
161
132
  </CopilotChatConfigurationProvider>
@@ -13,8 +13,10 @@ import { useCopilotChatConfiguration } from "../../providers/useCopilotChatConfi
13
13
  import CopilotChatToggleButton from "./CopilotChatToggleButton.vue";
14
14
  import CopilotChatView from "./CopilotChatView.vue";
15
15
  import CopilotModalHeader from "./CopilotModalHeader.vue";
16
+ import { forwardedSlotNames } from "./forwarded-slots";
16
17
  import type {
17
18
  CopilotChatFeatherSlotProps,
19
+ CopilotChatInterruptSlotProps,
18
20
  CopilotChatMessageViewSlotProps,
19
21
  CopilotChatScrollToBottomButtonSlotProps,
20
22
  CopilotChatScrollViewSlotProps,
@@ -57,14 +59,22 @@ defineSlots<{
57
59
  "scroll-to-bottom-button"?: (
58
60
  props: CopilotChatScrollToBottomButtonSlotProps,
59
61
  ) => unknown;
62
+ interrupt?: (props: CopilotChatInterruptSlotProps) => unknown;
60
63
  input?: (props: CopilotSidebarWelcomeScreenInputSlotProps) => unknown;
61
64
  "suggestion-view"?: (
62
65
  props: CopilotSidebarWelcomeScreenSuggestionViewSlotProps,
63
66
  ) => unknown;
64
67
  "welcome-screen"?: (props: CopilotChatWelcomeScreenSlotProps) => unknown;
65
68
  "welcome-message"?: () => unknown;
69
+ // Any other slot goes to the chat view, as on CopilotChat.
70
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
+ [key: string]: ((props: any) => unknown) | undefined;
66
72
  }>();
67
73
 
74
+ // Slots this component renders itself. It passes every other slot to the
75
+ // chat view.
76
+ const OWN_SLOTS = ["header", "toggle-button"] as const;
77
+
68
78
  const emit = defineEmits<{
69
79
  "submit-message": [value: string];
70
80
  stop: [];
@@ -310,42 +320,12 @@ onBeforeUnmount(() => {
310
320
  :on-finish-transcribe-with-audio="onFinishTranscribeWithAudio"
311
321
  v-bind="chatViewEventProps"
312
322
  >
313
- <template v-if="$slots['message-view']" #message-view="slotProps">
314
- <slot name="message-view" v-bind="slotProps" />
315
- </template>
316
-
317
- <template v-if="$slots['scroll-view']" #scroll-view="slotProps">
318
- <slot name="scroll-view" v-bind="slotProps" />
319
- </template>
320
-
321
- <template v-if="$slots.feather" #feather>
322
- <slot name="feather" />
323
- </template>
324
-
325
323
  <template
326
- v-if="$slots['scroll-to-bottom-button']"
327
- #scroll-to-bottom-button="slotProps"
324
+ v-for="slotName in forwardedSlotNames($slots, OWN_SLOTS)"
325
+ :key="slotName"
326
+ #[slotName]="slotProps"
328
327
  >
329
- <slot name="scroll-to-bottom-button" v-bind="slotProps" />
330
- </template>
331
-
332
- <template v-if="$slots.input" #input="slotProps">
333
- <slot name="input" v-bind="slotProps" />
334
- </template>
335
-
336
- <template
337
- v-if="$slots['suggestion-view']"
338
- #suggestion-view="slotProps"
339
- >
340
- <slot name="suggestion-view" v-bind="slotProps" />
341
- </template>
342
-
343
- <template v-if="$slots['welcome-screen']" #welcome-screen="slotProps">
344
- <slot name="welcome-screen" v-bind="slotProps" />
345
- </template>
346
-
347
- <template v-if="$slots['welcome-message']" #welcome-message>
348
- <slot name="welcome-message" />
328
+ <slot :name="slotName" v-bind="slotProps" />
349
329
  </template>
350
330
  </CopilotChatView>
351
331
  </div>
@@ -1,8 +1,9 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { h } from "vue";
2
+ import { h, nextTick } from "vue";
3
3
  import { mount } from "@vue/test-utils";
4
4
  import CopilotKitProvider from "../../../providers/CopilotKitProvider.vue";
5
5
  import { StateCapturingAgent } from "../../../__tests__/utils/agents";
6
+ import { mountWithProvider } from "../../../__tests__/utils/mount";
6
7
  import CopilotPopup from "../CopilotPopup.vue";
7
8
 
8
9
  function mountPopup(
@@ -55,4 +56,92 @@ describe("CopilotPopup", () => {
55
56
  ).toBe(true);
56
57
  expect(wrapper.find("[data-copilot-popup]").exists()).toBe(false);
57
58
  });
59
+
60
+ it("forwards the scroll-view slot to the chat view", () => {
61
+ const wrapper = mountPopup(
62
+ { welcomeScreen: false },
63
+ {
64
+ "scroll-view": ({ messages }: { messages: unknown[] }) =>
65
+ h(
66
+ "div",
67
+ { "data-testid": "custom-popup-scroll-view" },
68
+ String(messages.length),
69
+ ),
70
+ },
71
+ );
72
+
73
+ expect(wrapper.get("[data-testid='custom-popup-scroll-view']").text()).toBe(
74
+ "0",
75
+ );
76
+ expect(
77
+ wrapper.find("[data-testid='copilot-chat-view-scroll']").exists(),
78
+ ).toBe(false);
79
+ });
80
+
81
+ it("forwards the interrupt slot to the chat view", async () => {
82
+ const { wrapper, getCore } = mountWithProvider(
83
+ () =>
84
+ h(
85
+ CopilotPopup,
86
+ { welcomeScreen: false },
87
+ {
88
+ interrupt: ({ event }: { event: { value: string } }) =>
89
+ h("div", { "data-testid": "popup-interrupt" }, event.value),
90
+ },
91
+ ),
92
+ {
93
+ runtimeUrl: undefined,
94
+ agents__unsafe_dev_only: { default: new StateCapturingAgent() },
95
+ },
96
+ );
97
+
98
+ getCore().setInterruptState({
99
+ event: { name: "on_interrupt", value: "slot-forwarded" },
100
+ result: null,
101
+ resolve: () => undefined,
102
+ });
103
+ await nextTick();
104
+
105
+ expect(wrapper.get("[data-testid='popup-interrupt']").text()).toBe(
106
+ "slot-forwarded",
107
+ );
108
+ });
109
+
110
+ it("forwards the assistant-message slot to the message view", () => {
111
+ const agent = new StateCapturingAgent();
112
+ agent.setMessages([
113
+ { id: "assistant-1", role: "assistant", content: "Hello from the agent" },
114
+ ]);
115
+
116
+ const { wrapper } = mountWithProvider(
117
+ () =>
118
+ h(
119
+ CopilotPopup,
120
+ { welcomeScreen: false },
121
+ {
122
+ "assistant-message": ({
123
+ message,
124
+ }: {
125
+ message: { content: string };
126
+ }) =>
127
+ h(
128
+ "div",
129
+ { "data-testid": "popup-assistant-message" },
130
+ message.content,
131
+ ),
132
+ },
133
+ ),
134
+ {
135
+ runtimeUrl: undefined,
136
+ agents__unsafe_dev_only: { default: agent },
137
+ },
138
+ );
139
+
140
+ expect(wrapper.get("[data-testid='popup-assistant-message']").text()).toBe(
141
+ "Hello from the agent",
142
+ );
143
+ expect(
144
+ wrapper.find("[data-testid='copilot-assistant-message']").exists(),
145
+ ).toBe(false);
146
+ });
58
147
  });
@@ -1,8 +1,9 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { h } from "vue";
2
+ import { h, nextTick } from "vue";
3
3
  import { mount } from "@vue/test-utils";
4
4
  import CopilotKitProvider from "../../../providers/CopilotKitProvider.vue";
5
5
  import { StateCapturingAgent } from "../../../__tests__/utils/agents";
6
+ import { mountWithProvider } from "../../../__tests__/utils/mount";
6
7
  import CopilotSidebar from "../CopilotSidebar.vue";
7
8
 
8
9
  function mountSidebar(
@@ -55,4 +56,92 @@ describe("CopilotSidebar", () => {
55
56
  ).toBe(true);
56
57
  expect(wrapper.find("[data-copilot-sidebar]").exists()).toBe(false);
57
58
  });
59
+
60
+ it("forwards the scroll-view slot to the chat view", () => {
61
+ const wrapper = mountSidebar(
62
+ { welcomeScreen: false },
63
+ {
64
+ "scroll-view": ({ messages }: { messages: unknown[] }) =>
65
+ h(
66
+ "div",
67
+ { "data-testid": "custom-sidebar-scroll-view" },
68
+ String(messages.length),
69
+ ),
70
+ },
71
+ );
72
+
73
+ expect(
74
+ wrapper.get("[data-testid='custom-sidebar-scroll-view']").text(),
75
+ ).toBe("0");
76
+ expect(
77
+ wrapper.find("[data-testid='copilot-chat-view-scroll']").exists(),
78
+ ).toBe(false);
79
+ });
80
+
81
+ it("forwards the interrupt slot to the chat view", async () => {
82
+ const { wrapper, getCore } = mountWithProvider(
83
+ () =>
84
+ h(
85
+ CopilotSidebar,
86
+ { welcomeScreen: false },
87
+ {
88
+ interrupt: ({ event }: { event: { value: string } }) =>
89
+ h("div", { "data-testid": "sidebar-interrupt" }, event.value),
90
+ },
91
+ ),
92
+ {
93
+ runtimeUrl: undefined,
94
+ agents__unsafe_dev_only: { default: new StateCapturingAgent() },
95
+ },
96
+ );
97
+
98
+ getCore().setInterruptState({
99
+ event: { name: "on_interrupt", value: "slot-forwarded" },
100
+ result: null,
101
+ resolve: () => undefined,
102
+ });
103
+ await nextTick();
104
+
105
+ expect(wrapper.get("[data-testid='sidebar-interrupt']").text()).toBe(
106
+ "slot-forwarded",
107
+ );
108
+ });
109
+
110
+ it("forwards the assistant-message slot to the message view", () => {
111
+ const agent = new StateCapturingAgent();
112
+ agent.setMessages([
113
+ { id: "assistant-1", role: "assistant", content: "Hello from the agent" },
114
+ ]);
115
+
116
+ const { wrapper } = mountWithProvider(
117
+ () =>
118
+ h(
119
+ CopilotSidebar,
120
+ { welcomeScreen: false },
121
+ {
122
+ "assistant-message": ({
123
+ message,
124
+ }: {
125
+ message: { content: string };
126
+ }) =>
127
+ h(
128
+ "div",
129
+ { "data-testid": "sidebar-assistant-message" },
130
+ message.content,
131
+ ),
132
+ },
133
+ ),
134
+ {
135
+ runtimeUrl: undefined,
136
+ agents__unsafe_dev_only: { default: agent },
137
+ },
138
+ );
139
+
140
+ expect(
141
+ wrapper.get("[data-testid='sidebar-assistant-message']").text(),
142
+ ).toBe("Hello from the agent");
143
+ expect(
144
+ wrapper.find("[data-testid='copilot-assistant-message']").exists(),
145
+ ).toBe(false);
146
+ });
58
147
  });
@@ -0,0 +1,17 @@
1
+ import type { Slots } from "vue";
2
+
3
+ /**
4
+ * Returns the names of the slots that a wrapper passes on to the component it
5
+ * wraps: every slot in `slots` except the ones in `ownSlots`, which the
6
+ * wrapper renders itself.
7
+ *
8
+ * CopilotChat passes every slot except `chat-view` to CopilotChatView.
9
+ * CopilotSidebar, CopilotPopup, and their view components use this rule at
10
+ * each layer, so a slot that works on CopilotChat also works on them.
11
+ */
12
+ export function forwardedSlotNames(
13
+ slots: Slots,
14
+ ownSlots: readonly string[] = [],
15
+ ): string[] {
16
+ return Object.keys(slots).filter((name) => !ownSlots.includes(name));
17
+ }
@@ -116,7 +116,15 @@ export interface CopilotChatProps extends Omit<
116
116
  | "onStartTranscribe"
117
117
  | "onCancelTranscribe"
118
118
  | "onFinishTranscribe"
119
+ // Redeclared below, deprecated: the chat sets it from its own state
120
+ | "inputMode"
119
121
  > {
122
+ /**
123
+ * @deprecated Has no effect. `CopilotChat` sets the input mode from its own
124
+ * transcription state. To set it yourself, render `CopilotChatView` and pass
125
+ * `inputMode` there.
126
+ */
127
+ inputMode?: CopilotChatInputMode;
120
128
  agentId?: string;
121
129
  threadId?: string;
122
130
  throttleMs?: number;