@copilotkit/vue 1.68.3 → 1.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PARITY.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{use-render-activity-message-DljRBrXN.js → use-render-activity-message-BQADVWev.js} +2242 -2193
- package/dist/use-render-activity-message-BQADVWev.js.map +1 -0
- package/dist/{use-render-activity-message-bkrPa-92.cjs → use-render-activity-message-DYb_lsQs.cjs} +22 -22
- package/dist/use-render-activity-message-DYb_lsQs.cjs.map +1 -0
- package/dist/v2/components/chat/CopilotChatToolCallItem.vue.d.ts +21 -0
- package/dist/v2/components/chat/CopilotChatToolCallItem.vue.d.ts.map +1 -0
- package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts +10 -0
- package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts.map +1 -0
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.mjs +1 -1
- package/package.json +5 -5
- package/src/v2/components/chat/CopilotChatToolCallItem.vue +86 -0
- package/src/v2/components/chat/CopilotChatToolCallsView.vue +24 -136
- package/src/v2/components/chat/__tests__/CopilotChatToolCallsView.test.ts +302 -1
- package/src/v2/components/chat/__tests__/CopilotThreadsDrawer.ssr.test.ts +1 -1
- package/src/v2/components/chat/copilotChatToolCallItemRender.ts +126 -0
- package/dist/use-render-activity-message-DljRBrXN.js.map +0 -1
- package/dist/use-render-activity-message-bkrPa-92.cjs.map +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Message, ToolCall } from "@ag-ui/core";
|
|
2
|
+
import type { CopilotChatToolCallRenderSlotProps } from "./types";
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
toolCall: ToolCall;
|
|
5
|
+
messages?: Message[];
|
|
6
|
+
};
|
|
7
|
+
type __VLS_Slots = {
|
|
8
|
+
"tool-call"?: (props: CopilotChatToolCallRenderSlotProps) => unknown;
|
|
9
|
+
[key: `tool-call-${string}`]: (props: CopilotChatToolCallRenderSlotProps) => unknown;
|
|
10
|
+
};
|
|
11
|
+
declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
12
|
+
messages: Message[];
|
|
13
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
|
+
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
15
|
+
export default _default;
|
|
16
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
17
|
+
new (): {
|
|
18
|
+
$slots: S;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=CopilotChatToolCallItem.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopilotChatToolCallItem.vue.d.ts","sourceRoot":"","sources":["../../../../src/v2/components/chat/CopilotChatToolCallItem.vue"],"names":[],"mappings":"AAwFA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIrD,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,SAAS,CAAC;AASlE,KAAK,WAAW,GAAG;IACf,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACtB,CAAC;AAQJ,KAAK,WAAW,GAAG;IACjB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,kCAAkC,KAAK,OAAO,CAAC;IACrE,CAAC,GAAG,EAAE,aAAa,MAAM,EAAE,GAAG,CAC5B,KAAK,EAAE,kCAAkC,KACtC,OAAO,CAAC;CACd,CAAC;AA6FF,QAAA,MAAM,eAAe;cA3GN,OAAO,EAAE;6EAkHtB,CAAC;wBACkB,eAAe,CAAC,OAAO,eAAe,EAAE,WAAW,CAAC;AAAzE,wBAA0E;AAa1E,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CopilotChatToolCallsView.vue.d.ts","sourceRoot":"","sources":["../../../../src/v2/components/chat/CopilotChatToolCallsView.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CopilotChatToolCallsView.vue.d.ts","sourceRoot":"","sources":["../../../../src/v2/components/chat/CopilotChatToolCallsView.vue"],"names":[],"mappings":"AAoDA,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,SAAS,CAAC;AAGlE,KAAK,WAAW,GAAG;IACf,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACtB,CAAC;AAQJ,KAAK,WAAW,GAAG;IACjB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,kCAAkC,KAAK,OAAO,CAAC;IACrE,CAAC,GAAG,EAAE,aAAa,MAAM,EAAE,GAAG,CAC5B,KAAK,EAAE,kCAAkC,KACtC,OAAO,CAAC;CACd,CAAC;AAoEF,QAAA,MAAM,eAAe;cAlFN,OAAO,EAAE;6EAyFtB,CAAC;wBACkB,eAAe,CAAC,OAAO,eAAe,EAAE,WAAW,CAAC;AAAzE,wBAA0E;AAa1E,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Message, ToolCall, ToolMessage } from "@ag-ui/core";
|
|
2
|
+
import type { CopilotChatToolCallRenderSlotProps } from "./types";
|
|
3
|
+
import type { VueToolCallRenderer, VueToolCallRendererRenderProps } from "../../types";
|
|
4
|
+
export declare function findToolMessage(messages: Message[], toolCallId: string): ToolMessage | undefined;
|
|
5
|
+
export declare function getToolCallSlotName(toolName: string): `tool-call-${string}`;
|
|
6
|
+
export declare function getCoreRenderConfig(toolCall: ToolCall, renderToolCalls: readonly VueToolCallRenderer<unknown>[], agentId: string): VueToolCallRenderer<unknown> | undefined;
|
|
7
|
+
export declare function getToolCallRenderProps(toolCall: ToolCall, messages: Message[], executingToolCallIds: ReadonlySet<string>): CopilotChatToolCallRenderSlotProps;
|
|
8
|
+
export declare function getCoreRenderProps(toolCall: ToolCall, messages: Message[], executingToolCallIds: ReadonlySet<string>): VueToolCallRendererRenderProps<unknown>;
|
|
9
|
+
export declare function getToolCallMemoDeps(toolCall: ToolCall, messages: Message[], executingToolCallIds: ReadonlySet<string>, renderToolCalls: readonly VueToolCallRenderer<unknown>[], agentId?: string): unknown[];
|
|
10
|
+
//# sourceMappingURL=copilotChatToolCallItemRender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilotChatToolCallItemRender.d.ts","sourceRoot":"","sources":["../../../../src/v2/components/chat/copilotChatToolCallItemRender.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAIlE,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,KAAK,EACV,mBAAmB,EACnB,8BAA8B,EAC/B,MAAM,aAAa,CAAC;AAErB,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO,EAAE,EACnB,UAAU,EAAE,MAAM,GACjB,WAAW,GAAG,SAAS,CAMzB;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,MAAM,EAAE,CAE3E;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,SAAS,mBAAmB,CAAC,OAAO,CAAC,EAAE,EACxD,OAAO,EAAE,MAAM,GACd,mBAAmB,CAAC,OAAO,CAAC,GAAG,SAAS,CAW1C;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,OAAO,EAAE,EACnB,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAC,GACxC,kCAAkC,CAwBpC;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,OAAO,EAAE,EACnB,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAC,GACxC,8BAA8B,CAAC,OAAO,CAAC,CAgCzC;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,OAAO,EAAE,EACnB,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAC,EACzC,eAAe,EAAE,SAAS,mBAAmB,CAAC,OAAO,CAAC,EAAE,EACxD,OAAO,GAAE,MAAyB,GACjC,OAAO,EAAE,CASX"}
|
package/dist/v2/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@copilotkit/core"),i=require("@ag-ui/client"),e=require("../use-render-activity-message-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@copilotkit/core"),i=require("@ag-ui/client"),e=require("../use-render-activity-message-DYb_lsQs.cjs"),n=require("@copilotkit/shared");exports.A2UIActivityContentSchema=e.A2UIActivityContentSchema;exports.A2UISurfaceActivityRenderer=e._sfc_main;exports.A2UISurfaceActivityType=e.A2UISurfaceActivityType;exports.CopilotChat=e.CopilotChat;exports.CopilotChatAssistantMessage=e._sfc_main$1;exports.CopilotChatAttachmentQueue=e._sfc_main$2;exports.CopilotChatAttachmentRenderer=e._sfc_main$3;exports.CopilotChatAudioRecorder=e._sfc_main$4;exports.CopilotChatConfigurationProvider=e._sfc_main$5;exports.CopilotChatDefaultLabels=e.CopilotChatDefaultLabels;exports.CopilotChatInput=e._sfc_main$6;exports.CopilotChatMessageView=e._sfc_main$7;exports.CopilotChatReasoningMessage=e._sfc_main$8;exports.CopilotChatSuggestionPill=e._sfc_main$9;exports.CopilotChatSuggestionView=e._sfc_main$10;exports.CopilotChatToggleButton=e.CopilotChatToggleButton;exports.CopilotChatToggleButtonCloseIcon=e.CopilotChatToggleButtonCloseIcon;exports.CopilotChatToggleButtonOpenIcon=e.CopilotChatToggleButtonOpenIcon;exports.CopilotChatToolCallsView=e._sfc_main$11;exports.CopilotChatUserMessage=e._sfc_main$12;exports.CopilotChatView=e._sfc_main$13;exports.CopilotKitCoreVue=e.CopilotKitCoreVue;exports.CopilotKitInspector=e._sfc_main$14;exports.CopilotKitProvider=e._sfc_main$15;exports.CopilotModalHeader=e.CopilotModalHeader;exports.CopilotPopup=e._sfc_main$16;exports.CopilotPopupView=e.CopilotPopupView;exports.CopilotSidebar=e._sfc_main$17;exports.CopilotSidebarView=e.CopilotSidebarView;exports.CopilotThreadsDrawer=e._sfc_main$18;exports.GenerateSandboxedUiArgsSchema=e.GenerateSandboxedUiArgsSchema;exports.LicenseContextKey=e.LicenseContextKey;exports.MCPAppsActivityContentSchema=e.MCPAppsActivityContentSchema;exports.MCPAppsActivityRenderer=e.MCPAppsActivityRenderer;exports.MCPAppsActivityType=e.MCPAppsActivityType;exports.OpenGenerativeUIActivityRenderer=e.OpenGenerativeUIActivityRenderer;exports.OpenGenerativeUIActivityType=e.OpenGenerativeUIActivityType;exports.OpenGenerativeUIContentSchema=e.OpenGenerativeUIContentSchema;exports.OpenGenerativeUIRenderer=e.OpenGenerativeUIRenderer;exports.OpenGenerativeUIToolRenderer=e.OpenGenerativeUIToolRenderer;exports.UseAgentUpdate=e.UseAgentUpdate;exports.createA2UIMessageRenderer=e.createA2UIMessageRenderer;exports.createDefaultLicenseRef=e.createDefaultLicenseRef;exports.defineToolCallRenderer=e.defineToolCallRenderer;exports.extractCompleteStyles=e.extractCompleteStyles;exports.getOperationSurfaceId=e.getOperationSurfaceId;exports.processPartialHtml=e.processPartialHtml;exports.useAgent=e.useAgent;exports.useAgentContext=e.useAgentContext;exports.useAttachments=e.useAttachments;exports.useCapabilities=e.useCapabilities;exports.useComponent=e.useComponent;exports.useConfigureSuggestions=e.useConfigureSuggestions;exports.useCopilotChatConfiguration=e.useCopilotChatConfiguration;exports.useCopilotKit=e.useCopilotKit;exports.useDefaultRenderTool=e.useDefaultRenderTool;exports.useFrontendTool=e.useFrontendTool;exports.useHumanInTheLoop=e.useHumanInTheLoop;exports.useInterrupt=e.useInterrupt;exports.useKatexStyles=e.useKatexStyles;exports.useKeyboardHeight=e.useKeyboardHeight;exports.useLicenseContext=e.useLicenseContext;exports.useRenderActivityMessage=e.useRenderActivityMessage;exports.useRenderCustomMessages=e.useRenderCustomMessages;exports.useRenderTool=e.useRenderTool;exports.useSandboxFunctions=e.useSandboxFunctions;exports.useSuggestions=e.useSuggestions;exports.useThreads=e.useThreads;exports.vueBasicCatalog=e.vueBasicCatalog;Object.defineProperty(exports,"createLicenseContextValue",{enumerable:!0,get:()=>n.createLicenseContextValue});Object.keys(o).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>o[t]})});Object.keys(i).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>i[t]})});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/v2/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "@copilotkit/core";
|
|
2
2
|
export * from "@ag-ui/client";
|
|
3
|
-
import { A as o, _ as i, a as n, C, b as r, c as p, d as l, e as u, f as c, g, h as d, i as h, j as A, k as v, l as S, m, n as y, o as I, p as f, q as R, r as T, s as U, t as x, u as M, v as P, w as b, x as V, y as w, z as K, B as O, G, L, M as B, D, E as H, O as F, F as Q, H as j, I as k, J as q, U as z, K as E, N as J, P as N, Q as W, R as X, S as Y, T as Z, V as _, W as $, X as ee, Y as ae, Z as te, $ as se, a0 as oe, a1 as ie, a2 as ne, a3 as Ce, a4 as re, a5 as pe, a6 as le, a7 as ue, a8 as ce, a9 as ge, aa as de, ab as he, ac as Ae, ad as ve, ae as Se } from "../use-render-activity-message-
|
|
3
|
+
import { A as o, _ as i, a as n, C, b as r, c as p, d as l, e as u, f as c, g, h as d, i as h, j as A, k as v, l as S, m, n as y, o as I, p as f, q as R, r as T, s as U, t as x, u as M, v as P, w as b, x as V, y as w, z as K, B as O, G, L, M as B, D, E as H, O as F, F as Q, H as j, I as k, J as q, U as z, K as E, N as J, P as N, Q as W, R as X, S as Y, T as Z, V as _, W as $, X as ee, Y as ae, Z as te, $ as se, a0 as oe, a1 as ie, a2 as ne, a3 as Ce, a4 as re, a5 as pe, a6 as le, a7 as ue, a8 as ce, a9 as ge, aa as de, ab as he, ac as Ae, ad as ve, ae as Se } from "../use-render-activity-message-BQADVWev.js";
|
|
4
4
|
import { createLicenseContextValue as ye } from "@copilotkit/shared";
|
|
5
5
|
export {
|
|
6
6
|
o as A2UIActivityContentSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.69.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Vue 3 components and composables for CopilotKit",
|
|
6
6
|
"keywords": [
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"streamdown-vue": "^1.0.29",
|
|
71
71
|
"zod": "^3.25.75",
|
|
72
72
|
"zod-to-json-schema": "^3.24.5",
|
|
73
|
-
"@copilotkit/
|
|
74
|
-
"@copilotkit/
|
|
75
|
-
"@copilotkit/web-
|
|
76
|
-
"@copilotkit/
|
|
73
|
+
"@copilotkit/shared": "1.69.0",
|
|
74
|
+
"@copilotkit/web-components": "1.69.0",
|
|
75
|
+
"@copilotkit/web-inspector": "1.69.0",
|
|
76
|
+
"@copilotkit/core": "1.69.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@eslint/js": "^9.39.2",
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { Message, ToolCall } from "@ag-ui/core";
|
|
3
|
+
import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
|
|
4
|
+
import { useCopilotKit } from "../../providers/useCopilotKit";
|
|
5
|
+
import { useCopilotChatConfiguration } from "../../providers/useCopilotChatConfiguration";
|
|
6
|
+
import type { CopilotChatToolCallRenderSlotProps } from "./types";
|
|
7
|
+
import {
|
|
8
|
+
getCoreRenderConfig,
|
|
9
|
+
getCoreRenderProps,
|
|
10
|
+
getToolCallMemoDeps,
|
|
11
|
+
getToolCallRenderProps,
|
|
12
|
+
getToolCallSlotName,
|
|
13
|
+
} from "./copilotChatToolCallItemRender";
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(
|
|
16
|
+
defineProps<{
|
|
17
|
+
toolCall: ToolCall;
|
|
18
|
+
messages?: Message[];
|
|
19
|
+
}>(),
|
|
20
|
+
{
|
|
21
|
+
messages: () => [],
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
defineSlots<{
|
|
26
|
+
"tool-call"?: (props: CopilotChatToolCallRenderSlotProps) => unknown;
|
|
27
|
+
[key: `tool-call-${string}`]: (
|
|
28
|
+
props: CopilotChatToolCallRenderSlotProps,
|
|
29
|
+
) => unknown;
|
|
30
|
+
}>();
|
|
31
|
+
|
|
32
|
+
const { copilotkit, executingToolCallIds } = useCopilotKit();
|
|
33
|
+
const config = useCopilotChatConfiguration();
|
|
34
|
+
|
|
35
|
+
function getRenderProps(): CopilotChatToolCallRenderSlotProps {
|
|
36
|
+
return getToolCallRenderProps(
|
|
37
|
+
props.toolCall,
|
|
38
|
+
props.messages,
|
|
39
|
+
executingToolCallIds.value,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getCoreProps() {
|
|
44
|
+
return getCoreRenderProps(
|
|
45
|
+
props.toolCall,
|
|
46
|
+
props.messages,
|
|
47
|
+
executingToolCallIds.value,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getRenderConfig() {
|
|
52
|
+
const agentId = config.value?.agentId ?? DEFAULT_AGENT_ID;
|
|
53
|
+
return getCoreRenderConfig(
|
|
54
|
+
props.toolCall,
|
|
55
|
+
copilotkit.value.renderToolCalls,
|
|
56
|
+
agentId,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getMemoDeps() {
|
|
61
|
+
const agentId = config.value?.agentId ?? DEFAULT_AGENT_ID;
|
|
62
|
+
return getToolCallMemoDeps(
|
|
63
|
+
props.toolCall,
|
|
64
|
+
props.messages,
|
|
65
|
+
executingToolCallIds.value,
|
|
66
|
+
copilotkit.value.renderToolCalls,
|
|
67
|
+
agentId,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<template>
|
|
73
|
+
<slot
|
|
74
|
+
:name="getToolCallSlotName(toolCall.function.name)"
|
|
75
|
+
v-bind="getRenderProps()"
|
|
76
|
+
>
|
|
77
|
+
<slot name="tool-call" v-bind="getRenderProps()">
|
|
78
|
+
<component
|
|
79
|
+
:is="getRenderConfig()?.render"
|
|
80
|
+
v-if="getRenderConfig()"
|
|
81
|
+
v-memo="getMemoDeps()"
|
|
82
|
+
v-bind="getCoreProps()"
|
|
83
|
+
/>
|
|
84
|
+
</slot>
|
|
85
|
+
</slot>
|
|
86
|
+
</template>
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
Message,
|
|
5
|
-
ToolCall,
|
|
6
|
-
ToolMessage,
|
|
7
|
-
} from "@ag-ui/core";
|
|
8
|
-
import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
|
|
9
|
-
import { ToolCallStatus } from "@copilotkit/core";
|
|
10
|
-
import { partialJSONParse } from "@copilotkit/shared";
|
|
11
|
-
import { useCopilotKit } from "../../providers/useCopilotKit";
|
|
12
|
-
import { useCopilotChatConfiguration } from "../../providers/useCopilotChatConfiguration";
|
|
2
|
+
import { useSlots } from "vue";
|
|
3
|
+
import type { AssistantMessage, Message } from "@ag-ui/core";
|
|
13
4
|
import type { CopilotChatToolCallRenderSlotProps } from "./types";
|
|
14
|
-
import
|
|
15
|
-
import type { VueToolCallRendererRenderProps } from "../../types";
|
|
5
|
+
import CopilotChatToolCallItem from "./CopilotChatToolCallItem.vue";
|
|
16
6
|
|
|
17
|
-
|
|
7
|
+
withDefaults(
|
|
18
8
|
defineProps<{
|
|
19
9
|
message: AssistantMessage;
|
|
20
10
|
messages?: Message[];
|
|
@@ -31,131 +21,29 @@ defineSlots<{
|
|
|
31
21
|
) => unknown;
|
|
32
22
|
}>();
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
(message as ToolMessage).toolCallId === toolCallId,
|
|
42
|
-
) as ToolMessage | undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getSlotName(toolName: string): `tool-call-${string}` {
|
|
46
|
-
return `tool-call-${toolName}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function isExecutingToolCall(toolCallId: string): boolean {
|
|
50
|
-
return executingToolCallIds.value.has(toolCallId);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getToolResultContent(toolCallId: string): string | undefined {
|
|
54
|
-
return findToolMessage(toolCallId)?.content;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function getRenderProps(
|
|
58
|
-
toolCall: ToolCall,
|
|
59
|
-
): CopilotChatToolCallRenderSlotProps {
|
|
60
|
-
const toolMessage = findToolMessage(toolCall.id);
|
|
61
|
-
const parsedArgs = partialJSONParse(toolCall.function.arguments);
|
|
62
|
-
|
|
63
|
-
if (toolMessage) {
|
|
64
|
-
return {
|
|
65
|
-
name: toolCall.function.name,
|
|
66
|
-
args: parsedArgs,
|
|
67
|
-
status: ToolCallStatus.Complete,
|
|
68
|
-
result: toolMessage.content,
|
|
69
|
-
toolCall,
|
|
70
|
-
toolMessage,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const isExecuting = isExecutingToolCall(toolCall.id);
|
|
75
|
-
return {
|
|
76
|
-
name: toolCall.function.name,
|
|
77
|
-
args: parsedArgs,
|
|
78
|
-
status: isExecuting ? ToolCallStatus.Executing : ToolCallStatus.InProgress,
|
|
79
|
-
result: undefined,
|
|
80
|
-
toolCall,
|
|
81
|
-
toolMessage: undefined,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function getCoreRenderProps(
|
|
86
|
-
toolCall: ToolCall,
|
|
87
|
-
): VueToolCallRendererRenderProps<unknown> {
|
|
88
|
-
const toolMessage = findToolMessage(toolCall.id);
|
|
89
|
-
const parsedArgs = partialJSONParse(toolCall.function.arguments);
|
|
90
|
-
|
|
91
|
-
if (toolMessage) {
|
|
92
|
-
return {
|
|
93
|
-
name: toolCall.function.name,
|
|
94
|
-
toolCallId: toolCall.id,
|
|
95
|
-
args: parsedArgs,
|
|
96
|
-
status: ToolCallStatus.Complete,
|
|
97
|
-
result: toolMessage.content,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const isExecuting = isExecutingToolCall(toolCall.id);
|
|
102
|
-
if (isExecuting) {
|
|
103
|
-
return {
|
|
104
|
-
name: toolCall.function.name,
|
|
105
|
-
toolCallId: toolCall.id,
|
|
106
|
-
args: parsedArgs,
|
|
107
|
-
status: ToolCallStatus.Executing,
|
|
108
|
-
result: undefined,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
name: toolCall.function.name,
|
|
114
|
-
toolCallId: toolCall.id,
|
|
115
|
-
args: parsedArgs && typeof parsedArgs === "object" ? parsedArgs : {},
|
|
116
|
-
status: ToolCallStatus.InProgress,
|
|
117
|
-
result: undefined,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function getCoreRenderConfig(
|
|
122
|
-
toolCall: ToolCall,
|
|
123
|
-
): VueToolCallRenderer<unknown> | undefined {
|
|
124
|
-
const renderToolCalls = copilotkit.value.renderToolCalls;
|
|
125
|
-
const agentId = config.value?.agentId ?? DEFAULT_AGENT_ID;
|
|
126
|
-
const exactMatches = renderToolCalls.filter(
|
|
127
|
-
(renderConfig) => renderConfig.name === toolCall.function.name,
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
return (
|
|
131
|
-
exactMatches.find((renderConfig) => renderConfig.agentId === agentId) ??
|
|
132
|
-
exactMatches.find((renderConfig) => !renderConfig.agentId) ??
|
|
133
|
-
exactMatches[0] ??
|
|
134
|
-
renderToolCalls.find((renderConfig) => renderConfig.name === "*")
|
|
135
|
-
);
|
|
24
|
+
type ToolCallSlotName = "tool-call" | `tool-call-${string}`;
|
|
25
|
+
const componentSlots = useSlots() as Record<
|
|
26
|
+
ToolCallSlotName,
|
|
27
|
+
(props?: unknown) => unknown
|
|
28
|
+
>;
|
|
29
|
+
function getForwardedSlotNames(): ToolCallSlotName[] {
|
|
30
|
+
return Object.keys(componentSlots) as ToolCallSlotName[];
|
|
136
31
|
}
|
|
137
32
|
</script>
|
|
138
33
|
|
|
139
34
|
<template>
|
|
140
|
-
<
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
35
|
+
<CopilotChatToolCallItem
|
|
36
|
+
v-for="toolCall in message.toolCalls ?? []"
|
|
37
|
+
:key="toolCall.id"
|
|
38
|
+
:tool-call="toolCall"
|
|
39
|
+
:messages="messages"
|
|
40
|
+
>
|
|
41
|
+
<template
|
|
42
|
+
v-for="slotName in getForwardedSlotNames()"
|
|
43
|
+
:key="slotName"
|
|
44
|
+
#[slotName]="slotProps"
|
|
144
45
|
>
|
|
145
|
-
<slot name="
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
v-if="getCoreRenderConfig(toolCall)"
|
|
149
|
-
v-bind="getCoreRenderProps(toolCall)"
|
|
150
|
-
v-memo="[
|
|
151
|
-
toolCall.id,
|
|
152
|
-
toolCall.function.arguments,
|
|
153
|
-
getToolResultContent(toolCall.id),
|
|
154
|
-
isExecutingToolCall(toolCall.id),
|
|
155
|
-
getCoreRenderConfig(toolCall)?.render,
|
|
156
|
-
]"
|
|
157
|
-
/>
|
|
158
|
-
</slot>
|
|
159
|
-
</slot>
|
|
160
|
-
</template>
|
|
46
|
+
<slot :name="slotName" v-bind="slotProps ?? {}" />
|
|
47
|
+
</template>
|
|
48
|
+
</CopilotChatToolCallItem>
|
|
161
49
|
</template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { defineComponent, h } from "vue";
|
|
2
|
+
import { defineComponent, h, nextTick, ref } from "vue";
|
|
3
3
|
import { mount } from "@vue/test-utils";
|
|
4
4
|
import type { AssistantMessage, Message, ToolMessage } from "@ag-ui/core";
|
|
5
5
|
import CopilotKitProvider from "../../../providers/CopilotKitProvider.vue";
|
|
@@ -252,6 +252,307 @@ describe("CopilotChatToolCallsView", () => {
|
|
|
252
252
|
);
|
|
253
253
|
});
|
|
254
254
|
|
|
255
|
+
it("updates generic consumer-provided tool-call slots when parent state changes", async () => {
|
|
256
|
+
const message = baseAssistantMessage();
|
|
257
|
+
const label = ref("first");
|
|
258
|
+
const Harness = defineComponent({
|
|
259
|
+
setup() {
|
|
260
|
+
return () => {
|
|
261
|
+
const currentLabel = label.value;
|
|
262
|
+
return h(
|
|
263
|
+
CopilotChatToolCallsView,
|
|
264
|
+
{ message, messages: [message] },
|
|
265
|
+
{
|
|
266
|
+
"tool-call": () =>
|
|
267
|
+
h("div", { "data-testid": "slot-label" }, currentLabel),
|
|
268
|
+
},
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const wrapper = mount(CopilotKitProvider, {
|
|
275
|
+
props: { runtimeUrl: "/api/copilotkit" },
|
|
276
|
+
slots: {
|
|
277
|
+
default: () =>
|
|
278
|
+
h(
|
|
279
|
+
CopilotChatConfigurationProvider,
|
|
280
|
+
{ threadId: "thread-1", agentId: "default" },
|
|
281
|
+
{ default: () => h(Harness) },
|
|
282
|
+
),
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
expect(wrapper.get("[data-testid='slot-label']").text()).toBe("first");
|
|
287
|
+
label.value = "second";
|
|
288
|
+
await nextTick();
|
|
289
|
+
expect(wrapper.get("[data-testid='slot-label']").text()).toBe("second");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("updates exact consumer-provided tool-call slots when parent state changes", async () => {
|
|
293
|
+
const message = baseAssistantMessage();
|
|
294
|
+
const label = ref("first");
|
|
295
|
+
const Harness = defineComponent({
|
|
296
|
+
setup() {
|
|
297
|
+
return () => {
|
|
298
|
+
const currentLabel = label.value;
|
|
299
|
+
return h(
|
|
300
|
+
CopilotChatToolCallsView,
|
|
301
|
+
{ message, messages: [message] },
|
|
302
|
+
{
|
|
303
|
+
"tool-call-search_docs": () =>
|
|
304
|
+
h("div", { "data-testid": "slot-label" }, currentLabel),
|
|
305
|
+
},
|
|
306
|
+
);
|
|
307
|
+
};
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
const wrapper = mount(CopilotKitProvider, {
|
|
312
|
+
props: { runtimeUrl: "/api/copilotkit" },
|
|
313
|
+
slots: {
|
|
314
|
+
default: () =>
|
|
315
|
+
h(
|
|
316
|
+
CopilotChatConfigurationProvider,
|
|
317
|
+
{ threadId: "thread-1", agentId: "default" },
|
|
318
|
+
{ default: () => h(Harness) },
|
|
319
|
+
),
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
expect(wrapper.get("[data-testid='slot-label']").text()).toBe("first");
|
|
324
|
+
label.value = "second";
|
|
325
|
+
await nextTick();
|
|
326
|
+
expect(wrapper.get("[data-testid='slot-label']").text()).toBe("second");
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("forwards a consumer-provided tool-call slot when slot membership changes", async () => {
|
|
330
|
+
const message = baseAssistantMessage();
|
|
331
|
+
const showCustom = ref(false);
|
|
332
|
+
const Harness = defineComponent({
|
|
333
|
+
components: { CopilotChatToolCallsView },
|
|
334
|
+
setup() {
|
|
335
|
+
return { message, showCustom };
|
|
336
|
+
},
|
|
337
|
+
template: `
|
|
338
|
+
<CopilotChatToolCallsView :message="message" :messages="[message]">
|
|
339
|
+
<template v-if="showCustom" #tool-call-search_docs>
|
|
340
|
+
<div data-testid="custom-tool-slot">CUSTOM</div>
|
|
341
|
+
</template>
|
|
342
|
+
</CopilotChatToolCallsView>
|
|
343
|
+
`,
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const wrapper = mount(CopilotKitProvider, {
|
|
347
|
+
props: { runtimeUrl: "/api/copilotkit" },
|
|
348
|
+
slots: {
|
|
349
|
+
default: () =>
|
|
350
|
+
h(
|
|
351
|
+
CopilotChatConfigurationProvider,
|
|
352
|
+
{ threadId: "thread-1", agentId: "default" },
|
|
353
|
+
{ default: () => h(Harness) },
|
|
354
|
+
),
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
expect(wrapper.find("[data-testid='custom-tool-slot']").exists()).toBe(
|
|
359
|
+
false,
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
showCustom.value = true;
|
|
363
|
+
await nextTick();
|
|
364
|
+
expect(wrapper.find("[data-testid='custom-tool-slot']").text()).toBe(
|
|
365
|
+
"CUSTOM",
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
showCustom.value = false;
|
|
369
|
+
await nextTick();
|
|
370
|
+
expect(wrapper.find("[data-testid='custom-tool-slot']").exists()).toBe(
|
|
371
|
+
false,
|
|
372
|
+
);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("skips unchanged fallback renderers when an unrelated parent value changes", async () => {
|
|
376
|
+
const message = baseAssistantMessage();
|
|
377
|
+
const label = ref("first");
|
|
378
|
+
let renderCount = 0;
|
|
379
|
+
const ToolRenderer = defineComponent({
|
|
380
|
+
setup() {
|
|
381
|
+
return () => {
|
|
382
|
+
renderCount += 1;
|
|
383
|
+
return h("div", { "data-testid": "core-render-tool" }, "rendered");
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
const RegisterRenderer = defineComponent({
|
|
388
|
+
setup() {
|
|
389
|
+
const { copilotkit } = useCopilotKit();
|
|
390
|
+
copilotkit.value.setRenderToolCalls([
|
|
391
|
+
defineToolCallRenderer({
|
|
392
|
+
name: "search_docs",
|
|
393
|
+
args: undefined,
|
|
394
|
+
render: ToolRenderer,
|
|
395
|
+
}),
|
|
396
|
+
]);
|
|
397
|
+
return () => null;
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
const Harness = defineComponent({
|
|
401
|
+
setup() {
|
|
402
|
+
return () =>
|
|
403
|
+
h("div", [
|
|
404
|
+
h("span", { "data-testid": "unrelated-value" }, label.value),
|
|
405
|
+
h(RegisterRenderer),
|
|
406
|
+
h(CopilotChatToolCallsView, { message, messages: [message] }),
|
|
407
|
+
]);
|
|
408
|
+
},
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const wrapper = mount(CopilotKitProvider, {
|
|
412
|
+
props: { runtimeUrl: "/api/copilotkit" },
|
|
413
|
+
slots: {
|
|
414
|
+
default: () =>
|
|
415
|
+
h(
|
|
416
|
+
CopilotChatConfigurationProvider,
|
|
417
|
+
{ threadId: "thread-1", agentId: "default" },
|
|
418
|
+
{ default: () => h(Harness) },
|
|
419
|
+
),
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
expect(renderCount).toBe(1);
|
|
424
|
+
label.value = "second";
|
|
425
|
+
await nextTick();
|
|
426
|
+
expect(wrapper.get("[data-testid='unrelated-value']").text()).toBe(
|
|
427
|
+
"second",
|
|
428
|
+
);
|
|
429
|
+
expect(renderCount).toBe(1);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("updates a fallback renderer when the tool name changes", async () => {
|
|
433
|
+
const message = baseAssistantMessage();
|
|
434
|
+
const toolCall = message.toolCalls![0];
|
|
435
|
+
const currentMessage = ref(message);
|
|
436
|
+
const ToolRenderer = defineComponent({
|
|
437
|
+
props: {
|
|
438
|
+
name: { type: String, required: true },
|
|
439
|
+
},
|
|
440
|
+
template: `<div data-testid="fallback-tool-name">{{ name }}</div>`,
|
|
441
|
+
});
|
|
442
|
+
const RegisterRenderer = defineComponent({
|
|
443
|
+
setup() {
|
|
444
|
+
const { copilotkit } = useCopilotKit();
|
|
445
|
+
copilotkit.value.setRenderToolCalls([
|
|
446
|
+
defineToolCallRenderer({ name: "*", render: ToolRenderer }),
|
|
447
|
+
]);
|
|
448
|
+
return () => null;
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
const Harness = defineComponent({
|
|
452
|
+
setup() {
|
|
453
|
+
return () =>
|
|
454
|
+
h("div", [
|
|
455
|
+
h(RegisterRenderer),
|
|
456
|
+
h(CopilotChatToolCallsView, {
|
|
457
|
+
message: currentMessage.value,
|
|
458
|
+
messages: [currentMessage.value],
|
|
459
|
+
}),
|
|
460
|
+
]);
|
|
461
|
+
},
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
const wrapper = mount(CopilotKitProvider, {
|
|
465
|
+
props: { runtimeUrl: "/api/copilotkit" },
|
|
466
|
+
slots: {
|
|
467
|
+
default: () =>
|
|
468
|
+
h(
|
|
469
|
+
CopilotChatConfigurationProvider,
|
|
470
|
+
{ threadId: "thread-1", agentId: "default" },
|
|
471
|
+
{ default: () => h(Harness) },
|
|
472
|
+
),
|
|
473
|
+
},
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
expect(wrapper.get("[data-testid='fallback-tool-name']").text()).toBe(
|
|
477
|
+
"search_docs",
|
|
478
|
+
);
|
|
479
|
+
currentMessage.value = {
|
|
480
|
+
...message,
|
|
481
|
+
toolCalls: [
|
|
482
|
+
{
|
|
483
|
+
...toolCall,
|
|
484
|
+
function: { ...toolCall.function, name: "other_tool" },
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
};
|
|
488
|
+
await nextTick();
|
|
489
|
+
expect(wrapper.get("[data-testid='fallback-tool-name']").text()).toBe(
|
|
490
|
+
"other_tool",
|
|
491
|
+
);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it("updates a fallback renderer when agent-specific selection changes", async () => {
|
|
495
|
+
const message = baseAssistantMessage();
|
|
496
|
+
const agentId = ref("agent-a");
|
|
497
|
+
const AgentARenderer = defineComponent({
|
|
498
|
+
template: `<div data-testid="agent-renderer">agent-a</div>`,
|
|
499
|
+
});
|
|
500
|
+
const AgentBRenderer = defineComponent({
|
|
501
|
+
template: `<div data-testid="agent-renderer">agent-b</div>`,
|
|
502
|
+
});
|
|
503
|
+
const RegisterRenderer = defineComponent({
|
|
504
|
+
setup() {
|
|
505
|
+
const { copilotkit } = useCopilotKit();
|
|
506
|
+
copilotkit.value.setRenderToolCalls([
|
|
507
|
+
defineToolCallRenderer({
|
|
508
|
+
name: "search_docs",
|
|
509
|
+
agentId: "agent-a",
|
|
510
|
+
render: AgentARenderer,
|
|
511
|
+
}),
|
|
512
|
+
defineToolCallRenderer({
|
|
513
|
+
name: "search_docs",
|
|
514
|
+
agentId: "agent-b",
|
|
515
|
+
render: AgentBRenderer,
|
|
516
|
+
}),
|
|
517
|
+
]);
|
|
518
|
+
return () => null;
|
|
519
|
+
},
|
|
520
|
+
});
|
|
521
|
+
const Harness = defineComponent({
|
|
522
|
+
setup() {
|
|
523
|
+
return () =>
|
|
524
|
+
h(
|
|
525
|
+
CopilotChatConfigurationProvider,
|
|
526
|
+
{ threadId: "thread-1", agentId: agentId.value },
|
|
527
|
+
{
|
|
528
|
+
default: () =>
|
|
529
|
+
h("div", [
|
|
530
|
+
h(RegisterRenderer),
|
|
531
|
+
h(CopilotChatToolCallsView, {
|
|
532
|
+
message,
|
|
533
|
+
messages: [message],
|
|
534
|
+
}),
|
|
535
|
+
]),
|
|
536
|
+
},
|
|
537
|
+
);
|
|
538
|
+
},
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
const wrapper = mount(CopilotKitProvider, {
|
|
542
|
+
props: { runtimeUrl: "/api/copilotkit" },
|
|
543
|
+
slots: { default: () => h(Harness) },
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
expect(wrapper.get("[data-testid='agent-renderer']").text()).toBe(
|
|
547
|
+
"agent-a",
|
|
548
|
+
);
|
|
549
|
+
agentId.value = "agent-b";
|
|
550
|
+
await nextTick();
|
|
551
|
+
expect(wrapper.get("[data-testid='agent-renderer']").text()).toBe(
|
|
552
|
+
"agent-b",
|
|
553
|
+
);
|
|
554
|
+
});
|
|
555
|
+
|
|
255
556
|
it("prefers current-agent renderers over unscoped and wildcard renderers", () => {
|
|
256
557
|
const message = baseAssistantMessage("search_docs");
|
|
257
558
|
const RegisterRenderer = defineComponent({
|