@copilotkitnext/angular 0.0.1 → 0.0.4
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/README.md +248 -0
- package/dist/README.md +248 -0
- package/dist/components/chat/copilot-chat-assistant-message.component.d.ts +10 -10
- package/dist/components/chat/copilot-chat-message-view.component.d.ts +42 -42
- package/dist/components/chat/copilot-chat-view.component.d.ts +14 -14
- package/dist/esm2022/components/chat/copilot-chat-assistant-message-buttons.component.mjs +384 -0
- package/dist/esm2022/components/chat/copilot-chat-assistant-message-renderer.component.mjs +286 -0
- package/dist/esm2022/components/chat/copilot-chat-assistant-message-toolbar.component.mjs +27 -0
- package/dist/esm2022/components/chat/copilot-chat-assistant-message.component.mjs +433 -0
- package/dist/esm2022/components/chat/copilot-chat-assistant-message.types.mjs +2 -0
- package/dist/esm2022/components/chat/copilot-chat-audio-recorder.component.mjs +202 -0
- package/dist/esm2022/components/chat/copilot-chat-buttons.component.mjs +321 -0
- package/dist/esm2022/components/chat/copilot-chat-input-defaults.mjs +38 -0
- package/dist/esm2022/components/chat/copilot-chat-input.component.mjs +666 -0
- package/dist/esm2022/components/chat/copilot-chat-input.types.mjs +10 -0
- package/dist/esm2022/components/chat/copilot-chat-message-view-cursor.component.mjs +45 -0
- package/dist/esm2022/components/chat/copilot-chat-message-view.component.mjs +296 -0
- package/dist/esm2022/components/chat/copilot-chat-message-view.types.mjs +2 -0
- package/dist/esm2022/components/chat/copilot-chat-textarea.component.mjs +188 -0
- package/dist/esm2022/components/chat/copilot-chat-tool-calls-view.component.mjs +216 -0
- package/dist/esm2022/components/chat/copilot-chat-toolbar.component.mjs +25 -0
- package/dist/esm2022/components/chat/copilot-chat-tools-menu.component.mjs +199 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message-branch-navigation.component.mjs +137 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message-buttons.component.mjs +207 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message-renderer.component.mjs +35 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message-toolbar.component.mjs +34 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message.component.mjs +341 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message.types.mjs +2 -0
- package/dist/esm2022/components/chat/copilot-chat-view-disclaimer.component.mjs +52 -0
- package/dist/esm2022/components/chat/copilot-chat-view-feather.component.mjs +55 -0
- package/dist/esm2022/components/chat/copilot-chat-view-handlers.service.mjs +19 -0
- package/dist/esm2022/components/chat/copilot-chat-view-input-container.component.mjs +110 -0
- package/dist/esm2022/components/chat/copilot-chat-view-scroll-to-bottom-button.component.mjs +93 -0
- package/dist/esm2022/components/chat/copilot-chat-view-scroll-view.component.mjs +443 -0
- package/dist/esm2022/components/chat/copilot-chat-view.component.mjs +479 -0
- package/dist/esm2022/components/chat/copilot-chat-view.types.mjs +2 -0
- package/dist/esm2022/components/chat/copilot-chat.component.mjs +214 -0
- package/dist/esm2022/components/copilotkit-tool-render.component.mjs +153 -0
- package/dist/esm2022/copilotkitnext-angular.mjs +5 -0
- package/dist/esm2022/core/chat-configuration/chat-configuration.providers.mjs +65 -0
- package/dist/esm2022/core/chat-configuration/chat-configuration.service.mjs +145 -0
- package/dist/esm2022/core/chat-configuration/chat-configuration.types.mjs +26 -0
- package/dist/esm2022/core/copilotkit.providers.mjs +34 -0
- package/dist/esm2022/core/copilotkit.service.mjs +430 -0
- package/dist/esm2022/core/copilotkit.types.mjs +12 -0
- package/dist/esm2022/directives/copilotkit-agent-context.directive.mjs +130 -0
- package/dist/esm2022/directives/copilotkit-agent.directive.mjs +217 -0
- package/dist/esm2022/directives/copilotkit-chat-config.directive.mjs +218 -0
- package/dist/esm2022/directives/copilotkit-config.directive.mjs +94 -0
- package/dist/esm2022/directives/copilotkit-frontend-tool.directive.mjs +130 -0
- package/dist/esm2022/directives/copilotkit-human-in-the-loop.directive.mjs +266 -0
- package/dist/esm2022/directives/stick-to-bottom.directive.mjs +181 -0
- package/dist/esm2022/index.mjs +70 -0
- package/dist/esm2022/lib/directives/tooltip.directive.mjs +211 -0
- package/dist/esm2022/lib/slots/copilot-slot.component.mjs +144 -0
- package/dist/esm2022/lib/slots/slot.types.mjs +6 -0
- package/dist/esm2022/lib/slots/slot.utils.mjs +222 -0
- package/dist/esm2022/lib/utils.mjs +10 -0
- package/dist/esm2022/services/resize-observer.service.mjs +152 -0
- package/dist/esm2022/services/scroll-position.service.mjs +124 -0
- package/dist/esm2022/types/frontend-tool.mjs +2 -0
- package/dist/esm2022/types/human-in-the-loop.mjs +2 -0
- package/dist/esm2022/utils/agent-context.utils.mjs +114 -0
- package/dist/esm2022/utils/agent.utils.mjs +204 -0
- package/dist/esm2022/utils/chat-config.utils.mjs +186 -0
- package/dist/esm2022/utils/copilotkit.utils.mjs +20 -0
- package/dist/esm2022/utils/frontend-tool.utils.mjs +228 -0
- package/dist/esm2022/utils/human-in-the-loop.utils.mjs +296 -0
- package/dist/fesm2022/copilotkitnext-angular.mjs +163 -164
- package/dist/fesm2022/copilotkitnext-angular.mjs.map +1 -1
- package/dist/styles.css +0 -27
- package/package.json +23 -20
- package/vitest.config.mts +32 -21
- package/.turbo/turbo-build.log +0 -39
- package/.turbo/turbo-check-types.log +0 -0
- package/.turbo/turbo-test.log +0 -71
- package/README-agent-context.md +0 -310
- package/ng-package.json +0 -19
- package/slots.md +0 -331
- package/src/components/chat/__tests__/copilot-chat-assistant-message.component.spec.ts +0 -282
- package/src/components/chat/__tests__/copilot-chat-input.component.spec.ts +0 -419
- package/src/components/chat/__tests__/copilot-chat-message-view.component.spec.ts +0 -372
- package/src/components/chat/__tests__/copilot-chat-user-message.component.spec.ts +0 -249
- package/src/components/chat/copilot-chat-assistant-message-buttons.component.ts +0 -292
- package/src/components/chat/copilot-chat-assistant-message-renderer.component.ts +0 -472
- package/src/components/chat/copilot-chat-assistant-message-toolbar.component.ts +0 -29
- package/src/components/chat/copilot-chat-assistant-message.component.ts +0 -463
- package/src/components/chat/copilot-chat-assistant-message.types.ts +0 -50
- package/src/components/chat/copilot-chat-audio-recorder.component.ts +0 -241
- package/src/components/chat/copilot-chat-buttons.component.ts +0 -308
- package/src/components/chat/copilot-chat-buttons.component.ts.bak +0 -471
- package/src/components/chat/copilot-chat-input-defaults.ts +0 -47
- package/src/components/chat/copilot-chat-input.component.ts +0 -512
- package/src/components/chat/copilot-chat-input.types.ts +0 -148
- package/src/components/chat/copilot-chat-message-view-cursor.component.ts +0 -51
- package/src/components/chat/copilot-chat-message-view.component.ts +0 -233
- package/src/components/chat/copilot-chat-message-view.types.ts +0 -39
- package/src/components/chat/copilot-chat-textarea.component.ts +0 -220
- package/src/components/chat/copilot-chat-tool-calls-view.component.ts +0 -261
- package/src/components/chat/copilot-chat-toolbar.component.ts +0 -35
- package/src/components/chat/copilot-chat-tools-menu.component.ts +0 -185
- package/src/components/chat/copilot-chat-user-message-branch-navigation.component.ts +0 -121
- package/src/components/chat/copilot-chat-user-message-buttons.component.ts +0 -170
- package/src/components/chat/copilot-chat-user-message-renderer.component.ts +0 -37
- package/src/components/chat/copilot-chat-user-message-toolbar.component.ts +0 -37
- package/src/components/chat/copilot-chat-user-message.component.ts +0 -247
- package/src/components/chat/copilot-chat-user-message.types.ts +0 -42
- package/src/components/chat/copilot-chat-view-disclaimer.component.ts +0 -51
- package/src/components/chat/copilot-chat-view-feather.component.ts +0 -47
- package/src/components/chat/copilot-chat-view-handlers.service.ts +0 -14
- package/src/components/chat/copilot-chat-view-input-container.component.ts +0 -87
- package/src/components/chat/copilot-chat-view-scroll-to-bottom-button.component.ts +0 -79
- package/src/components/chat/copilot-chat-view-scroll-view.component.ts +0 -322
- package/src/components/chat/copilot-chat-view.component.ts +0 -420
- package/src/components/chat/copilot-chat-view.types.ts +0 -52
- package/src/components/chat/copilot-chat.component.ts +0 -232
- package/src/components/copilotkit-tool-render.component.ts +0 -169
- package/src/core/__tests__/copilotkit.service.spec.ts +0 -1051
- package/src/core/__tests__/copilotkit.service.wildcard.spec.ts +0 -316
- package/src/core/chat-configuration/__tests__/chat-configuration.service.spec.ts +0 -287
- package/src/core/chat-configuration/chat-configuration.providers.ts +0 -71
- package/src/core/chat-configuration/chat-configuration.service.ts +0 -162
- package/src/core/chat-configuration/chat-configuration.types.ts +0 -57
- package/src/core/copilotkit.providers.ts +0 -59
- package/src/core/copilotkit.service.ts +0 -542
- package/src/core/copilotkit.types.ts +0 -132
- package/src/directives/__tests__/copilotkit-agent-context.directive.spec.ts +0 -384
- package/src/directives/__tests__/copilotkit-agent.directive.spec.ts +0 -253
- package/src/directives/__tests__/copilotkit-chat-config.directive.spec.ts +0 -385
- package/src/directives/__tests__/copilotkit-config.directive.spec.ts +0 -69
- package/src/directives/__tests__/copilotkit-frontend-tool-simple.directive.spec.ts +0 -60
- package/src/directives/__tests__/copilotkit-frontend-tool.directive.spec.ts +0 -108
- package/src/directives/__tests__/copilotkit-human-in-the-loop.directive.spec.ts +0 -452
- package/src/directives/copilotkit-agent-context.directive.ts +0 -138
- package/src/directives/copilotkit-agent.directive.ts +0 -225
- package/src/directives/copilotkit-chat-config.directive.ts +0 -241
- package/src/directives/copilotkit-config.directive.ts +0 -81
- package/src/directives/copilotkit-frontend-tool.directive.ts +0 -145
- package/src/directives/copilotkit-human-in-the-loop.directive.ts +0 -281
- package/src/directives/stick-to-bottom.directive.ts +0 -204
- package/src/index.ts +0 -105
- package/src/lib/directives/tooltip.directive.ts +0 -292
- package/src/lib/slots/__tests__/slot.utils.spec.ts +0 -377
- package/src/lib/slots/copilot-slot.component.ts +0 -135
- package/src/lib/slots/index.ts +0 -3
- package/src/lib/slots/slot.types.ts +0 -64
- package/src/lib/slots/slot.utils.ts +0 -289
- package/src/lib/utils.ts +0 -10
- package/src/public-api.ts +0 -1
- package/src/services/resize-observer.service.ts +0 -181
- package/src/services/scroll-position.service.ts +0 -169
- package/src/styles/globals.css +0 -266
- package/src/styles/index.css +0 -3
- package/src/test-setup.ts +0 -15
- package/src/testing/index.ts +0 -3
- package/src/testing/testing.utils.ts +0 -248
- package/src/types/frontend-tool.ts +0 -44
- package/src/types/human-in-the-loop.ts +0 -52
- package/src/utils/__tests__/agent.utils.spec.ts +0 -234
- package/src/utils/__tests__/chat-config.utils.spec.ts +0 -306
- package/src/utils/__tests__/frontend-tool-inject.spec.ts +0 -350
- package/src/utils/__tests__/frontend-tool-integration.spec.ts +0 -199
- package/src/utils/__tests__/frontend-tool.utils.spec.ts +0 -272
- package/src/utils/__tests__/human-in-the-loop.utils.spec.ts +0 -365
- package/src/utils/agent-context.utils.ts +0 -133
- package/src/utils/agent.utils.ts +0 -239
- package/src/utils/chat-config.utils.ts +0 -221
- package/src/utils/copilotkit.utils.ts +0 -20
- package/src/utils/frontend-tool.utils.ts +0 -266
- package/src/utils/human-in-the-loop.utils.ts +0 -359
- package/tsconfig.spec.json +0 -12
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
import { TestBed } from "@angular/core/testing";
|
|
2
|
-
import { Component, OnInit } from "@angular/core";
|
|
3
|
-
import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
|
|
4
|
-
import {
|
|
5
|
-
registerFrontendTool,
|
|
6
|
-
createDynamicFrontendTool,
|
|
7
|
-
} from "../frontend-tool.utils";
|
|
8
|
-
import { CopilotKitService } from "../../core/copilotkit.service";
|
|
9
|
-
import { provideCopilotKit } from "../../core/copilotkit.providers";
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
import { signal } from "@angular/core";
|
|
12
|
-
|
|
13
|
-
// Mock CopilotKitCore
|
|
14
|
-
vi.mock("@copilotkitnext/core", () => ({
|
|
15
|
-
CopilotKitCore: vi.fn().mockImplementation(() => ({
|
|
16
|
-
addTool: vi.fn(),
|
|
17
|
-
removeTool: vi.fn(),
|
|
18
|
-
setRuntimeUrl: vi.fn(),
|
|
19
|
-
setHeaders: vi.fn(),
|
|
20
|
-
setProperties: vi.fn(),
|
|
21
|
-
setAgents: vi.fn(),
|
|
22
|
-
subscribe: vi.fn(() => () => {}),
|
|
23
|
-
})),
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
// Mock component for testing
|
|
27
|
-
@Component({
|
|
28
|
-
template: `<div>Mock Render</div>`,
|
|
29
|
-
standalone: true,
|
|
30
|
-
})
|
|
31
|
-
class MockRenderComponent {}
|
|
32
|
-
|
|
33
|
-
describe("Frontend Tool Inject Functions", () => {
|
|
34
|
-
let service: CopilotKitService;
|
|
35
|
-
let addToolSpy: any;
|
|
36
|
-
let removeToolSpy: any;
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
TestBed.configureTestingModule({
|
|
40
|
-
providers: [provideCopilotKit({})],
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
service = TestBed.inject(CopilotKitService);
|
|
44
|
-
addToolSpy = vi.spyOn(service.copilotkit, "addTool");
|
|
45
|
-
removeToolSpy = vi.spyOn(service.copilotkit, "removeTool");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
afterEach(() => {
|
|
49
|
-
vi.clearAllMocks();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("registerFrontendTool", () => {
|
|
53
|
-
it("should register tool within component context", () => {
|
|
54
|
-
@Component({
|
|
55
|
-
template: "",
|
|
56
|
-
standalone: true,
|
|
57
|
-
providers: [provideCopilotKit({})],
|
|
58
|
-
})
|
|
59
|
-
class TestComponent implements OnInit {
|
|
60
|
-
// Move the registration to constructor or field initializer
|
|
61
|
-
// where injection context is available
|
|
62
|
-
toolName = registerFrontendTool({
|
|
63
|
-
name: "testTool",
|
|
64
|
-
description: "Test tool",
|
|
65
|
-
parameters: z.object({ value: z.string() }),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
ngOnInit() {
|
|
69
|
-
expect(this.toolName).toBe("testTool");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
74
|
-
fixture.detectChanges();
|
|
75
|
-
|
|
76
|
-
// Tool should be added
|
|
77
|
-
expect(addToolSpy).toHaveBeenCalledWith(
|
|
78
|
-
expect.objectContaining({
|
|
79
|
-
name: "testTool",
|
|
80
|
-
description: "Test tool",
|
|
81
|
-
})
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should register render when provided", () => {
|
|
86
|
-
@Component({
|
|
87
|
-
template: "",
|
|
88
|
-
standalone: true,
|
|
89
|
-
providers: [provideCopilotKit({})],
|
|
90
|
-
})
|
|
91
|
-
class TestComponent {
|
|
92
|
-
// Call in field initializer where injection context is available
|
|
93
|
-
toolName = registerFrontendTool({
|
|
94
|
-
name: "renderTool",
|
|
95
|
-
render: MockRenderComponent,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
100
|
-
fixture.detectChanges();
|
|
101
|
-
|
|
102
|
-
const renders = service.currentRenderToolCalls();
|
|
103
|
-
const renderTool = renders.find((r) => r.name === "renderTool");
|
|
104
|
-
expect(renderTool).toBeDefined();
|
|
105
|
-
expect(renderTool?.render).toBe(MockRenderComponent);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should cleanup on component destroy", () => {
|
|
109
|
-
@Component({
|
|
110
|
-
template: "",
|
|
111
|
-
standalone: true,
|
|
112
|
-
providers: [provideCopilotKit({})],
|
|
113
|
-
})
|
|
114
|
-
class TestComponent {
|
|
115
|
-
toolName = registerFrontendTool({
|
|
116
|
-
name: "cleanupTool",
|
|
117
|
-
description: "Tool with auto cleanup",
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
122
|
-
fixture.detectChanges();
|
|
123
|
-
|
|
124
|
-
expect(addToolSpy).toHaveBeenCalled();
|
|
125
|
-
|
|
126
|
-
// Destroy the component
|
|
127
|
-
fixture.destroy();
|
|
128
|
-
|
|
129
|
-
// Tool should be removed
|
|
130
|
-
expect(removeToolSpy).toHaveBeenCalledWith("cleanupTool");
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("should handle complex tool configuration", () => {
|
|
134
|
-
const schema = z.object({
|
|
135
|
-
query: z.string(),
|
|
136
|
-
limit: z.number().optional(),
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
const handler = vi.fn(async (args: any) => {
|
|
140
|
-
return { results: [] };
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
@Component({
|
|
144
|
-
template: "",
|
|
145
|
-
standalone: true,
|
|
146
|
-
providers: [provideCopilotKit({})],
|
|
147
|
-
})
|
|
148
|
-
class TestComponent {
|
|
149
|
-
toolName = registerFrontendTool({
|
|
150
|
-
name: "searchTool",
|
|
151
|
-
description: "Search tool",
|
|
152
|
-
parameters: schema,
|
|
153
|
-
handler: handler,
|
|
154
|
-
render: MockRenderComponent,
|
|
155
|
-
followUp: true,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
160
|
-
fixture.detectChanges();
|
|
161
|
-
|
|
162
|
-
expect(addToolSpy).toHaveBeenCalledWith(
|
|
163
|
-
expect.objectContaining({
|
|
164
|
-
name: "searchTool",
|
|
165
|
-
description: "Search tool",
|
|
166
|
-
followUp: true,
|
|
167
|
-
})
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
describe("createDynamicFrontendTool", () => {
|
|
173
|
-
it("should create tool with initial configuration", () => {
|
|
174
|
-
@Component({
|
|
175
|
-
template: "",
|
|
176
|
-
standalone: true,
|
|
177
|
-
providers: [provideCopilotKit({})],
|
|
178
|
-
})
|
|
179
|
-
class TestComponent implements OnInit {
|
|
180
|
-
// Create in field initializer
|
|
181
|
-
tool = createDynamicFrontendTool(
|
|
182
|
-
"dynamicTool",
|
|
183
|
-
"Dynamic tool",
|
|
184
|
-
z.object({ value: z.string() }),
|
|
185
|
-
() => vi.fn(async () => "result")
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
ngOnInit() {
|
|
189
|
-
expect(this.tool).toBeDefined();
|
|
190
|
-
expect(this.tool.update).toBeDefined();
|
|
191
|
-
expect(this.tool.destroy).toBeDefined();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
196
|
-
fixture.detectChanges();
|
|
197
|
-
|
|
198
|
-
expect(addToolSpy).toHaveBeenCalledWith(
|
|
199
|
-
expect.objectContaining({
|
|
200
|
-
name: "dynamicTool",
|
|
201
|
-
description: "Dynamic tool",
|
|
202
|
-
})
|
|
203
|
-
);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("should handle dynamic updates", () => {
|
|
207
|
-
@Component({
|
|
208
|
-
template: "",
|
|
209
|
-
standalone: true,
|
|
210
|
-
providers: [provideCopilotKit({})],
|
|
211
|
-
})
|
|
212
|
-
class TestComponent implements OnInit {
|
|
213
|
-
handlerSignal = signal(vi.fn(async () => "initial"));
|
|
214
|
-
|
|
215
|
-
tool = createDynamicFrontendTool(
|
|
216
|
-
"updateableTool",
|
|
217
|
-
"Updateable tool",
|
|
218
|
-
z.object({ value: z.string() }),
|
|
219
|
-
() => this.handlerSignal()
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
ngOnInit() {
|
|
223
|
-
// Initial registration
|
|
224
|
-
expect(addToolSpy).toHaveBeenCalledTimes(1);
|
|
225
|
-
|
|
226
|
-
// Update handler
|
|
227
|
-
this.handlerSignal.set(vi.fn(async () => "updated"));
|
|
228
|
-
this.tool.update();
|
|
229
|
-
|
|
230
|
-
// Should remove old and add new
|
|
231
|
-
expect(removeToolSpy).toHaveBeenCalledWith("updateableTool");
|
|
232
|
-
expect(addToolSpy).toHaveBeenCalledTimes(2);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
237
|
-
fixture.detectChanges();
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it("should support dynamic description", () => {
|
|
241
|
-
@Component({
|
|
242
|
-
template: "",
|
|
243
|
-
standalone: true,
|
|
244
|
-
providers: [provideCopilotKit({})],
|
|
245
|
-
})
|
|
246
|
-
class TestComponent implements OnInit {
|
|
247
|
-
descSignal = signal("Initial description");
|
|
248
|
-
|
|
249
|
-
tool = createDynamicFrontendTool(
|
|
250
|
-
"descTool",
|
|
251
|
-
() => this.descSignal(),
|
|
252
|
-
z.object({}),
|
|
253
|
-
() => vi.fn(async () => null)
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
ngOnInit() {
|
|
257
|
-
this.descSignal.set("Updated description");
|
|
258
|
-
this.tool.update();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
263
|
-
fixture.detectChanges();
|
|
264
|
-
|
|
265
|
-
expect(addToolSpy).toHaveBeenLastCalledWith(
|
|
266
|
-
expect.objectContaining({
|
|
267
|
-
description: "Updated description",
|
|
268
|
-
})
|
|
269
|
-
);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it("should cleanup on manual destroy", () => {
|
|
273
|
-
@Component({
|
|
274
|
-
template: "",
|
|
275
|
-
standalone: true,
|
|
276
|
-
providers: [provideCopilotKit({})],
|
|
277
|
-
})
|
|
278
|
-
class TestComponent implements OnInit {
|
|
279
|
-
tool = createDynamicFrontendTool(
|
|
280
|
-
"manualCleanupTool",
|
|
281
|
-
"Manual cleanup",
|
|
282
|
-
z.object({}),
|
|
283
|
-
() => vi.fn(async () => null)
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
ngOnInit() {
|
|
287
|
-
// Manual destroy
|
|
288
|
-
this.tool.destroy();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
293
|
-
fixture.detectChanges();
|
|
294
|
-
|
|
295
|
-
expect(removeToolSpy).toHaveBeenCalledWith("manualCleanupTool");
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it("should auto-cleanup on component destroy", () => {
|
|
299
|
-
@Component({
|
|
300
|
-
template: "",
|
|
301
|
-
standalone: true,
|
|
302
|
-
providers: [provideCopilotKit({})],
|
|
303
|
-
})
|
|
304
|
-
class TestComponent {
|
|
305
|
-
tool = createDynamicFrontendTool(
|
|
306
|
-
"autoCleanupTool",
|
|
307
|
-
"Auto cleanup",
|
|
308
|
-
z.object({}),
|
|
309
|
-
() => vi.fn(async () => null)
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
314
|
-
fixture.detectChanges();
|
|
315
|
-
|
|
316
|
-
expect(addToolSpy).toHaveBeenCalled();
|
|
317
|
-
|
|
318
|
-
fixture.destroy();
|
|
319
|
-
|
|
320
|
-
expect(removeToolSpy).toHaveBeenCalledWith("autoCleanupTool");
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it("should support dynamic render", () => {
|
|
324
|
-
@Component({
|
|
325
|
-
template: "",
|
|
326
|
-
standalone: true,
|
|
327
|
-
providers: [provideCopilotKit({})],
|
|
328
|
-
})
|
|
329
|
-
class TestComponent {
|
|
330
|
-
renderSignal = signal<any>(MockRenderComponent);
|
|
331
|
-
|
|
332
|
-
tool = createDynamicFrontendTool(
|
|
333
|
-
"renderDynamicTool",
|
|
334
|
-
"Dynamic render",
|
|
335
|
-
z.object({}),
|
|
336
|
-
() => vi.fn(async () => null),
|
|
337
|
-
() => this.renderSignal()
|
|
338
|
-
);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const fixture = TestBed.createComponent(TestComponent);
|
|
342
|
-
fixture.detectChanges();
|
|
343
|
-
|
|
344
|
-
const renders = service.currentRenderToolCalls();
|
|
345
|
-
const renderTool = renders.find((r) => r.name === "renderDynamicTool");
|
|
346
|
-
expect(renderTool).toBeDefined();
|
|
347
|
-
expect(renderTool?.render).toBe(MockRenderComponent);
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
});
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { TestBed } from "@angular/core/testing";
|
|
2
|
-
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
3
|
-
import { CopilotKitService } from "../../core/copilotkit.service";
|
|
4
|
-
import { provideCopilotKit } from "../../core/copilotkit.providers";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
|
|
7
|
-
// Mock CopilotKitCore
|
|
8
|
-
vi.mock("@copilotkitnext/core", () => ({
|
|
9
|
-
CopilotKitCore: vi.fn().mockImplementation(() => ({
|
|
10
|
-
addTool: vi.fn(),
|
|
11
|
-
removeTool: vi.fn(),
|
|
12
|
-
setRuntimeUrl: vi.fn(),
|
|
13
|
-
setHeaders: vi.fn(),
|
|
14
|
-
setProperties: vi.fn(),
|
|
15
|
-
setAgents: vi.fn(),
|
|
16
|
-
subscribe: vi.fn(() => () => {}),
|
|
17
|
-
})),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
describe("Frontend Tool Integration", () => {
|
|
21
|
-
let service: CopilotKitService;
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
TestBed.configureTestingModule({
|
|
25
|
-
providers: [provideCopilotKit({})],
|
|
26
|
-
});
|
|
27
|
-
service = TestBed.inject(CopilotKitService);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("Service Tool Render Methods", () => {
|
|
31
|
-
it("should register tool render", () => {
|
|
32
|
-
const render = {
|
|
33
|
-
name: "testTool",
|
|
34
|
-
args: z.object({ value: z.string() }),
|
|
35
|
-
render: {} as any, // Mock component
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
service.registerToolRender("testTool", render);
|
|
39
|
-
|
|
40
|
-
const retrieved = service.getToolRender("testTool");
|
|
41
|
-
expect(retrieved).toBe(render);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should unregister tool render", () => {
|
|
45
|
-
const render = {
|
|
46
|
-
name: "removeTool",
|
|
47
|
-
args: z.object({}),
|
|
48
|
-
render: {} as any,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
service.registerToolRender("removeTool", render);
|
|
52
|
-
expect(service.getToolRender("removeTool")).toBeDefined();
|
|
53
|
-
|
|
54
|
-
service.unregisterToolRender("removeTool");
|
|
55
|
-
expect(service.getToolRender("removeTool")).toBeUndefined();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should warn when overwriting render", () => {
|
|
59
|
-
const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
60
|
-
|
|
61
|
-
service.registerToolRender("dupeTool", {
|
|
62
|
-
name: "dupeTool",
|
|
63
|
-
args: z.object({}),
|
|
64
|
-
render: {} as any,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
service.registerToolRender("dupeTool", {
|
|
68
|
-
name: "dupeTool",
|
|
69
|
-
args: z.object({}),
|
|
70
|
-
render: {} as any,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
74
|
-
expect.stringContaining("being overwritten")
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
consoleSpy.mockRestore();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should handle multiple tool renders", () => {
|
|
81
|
-
const tools = ["tool1", "tool2", "tool3"];
|
|
82
|
-
|
|
83
|
-
tools.forEach((name) => {
|
|
84
|
-
service.registerToolRender(name, {
|
|
85
|
-
name: name,
|
|
86
|
-
args: z.object({}),
|
|
87
|
-
render: {} as any,
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
tools.forEach((name) => {
|
|
92
|
-
expect(service.getToolRender(name)).toBeDefined();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Remove middle one
|
|
96
|
-
service.unregisterToolRender("tool2");
|
|
97
|
-
|
|
98
|
-
expect(service.getToolRender("tool1")).toBeDefined();
|
|
99
|
-
expect(service.getToolRender("tool2")).toBeUndefined();
|
|
100
|
-
expect(service.getToolRender("tool3")).toBeDefined();
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe("Tool Registration Flow", () => {
|
|
105
|
-
it("should add tool to copilotkit instance", () => {
|
|
106
|
-
const addToolSpy = vi.spyOn(service.copilotkit, "addTool");
|
|
107
|
-
|
|
108
|
-
const tool = {
|
|
109
|
-
name: "flowTool",
|
|
110
|
-
description: "Test flow",
|
|
111
|
-
parameters: z.object({ input: z.string() }),
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
service.copilotkit.addTool(tool);
|
|
115
|
-
|
|
116
|
-
expect(addToolSpy).toHaveBeenCalledWith(tool);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("should remove tool from copilotkit instance", () => {
|
|
120
|
-
const removeToolSpy = vi.spyOn(service.copilotkit, "removeTool");
|
|
121
|
-
|
|
122
|
-
service.copilotkit.removeTool("testTool");
|
|
123
|
-
|
|
124
|
-
expect(removeToolSpy).toHaveBeenCalledWith("testTool");
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("should handle tool with all properties", () => {
|
|
128
|
-
const addToolSpy = vi.spyOn(service.copilotkit, "addTool");
|
|
129
|
-
|
|
130
|
-
const tool = {
|
|
131
|
-
name: "fullTool",
|
|
132
|
-
description: "Full featured tool",
|
|
133
|
-
parameters: z.object({
|
|
134
|
-
query: z.string(),
|
|
135
|
-
filters: z.object({
|
|
136
|
-
category: z.enum(["a", "b", "c"]),
|
|
137
|
-
}),
|
|
138
|
-
}),
|
|
139
|
-
handler: vi.fn(async () => ({ results: [] })),
|
|
140
|
-
followUp: true,
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
service.copilotkit.addTool(tool);
|
|
144
|
-
|
|
145
|
-
expect(addToolSpy).toHaveBeenCalledWith(
|
|
146
|
-
expect.objectContaining({
|
|
147
|
-
name: "fullTool",
|
|
148
|
-
description: "Full featured tool",
|
|
149
|
-
followUp: true,
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe("Render Tool Calls State", () => {
|
|
156
|
-
it("should update current render tool calls", () => {
|
|
157
|
-
const initial = service.currentRenderToolCalls();
|
|
158
|
-
expect(initial).toEqual([]);
|
|
159
|
-
|
|
160
|
-
const renders = [
|
|
161
|
-
{ name: "tool1", args: z.object({}), render: {} as any },
|
|
162
|
-
{ name: "tool2", args: z.object({}), render: {} as any },
|
|
163
|
-
];
|
|
164
|
-
|
|
165
|
-
service.setCurrentRenderToolCalls(renders);
|
|
166
|
-
|
|
167
|
-
expect(service.currentRenderToolCalls()).toEqual(renders);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("should merge renders when registering", () => {
|
|
171
|
-
service.setCurrentRenderToolCalls([
|
|
172
|
-
{ name: "existing", args: z.object({}), render: {} as any },
|
|
173
|
-
]);
|
|
174
|
-
|
|
175
|
-
service.registerToolRender("newTool", {
|
|
176
|
-
name: "newTool",
|
|
177
|
-
args: z.object({}),
|
|
178
|
-
render: {} as any,
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const renders = service.currentRenderToolCalls();
|
|
182
|
-
expect(renders.find((r) => r.name === "existing")).toBeDefined();
|
|
183
|
-
expect(renders.find((r) => r.name === "newTool")).toBeDefined();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("should preserve other renders when unregistering", () => {
|
|
187
|
-
service.setCurrentRenderToolCalls([
|
|
188
|
-
{ name: "keep1", args: z.object({}), render: {} as any },
|
|
189
|
-
{ name: "remove", args: z.object({}), render: {} as any },
|
|
190
|
-
{ name: "keep2", args: z.object({}), render: {} as any },
|
|
191
|
-
]);
|
|
192
|
-
|
|
193
|
-
service.unregisterToolRender("remove");
|
|
194
|
-
|
|
195
|
-
const renders = service.currentRenderToolCalls();
|
|
196
|
-
expect(renders.map((r) => r.name)).toEqual(["keep1", "keep2"]);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|