@copilotkitnext/angular 0.0.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.
- package/.turbo/turbo-build.log +39 -0
- package/.turbo/turbo-check-types.log +0 -0
- package/.turbo/turbo-test.log +71 -0
- package/LICENSE +10 -0
- package/README-agent-context.md +310 -0
- package/dist/LICENSE +10 -0
- package/dist/components/chat/copilot-chat-assistant-message-buttons.component.d.ts +75 -0
- package/dist/components/chat/copilot-chat-assistant-message-renderer.component.d.ts +31 -0
- package/dist/components/chat/copilot-chat-assistant-message-toolbar.component.d.ts +8 -0
- package/dist/components/chat/copilot-chat-assistant-message.component.d.ts +131 -0
- package/dist/components/chat/copilot-chat-assistant-message.types.d.ts +31 -0
- package/dist/components/chat/copilot-chat-audio-recorder.component.d.ts +40 -0
- package/dist/components/chat/copilot-chat-buttons.component.d.ts +66 -0
- package/dist/components/chat/copilot-chat-input-defaults.d.ts +37 -0
- package/dist/components/chat/copilot-chat-input.component.d.ts +133 -0
- package/dist/components/chat/copilot-chat-input.types.d.ts +129 -0
- package/dist/components/chat/copilot-chat-message-view-cursor.component.d.ts +15 -0
- package/dist/components/chat/copilot-chat-message-view.component.d.ts +293 -0
- package/dist/components/chat/copilot-chat-message-view.types.d.ts +24 -0
- package/dist/components/chat/copilot-chat-textarea.component.d.ts +45 -0
- package/dist/components/chat/copilot-chat-tool-calls-view.component.d.ts +35 -0
- package/dist/components/chat/copilot-chat-toolbar.component.d.ts +8 -0
- package/dist/components/chat/copilot-chat-tools-menu.component.d.ts +20 -0
- package/dist/components/chat/copilot-chat-user-message-branch-navigation.component.d.ts +23 -0
- package/dist/components/chat/copilot-chat-user-message-buttons.component.d.ts +39 -0
- package/dist/components/chat/copilot-chat-user-message-renderer.component.d.ts +9 -0
- package/dist/components/chat/copilot-chat-user-message-toolbar.component.d.ts +8 -0
- package/dist/components/chat/copilot-chat-user-message.component.d.ts +55 -0
- package/dist/components/chat/copilot-chat-user-message.types.d.ts +33 -0
- package/dist/components/chat/copilot-chat-view-disclaimer.component.d.ts +15 -0
- package/dist/components/chat/copilot-chat-view-feather.component.d.ts +15 -0
- package/dist/components/chat/copilot-chat-view-handlers.service.d.ts +11 -0
- package/dist/components/chat/copilot-chat-view-input-container.component.d.ts +23 -0
- package/dist/components/chat/copilot-chat-view-scroll-to-bottom-button.component.d.ts +17 -0
- package/dist/components/chat/copilot-chat-view-scroll-view.component.d.ts +84 -0
- package/dist/components/chat/copilot-chat-view.component.d.ts +205 -0
- package/dist/components/chat/copilot-chat-view.types.d.ts +42 -0
- package/dist/components/chat/copilot-chat.component.d.ts +37 -0
- package/dist/components/copilotkit-tool-render.component.d.ts +25 -0
- package/dist/core/chat-configuration/chat-configuration.providers.d.ts +54 -0
- package/dist/core/chat-configuration/chat-configuration.service.d.ts +75 -0
- package/dist/core/chat-configuration/chat-configuration.types.d.ts +27 -0
- package/dist/core/copilotkit.providers.d.ts +13 -0
- package/dist/core/copilotkit.service.d.ts +119 -0
- package/dist/core/copilotkit.types.d.ts +83 -0
- package/dist/directives/copilotkit-agent-context.directive.d.ts +68 -0
- package/dist/directives/copilotkit-agent.directive.d.ts +106 -0
- package/dist/directives/copilotkit-chat-config.directive.d.ts +84 -0
- package/dist/directives/copilotkit-config.directive.d.ts +44 -0
- package/dist/directives/copilotkit-frontend-tool.directive.d.ts +25 -0
- package/dist/directives/copilotkit-human-in-the-loop.directive.d.ts +124 -0
- package/dist/directives/stick-to-bottom.directive.d.ts +62 -0
- package/dist/fesm2022/copilotkitnext-angular.mjs +9314 -0
- package/dist/fesm2022/copilotkitnext-angular.mjs.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/lib/directives/tooltip.directive.d.ts +33 -0
- package/dist/lib/slots/copilot-slot.component.d.ts +34 -0
- package/dist/lib/slots/slot.types.d.ts +55 -0
- package/dist/lib/slots/slot.utils.d.ts +108 -0
- package/dist/lib/utils.d.ts +6 -0
- package/dist/services/resize-observer.service.d.ts +44 -0
- package/dist/services/scroll-position.service.d.ts +50 -0
- package/dist/styles.css +1963 -0
- package/dist/types/frontend-tool.d.ts +37 -0
- package/dist/types/human-in-the-loop.d.ts +44 -0
- package/dist/utils/agent-context.utils.d.ts +75 -0
- package/dist/utils/agent.utils.d.ts +99 -0
- package/dist/utils/chat-config.utils.d.ts +166 -0
- package/dist/utils/copilotkit.utils.d.ts +16 -0
- package/dist/utils/frontend-tool.utils.d.ts +119 -0
- package/dist/utils/human-in-the-loop.utils.d.ts +92 -0
- package/eslint.config.mjs +20 -0
- package/ng-package.json +19 -0
- package/package.json +96 -0
- package/slots.md +331 -0
- package/src/components/chat/__tests__/copilot-chat-assistant-message.component.spec.ts +282 -0
- package/src/components/chat/__tests__/copilot-chat-input.component.spec.ts +419 -0
- package/src/components/chat/__tests__/copilot-chat-message-view.component.spec.ts +372 -0
- package/src/components/chat/__tests__/copilot-chat-user-message.component.spec.ts +249 -0
- package/src/components/chat/copilot-chat-assistant-message-buttons.component.ts +292 -0
- package/src/components/chat/copilot-chat-assistant-message-renderer.component.ts +472 -0
- package/src/components/chat/copilot-chat-assistant-message-toolbar.component.ts +29 -0
- package/src/components/chat/copilot-chat-assistant-message.component.ts +463 -0
- package/src/components/chat/copilot-chat-assistant-message.types.ts +50 -0
- package/src/components/chat/copilot-chat-audio-recorder.component.ts +241 -0
- package/src/components/chat/copilot-chat-buttons.component.ts +308 -0
- package/src/components/chat/copilot-chat-buttons.component.ts.bak +471 -0
- package/src/components/chat/copilot-chat-input-defaults.ts +47 -0
- package/src/components/chat/copilot-chat-input.component.ts +512 -0
- package/src/components/chat/copilot-chat-input.types.ts +148 -0
- package/src/components/chat/copilot-chat-message-view-cursor.component.ts +51 -0
- package/src/components/chat/copilot-chat-message-view.component.ts +233 -0
- package/src/components/chat/copilot-chat-message-view.types.ts +39 -0
- package/src/components/chat/copilot-chat-textarea.component.ts +220 -0
- package/src/components/chat/copilot-chat-tool-calls-view.component.ts +261 -0
- package/src/components/chat/copilot-chat-toolbar.component.ts +35 -0
- package/src/components/chat/copilot-chat-tools-menu.component.ts +185 -0
- package/src/components/chat/copilot-chat-user-message-branch-navigation.component.ts +121 -0
- package/src/components/chat/copilot-chat-user-message-buttons.component.ts +170 -0
- package/src/components/chat/copilot-chat-user-message-renderer.component.ts +37 -0
- package/src/components/chat/copilot-chat-user-message-toolbar.component.ts +37 -0
- package/src/components/chat/copilot-chat-user-message.component.ts +247 -0
- package/src/components/chat/copilot-chat-user-message.types.ts +42 -0
- package/src/components/chat/copilot-chat-view-disclaimer.component.ts +51 -0
- package/src/components/chat/copilot-chat-view-feather.component.ts +47 -0
- package/src/components/chat/copilot-chat-view-handlers.service.ts +14 -0
- package/src/components/chat/copilot-chat-view-input-container.component.ts +87 -0
- package/src/components/chat/copilot-chat-view-scroll-to-bottom-button.component.ts +79 -0
- package/src/components/chat/copilot-chat-view-scroll-view.component.ts +322 -0
- package/src/components/chat/copilot-chat-view.component.ts +420 -0
- package/src/components/chat/copilot-chat-view.types.ts +52 -0
- package/src/components/chat/copilot-chat.component.ts +232 -0
- package/src/components/copilotkit-tool-render.component.ts +169 -0
- package/src/core/__tests__/copilotkit.service.spec.ts +1051 -0
- package/src/core/__tests__/copilotkit.service.wildcard.spec.ts +316 -0
- package/src/core/chat-configuration/__tests__/chat-configuration.service.spec.ts +287 -0
- package/src/core/chat-configuration/chat-configuration.providers.ts +71 -0
- package/src/core/chat-configuration/chat-configuration.service.ts +162 -0
- package/src/core/chat-configuration/chat-configuration.types.ts +57 -0
- package/src/core/copilotkit.providers.ts +59 -0
- package/src/core/copilotkit.service.ts +542 -0
- package/src/core/copilotkit.types.ts +132 -0
- package/src/directives/__tests__/copilotkit-agent-context.directive.spec.ts +384 -0
- package/src/directives/__tests__/copilotkit-agent.directive.spec.ts +253 -0
- package/src/directives/__tests__/copilotkit-chat-config.directive.spec.ts +385 -0
- package/src/directives/__tests__/copilotkit-config.directive.spec.ts +69 -0
- package/src/directives/__tests__/copilotkit-frontend-tool-simple.directive.spec.ts +60 -0
- package/src/directives/__tests__/copilotkit-frontend-tool.directive.spec.ts +108 -0
- package/src/directives/__tests__/copilotkit-human-in-the-loop.directive.spec.ts +452 -0
- package/src/directives/copilotkit-agent-context.directive.ts +138 -0
- package/src/directives/copilotkit-agent.directive.ts +225 -0
- package/src/directives/copilotkit-chat-config.directive.ts +241 -0
- package/src/directives/copilotkit-config.directive.ts +81 -0
- package/src/directives/copilotkit-frontend-tool.directive.ts +145 -0
- package/src/directives/copilotkit-human-in-the-loop.directive.ts +281 -0
- package/src/directives/stick-to-bottom.directive.ts +204 -0
- package/src/index.ts +105 -0
- package/src/lib/directives/tooltip.directive.ts +292 -0
- package/src/lib/slots/__tests__/slot.utils.spec.ts +377 -0
- package/src/lib/slots/copilot-slot.component.ts +135 -0
- package/src/lib/slots/index.ts +3 -0
- package/src/lib/slots/slot.types.ts +64 -0
- package/src/lib/slots/slot.utils.ts +289 -0
- package/src/lib/utils.ts +10 -0
- package/src/public-api.ts +1 -0
- package/src/services/resize-observer.service.ts +181 -0
- package/src/services/scroll-position.service.ts +169 -0
- package/src/styles/globals.css +266 -0
- package/src/styles/index.css +3 -0
- package/src/test-setup.ts +15 -0
- package/src/testing/index.ts +3 -0
- package/src/testing/testing.utils.ts +248 -0
- package/src/types/frontend-tool.ts +44 -0
- package/src/types/human-in-the-loop.ts +52 -0
- package/src/utils/__tests__/agent.utils.spec.ts +234 -0
- package/src/utils/__tests__/chat-config.utils.spec.ts +306 -0
- package/src/utils/__tests__/frontend-tool-inject.spec.ts +350 -0
- package/src/utils/__tests__/frontend-tool-integration.spec.ts +199 -0
- package/src/utils/__tests__/frontend-tool.utils.spec.ts +272 -0
- package/src/utils/__tests__/human-in-the-loop.utils.spec.ts +365 -0
- package/src/utils/agent-context.utils.ts +133 -0
- package/src/utils/agent.utils.ts +239 -0
- package/src/utils/chat-config.utils.ts +221 -0
- package/src/utils/copilotkit.utils.ts +20 -0
- package/src/utils/frontend-tool.utils.ts +266 -0
- package/src/utils/human-in-the-loop.utils.ts +359 -0
- package/tsconfig.json +33 -0
- package/tsconfig.spec.json +12 -0
- package/vitest.config.mts +34 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
Input,
|
|
4
|
+
Output,
|
|
5
|
+
EventEmitter,
|
|
6
|
+
signal,
|
|
7
|
+
computed,
|
|
8
|
+
ChangeDetectionStrategy,
|
|
9
|
+
ChangeDetectorRef,
|
|
10
|
+
ViewEncapsulation,
|
|
11
|
+
inject
|
|
12
|
+
} from '@angular/core';
|
|
13
|
+
import { CommonModule } from '@angular/common';
|
|
14
|
+
import { LucideAngularModule, Copy, Check, Edit } from 'lucide-angular';
|
|
15
|
+
import { CopilotTooltipDirective } from '../../lib/directives/tooltip.directive';
|
|
16
|
+
import { CopilotChatConfigurationService } from '../../core/chat-configuration/chat-configuration.service';
|
|
17
|
+
import { cn } from '../../lib/utils';
|
|
18
|
+
|
|
19
|
+
// Base toolbar button component
|
|
20
|
+
@Component({
|
|
21
|
+
selector: 'button[copilotChatUserMessageToolbarButton]',
|
|
22
|
+
standalone: true,
|
|
23
|
+
imports: [CommonModule],
|
|
24
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
25
|
+
encapsulation: ViewEncapsulation.None,
|
|
26
|
+
template: `
|
|
27
|
+
<ng-content></ng-content>
|
|
28
|
+
`,
|
|
29
|
+
host: {
|
|
30
|
+
'[class]': 'computedClass()',
|
|
31
|
+
'[attr.disabled]': 'disabled ? true : null',
|
|
32
|
+
'type': 'button',
|
|
33
|
+
'[attr.aria-label]': 'title'
|
|
34
|
+
},
|
|
35
|
+
hostDirectives: [
|
|
36
|
+
{
|
|
37
|
+
directive: CopilotTooltipDirective,
|
|
38
|
+
inputs: ['copilotTooltip: title', 'tooltipPosition', 'tooltipDelay']
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
})
|
|
42
|
+
export class CopilotChatUserMessageToolbarButtonComponent {
|
|
43
|
+
@Input() title = '';
|
|
44
|
+
@Input() disabled = false;
|
|
45
|
+
@Input() set inputClass(value: string | undefined) {
|
|
46
|
+
this.customClass.set(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private customClass = signal<string | undefined>(undefined);
|
|
50
|
+
|
|
51
|
+
computedClass = computed(() => {
|
|
52
|
+
return cn(
|
|
53
|
+
// Flex centering
|
|
54
|
+
'inline-flex items-center justify-center',
|
|
55
|
+
// Cursor
|
|
56
|
+
'cursor-pointer',
|
|
57
|
+
// Background and text
|
|
58
|
+
'p-0 text-[rgb(93,93,93)] hover:bg-[#E8E8E8]',
|
|
59
|
+
// Dark mode
|
|
60
|
+
'dark:text-[rgb(243,243,243)] dark:hover:bg-[#303030]',
|
|
61
|
+
// Shape and sizing
|
|
62
|
+
'h-8 w-8 rounded-md',
|
|
63
|
+
// Interactions
|
|
64
|
+
'transition-colors',
|
|
65
|
+
// Hover states
|
|
66
|
+
'hover:text-[rgb(93,93,93)]',
|
|
67
|
+
'dark:hover:text-[rgb(243,243,243)]',
|
|
68
|
+
// Focus states
|
|
69
|
+
'focus:outline-none focus:ring-2 focus:ring-offset-2',
|
|
70
|
+
// Disabled state
|
|
71
|
+
'disabled:opacity-50 disabled:cursor-not-allowed',
|
|
72
|
+
this.customClass()
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Copy button component
|
|
78
|
+
@Component({
|
|
79
|
+
selector: 'copilot-chat-user-message-copy-button',
|
|
80
|
+
standalone: true,
|
|
81
|
+
imports: [CommonModule, LucideAngularModule, CopilotChatUserMessageToolbarButtonComponent],
|
|
82
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
83
|
+
encapsulation: ViewEncapsulation.None,
|
|
84
|
+
template: `
|
|
85
|
+
<button
|
|
86
|
+
copilotChatUserMessageToolbarButton
|
|
87
|
+
[title]="title || labels.userMessageToolbarCopyMessageLabel"
|
|
88
|
+
[disabled]="disabled"
|
|
89
|
+
[inputClass]="inputClass"
|
|
90
|
+
(click)="handleCopy()">
|
|
91
|
+
@if (copied()) {
|
|
92
|
+
<lucide-angular [img]="CheckIcon" [size]="18"></lucide-angular>
|
|
93
|
+
} @else {
|
|
94
|
+
<lucide-angular [img]="CopyIcon" [size]="18"></lucide-angular>
|
|
95
|
+
}
|
|
96
|
+
</button>
|
|
97
|
+
`
|
|
98
|
+
})
|
|
99
|
+
export class CopilotChatUserMessageCopyButtonComponent {
|
|
100
|
+
@Input() title?: string;
|
|
101
|
+
@Input() disabled = false;
|
|
102
|
+
@Input() inputClass?: string;
|
|
103
|
+
@Input() content?: string;
|
|
104
|
+
@Output() clicked = new EventEmitter<void>();
|
|
105
|
+
|
|
106
|
+
readonly CopyIcon = Copy;
|
|
107
|
+
readonly CheckIcon = Check;
|
|
108
|
+
|
|
109
|
+
copied = signal(false);
|
|
110
|
+
private chatConfig = inject(CopilotChatConfigurationService);
|
|
111
|
+
|
|
112
|
+
get labels() {
|
|
113
|
+
return this.chatConfig.labels();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
handleCopy(): void {
|
|
117
|
+
if (!this.content) return;
|
|
118
|
+
|
|
119
|
+
// Set copied immediately for instant feedback
|
|
120
|
+
this.copied.set(true);
|
|
121
|
+
setTimeout(() => this.copied.set(false), 2000);
|
|
122
|
+
|
|
123
|
+
// Copy to clipboard (fire and forget)
|
|
124
|
+
navigator.clipboard.writeText(this.content).then(
|
|
125
|
+
() => this.clicked.emit(),
|
|
126
|
+
(err) => {
|
|
127
|
+
console.error('Failed to copy message:', err);
|
|
128
|
+
this.copied.set(false);
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Edit button component
|
|
135
|
+
@Component({
|
|
136
|
+
selector: 'copilot-chat-user-message-edit-button',
|
|
137
|
+
standalone: true,
|
|
138
|
+
imports: [CommonModule, LucideAngularModule, CopilotChatUserMessageToolbarButtonComponent],
|
|
139
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
140
|
+
encapsulation: ViewEncapsulation.None,
|
|
141
|
+
template: `
|
|
142
|
+
<button
|
|
143
|
+
copilotChatUserMessageToolbarButton
|
|
144
|
+
[title]="title || labels.userMessageToolbarEditMessageLabel"
|
|
145
|
+
[disabled]="disabled"
|
|
146
|
+
[inputClass]="inputClass"
|
|
147
|
+
(click)="handleEdit()">
|
|
148
|
+
<lucide-angular [img]="EditIcon" [size]="18"></lucide-angular>
|
|
149
|
+
</button>
|
|
150
|
+
`
|
|
151
|
+
})
|
|
152
|
+
export class CopilotChatUserMessageEditButtonComponent {
|
|
153
|
+
@Input() title?: string;
|
|
154
|
+
@Input() disabled = false;
|
|
155
|
+
@Input() inputClass?: string;
|
|
156
|
+
@Output() clicked = new EventEmitter<void>();
|
|
157
|
+
|
|
158
|
+
readonly EditIcon = Edit;
|
|
159
|
+
private chatConfig = inject(CopilotChatConfigurationService);
|
|
160
|
+
|
|
161
|
+
get labels() {
|
|
162
|
+
return this.chatConfig.labels();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
handleEdit(): void {
|
|
166
|
+
if (!this.disabled) {
|
|
167
|
+
this.clicked.emit();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
Input,
|
|
4
|
+
ChangeDetectionStrategy,
|
|
5
|
+
ViewEncapsulation,
|
|
6
|
+
computed,
|
|
7
|
+
signal
|
|
8
|
+
} from '@angular/core';
|
|
9
|
+
import { CommonModule } from '@angular/common';
|
|
10
|
+
import { cn } from '../../lib/utils';
|
|
11
|
+
|
|
12
|
+
@Component({
|
|
13
|
+
selector: 'copilot-chat-user-message-renderer',
|
|
14
|
+
standalone: true,
|
|
15
|
+
imports: [CommonModule],
|
|
16
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
17
|
+
encapsulation: ViewEncapsulation.None,
|
|
18
|
+
host: {
|
|
19
|
+
'[class]': 'computedClass()'
|
|
20
|
+
},
|
|
21
|
+
template: `{{ content }}`
|
|
22
|
+
})
|
|
23
|
+
export class CopilotChatUserMessageRendererComponent {
|
|
24
|
+
@Input() content = '';
|
|
25
|
+
@Input() set inputClass(value: string | undefined) {
|
|
26
|
+
this.customClass.set(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private customClass = signal<string | undefined>(undefined);
|
|
30
|
+
|
|
31
|
+
computedClass = computed(() => {
|
|
32
|
+
return cn(
|
|
33
|
+
"prose dark:prose-invert bg-muted relative max-w-[80%] rounded-[18px] px-4 py-1.5 data-[multiline]:py-3 inline-block whitespace-pre-wrap",
|
|
34
|
+
this.customClass()
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
Input,
|
|
4
|
+
ChangeDetectionStrategy,
|
|
5
|
+
ViewEncapsulation,
|
|
6
|
+
signal
|
|
7
|
+
} from '@angular/core';
|
|
8
|
+
import { CommonModule } from '@angular/common';
|
|
9
|
+
import { cn } from '../../lib/utils';
|
|
10
|
+
|
|
11
|
+
@Component({
|
|
12
|
+
selector: 'div[copilotChatUserMessageToolbar]',
|
|
13
|
+
standalone: true,
|
|
14
|
+
imports: [CommonModule],
|
|
15
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
16
|
+
encapsulation: ViewEncapsulation.None,
|
|
17
|
+
template: `
|
|
18
|
+
<ng-content></ng-content>
|
|
19
|
+
`,
|
|
20
|
+
host: {
|
|
21
|
+
'[class]': 'computedClass()'
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
export class CopilotChatUserMessageToolbarComponent {
|
|
25
|
+
@Input() inputClass?: string;
|
|
26
|
+
|
|
27
|
+
computedClass = signal<string>('');
|
|
28
|
+
|
|
29
|
+
ngOnInit() {
|
|
30
|
+
this.computedClass.set(
|
|
31
|
+
cn(
|
|
32
|
+
"w-full bg-transparent flex items-center justify-end mt-[4px] invisible group-hover:visible",
|
|
33
|
+
this.inputClass
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
Input,
|
|
4
|
+
Output,
|
|
5
|
+
EventEmitter,
|
|
6
|
+
TemplateRef,
|
|
7
|
+
ContentChild,
|
|
8
|
+
signal,
|
|
9
|
+
computed,
|
|
10
|
+
Type,
|
|
11
|
+
ChangeDetectionStrategy,
|
|
12
|
+
ViewEncapsulation
|
|
13
|
+
} from '@angular/core';
|
|
14
|
+
import { CommonModule } from '@angular/common';
|
|
15
|
+
import { CopilotSlotComponent } from '../../lib/slots/copilot-slot.component';
|
|
16
|
+
import {
|
|
17
|
+
type UserMessage,
|
|
18
|
+
type CopilotChatUserMessageOnEditMessageProps,
|
|
19
|
+
type CopilotChatUserMessageOnSwitchToBranchProps,
|
|
20
|
+
type MessageRendererContext,
|
|
21
|
+
type CopyButtonContext,
|
|
22
|
+
type EditButtonContext,
|
|
23
|
+
type BranchNavigationContext,
|
|
24
|
+
type ToolbarContext
|
|
25
|
+
} from './copilot-chat-user-message.types';
|
|
26
|
+
import { CopilotChatUserMessageRendererComponent } from './copilot-chat-user-message-renderer.component';
|
|
27
|
+
import {
|
|
28
|
+
CopilotChatUserMessageCopyButtonComponent,
|
|
29
|
+
CopilotChatUserMessageEditButtonComponent
|
|
30
|
+
} from './copilot-chat-user-message-buttons.component';
|
|
31
|
+
import { CopilotChatUserMessageToolbarComponent } from './copilot-chat-user-message-toolbar.component';
|
|
32
|
+
import { CopilotChatUserMessageBranchNavigationComponent } from './copilot-chat-user-message-branch-navigation.component';
|
|
33
|
+
import { cn } from '../../lib/utils';
|
|
34
|
+
|
|
35
|
+
@Component({
|
|
36
|
+
selector: 'copilot-chat-user-message',
|
|
37
|
+
standalone: true,
|
|
38
|
+
imports: [
|
|
39
|
+
CommonModule,
|
|
40
|
+
CopilotSlotComponent,
|
|
41
|
+
CopilotChatUserMessageRendererComponent,
|
|
42
|
+
CopilotChatUserMessageCopyButtonComponent,
|
|
43
|
+
CopilotChatUserMessageEditButtonComponent,
|
|
44
|
+
CopilotChatUserMessageToolbarComponent,
|
|
45
|
+
CopilotChatUserMessageBranchNavigationComponent
|
|
46
|
+
],
|
|
47
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
48
|
+
encapsulation: ViewEncapsulation.None,
|
|
49
|
+
template: `
|
|
50
|
+
<div
|
|
51
|
+
[class]="computedClass()"
|
|
52
|
+
[attr.data-message-id]="message.id">
|
|
53
|
+
|
|
54
|
+
<!-- Message Renderer -->
|
|
55
|
+
@if (messageRendererTemplate || messageRendererComponent) {
|
|
56
|
+
<copilot-slot
|
|
57
|
+
[slot]="messageRendererTemplate || messageRendererComponent"
|
|
58
|
+
[context]="messageRendererContext()"
|
|
59
|
+
[defaultComponent]="CopilotChatUserMessageRendererComponent"
|
|
60
|
+
>
|
|
61
|
+
</copilot-slot>
|
|
62
|
+
} @else {
|
|
63
|
+
<copilot-chat-user-message-renderer
|
|
64
|
+
[content]="message.content || ''"
|
|
65
|
+
[inputClass]="messageRendererClass">
|
|
66
|
+
</copilot-chat-user-message-renderer>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
<!-- Toolbar -->
|
|
70
|
+
@if (toolbarTemplate || toolbarComponent) {
|
|
71
|
+
<copilot-slot
|
|
72
|
+
[slot]="toolbarTemplate || toolbarComponent"
|
|
73
|
+
[context]="toolbarContext()"
|
|
74
|
+
[defaultComponent]="CopilotChatUserMessageToolbarComponent"
|
|
75
|
+
>
|
|
76
|
+
</copilot-slot>
|
|
77
|
+
} @else {
|
|
78
|
+
<div copilotChatUserMessageToolbar [inputClass]="toolbarClass">
|
|
79
|
+
<div class="flex items-center gap-1 justify-end">
|
|
80
|
+
<!-- Additional toolbar items -->
|
|
81
|
+
@if (additionalToolbarItems) {
|
|
82
|
+
<ng-container *ngTemplateOutlet="additionalToolbarItems"></ng-container>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
<!-- Copy button -->
|
|
86
|
+
@if (copyButtonTemplate || copyButtonComponent) {
|
|
87
|
+
<copilot-slot
|
|
88
|
+
[slot]="copyButtonTemplate || copyButtonComponent"
|
|
89
|
+
[context]="{ content: message?.content || '' }"
|
|
90
|
+
[outputs]="copyButtonOutputs"
|
|
91
|
+
[defaultComponent]="CopilotChatUserMessageCopyButtonComponent"
|
|
92
|
+
>
|
|
93
|
+
</copilot-slot>
|
|
94
|
+
} @else {
|
|
95
|
+
<copilot-chat-user-message-copy-button
|
|
96
|
+
[content]="message.content"
|
|
97
|
+
[inputClass]="copyButtonClass"
|
|
98
|
+
(clicked)="handleCopy()">
|
|
99
|
+
</copilot-chat-user-message-copy-button>
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
<!-- Edit button -->
|
|
103
|
+
@if (editMessage.observed) {
|
|
104
|
+
@if (editButtonTemplate || editButtonComponent) {
|
|
105
|
+
<copilot-slot
|
|
106
|
+
[slot]="editButtonTemplate || editButtonComponent"
|
|
107
|
+
[context]="{}"
|
|
108
|
+
[outputs]="editButtonOutputs"
|
|
109
|
+
[defaultComponent]="CopilotChatUserMessageEditButtonComponent"
|
|
110
|
+
>
|
|
111
|
+
</copilot-slot>
|
|
112
|
+
} @else {
|
|
113
|
+
<copilot-chat-user-message-edit-button
|
|
114
|
+
[inputClass]="editButtonClass"
|
|
115
|
+
(clicked)="handleEdit()">
|
|
116
|
+
</copilot-chat-user-message-edit-button>
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
<!-- Branch navigation -->
|
|
121
|
+
@if (showBranchNavigation()) {
|
|
122
|
+
@if (branchNavigationTemplate || branchNavigationComponent) {
|
|
123
|
+
<copilot-slot
|
|
124
|
+
[slot]="branchNavigationTemplate || branchNavigationComponent"
|
|
125
|
+
[context]="branchNavigationContext()"
|
|
126
|
+
[defaultComponent]="CopilotChatUserMessageBranchNavigationComponent"
|
|
127
|
+
>
|
|
128
|
+
</copilot-slot>
|
|
129
|
+
} @else {
|
|
130
|
+
<copilot-chat-user-message-branch-navigation
|
|
131
|
+
[currentBranch]="branchIndexSignal()"
|
|
132
|
+
[numberOfBranches]="numberOfBranchesSignal()"
|
|
133
|
+
[message]="message"
|
|
134
|
+
[inputClass]="branchNavigationClass"
|
|
135
|
+
(switchToBranch)="handleSwitchToBranch($event)">
|
|
136
|
+
</copilot-chat-user-message-branch-navigation>
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
}
|
|
142
|
+
</div>
|
|
143
|
+
`,
|
|
144
|
+
styles: [`
|
|
145
|
+
:host {
|
|
146
|
+
display: block;
|
|
147
|
+
width: 100%;
|
|
148
|
+
}
|
|
149
|
+
`]
|
|
150
|
+
})
|
|
151
|
+
export class CopilotChatUserMessageComponent {
|
|
152
|
+
// Capture templates from content projection
|
|
153
|
+
@ContentChild('messageRenderer', { read: TemplateRef }) messageRendererTemplate?: TemplateRef<MessageRendererContext>;
|
|
154
|
+
@ContentChild('toolbar', { read: TemplateRef }) toolbarTemplate?: TemplateRef<ToolbarContext>;
|
|
155
|
+
@ContentChild('copyButton', { read: TemplateRef }) copyButtonTemplate?: TemplateRef<CopyButtonContext>;
|
|
156
|
+
@ContentChild('editButton', { read: TemplateRef }) editButtonTemplate?: TemplateRef<EditButtonContext>;
|
|
157
|
+
@ContentChild('branchNavigation', { read: TemplateRef }) branchNavigationTemplate?: TemplateRef<BranchNavigationContext>;
|
|
158
|
+
|
|
159
|
+
// Props for tweaking default components
|
|
160
|
+
@Input() messageRendererClass?: string;
|
|
161
|
+
@Input() toolbarClass?: string;
|
|
162
|
+
@Input() copyButtonClass?: string;
|
|
163
|
+
@Input() editButtonClass?: string;
|
|
164
|
+
@Input() branchNavigationClass?: string;
|
|
165
|
+
|
|
166
|
+
// Component inputs for overrides
|
|
167
|
+
@Input() messageRendererComponent?: Type<any>;
|
|
168
|
+
@Input() toolbarComponent?: Type<any>;
|
|
169
|
+
@Input() copyButtonComponent?: Type<any>;
|
|
170
|
+
@Input() editButtonComponent?: Type<any>;
|
|
171
|
+
@Input() branchNavigationComponent?: Type<any>;
|
|
172
|
+
|
|
173
|
+
// Regular inputs
|
|
174
|
+
@Input() message!: UserMessage;
|
|
175
|
+
@Input() set branchIndex(val: number | undefined) {
|
|
176
|
+
this.branchIndexSignal.set(val ?? 0);
|
|
177
|
+
}
|
|
178
|
+
@Input() set numberOfBranches(val: number | undefined) {
|
|
179
|
+
this.numberOfBranchesSignal.set(val ?? 1);
|
|
180
|
+
}
|
|
181
|
+
@Input() additionalToolbarItems?: TemplateRef<any>;
|
|
182
|
+
@Input() set inputClass(val: string | undefined) {
|
|
183
|
+
this.customClass.set(val);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Output events
|
|
187
|
+
@Output() editMessage = new EventEmitter<CopilotChatUserMessageOnEditMessageProps>();
|
|
188
|
+
@Output() switchToBranch = new EventEmitter<CopilotChatUserMessageOnSwitchToBranchProps>();
|
|
189
|
+
|
|
190
|
+
// Signals
|
|
191
|
+
branchIndexSignal = signal(0);
|
|
192
|
+
numberOfBranchesSignal = signal(1);
|
|
193
|
+
customClass = signal<string | undefined>(undefined);
|
|
194
|
+
|
|
195
|
+
// Default components
|
|
196
|
+
CopilotChatUserMessageRendererComponent = CopilotChatUserMessageRendererComponent;
|
|
197
|
+
CopilotChatUserMessageToolbarComponent = CopilotChatUserMessageToolbarComponent;
|
|
198
|
+
CopilotChatUserMessageCopyButtonComponent = CopilotChatUserMessageCopyButtonComponent;
|
|
199
|
+
CopilotChatUserMessageEditButtonComponent = CopilotChatUserMessageEditButtonComponent;
|
|
200
|
+
CopilotChatUserMessageBranchNavigationComponent = CopilotChatUserMessageBranchNavigationComponent;
|
|
201
|
+
|
|
202
|
+
// Computed values
|
|
203
|
+
showBranchNavigation = computed(() => {
|
|
204
|
+
const branches = this.numberOfBranchesSignal();
|
|
205
|
+
return branches > 1 && this.switchToBranch.observed;
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
computedClass = computed(() => {
|
|
209
|
+
return cn(
|
|
210
|
+
"flex flex-col items-end group pt-10",
|
|
211
|
+
this.customClass()
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Context for slots (reactive via signals)
|
|
216
|
+
messageRendererContext = computed<MessageRendererContext>(() => ({
|
|
217
|
+
content: this.message?.content || ''
|
|
218
|
+
}));
|
|
219
|
+
|
|
220
|
+
// Output maps for slots
|
|
221
|
+
copyButtonOutputs = { clicked: () => this.handleCopy() };
|
|
222
|
+
editButtonOutputs = { clicked: () => this.handleEdit() };
|
|
223
|
+
|
|
224
|
+
branchNavigationContext = computed<BranchNavigationContext>(() => ({
|
|
225
|
+
currentBranch: this.branchIndexSignal(),
|
|
226
|
+
numberOfBranches: this.numberOfBranchesSignal(),
|
|
227
|
+
onSwitchToBranch: (props) => this.handleSwitchToBranch(props),
|
|
228
|
+
message: this.message
|
|
229
|
+
}));
|
|
230
|
+
|
|
231
|
+
toolbarContext = computed<ToolbarContext>(() => ({
|
|
232
|
+
children: null // Will be populated by the toolbar content
|
|
233
|
+
}));
|
|
234
|
+
|
|
235
|
+
handleCopy(): void {
|
|
236
|
+
// Copy is handled by the button component itself
|
|
237
|
+
// This is just for any additional logic if needed
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
handleEdit(): void {
|
|
241
|
+
this.editMessage.emit({ message: this.message });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
handleSwitchToBranch(props: CopilotChatUserMessageOnSwitchToBranchProps): void {
|
|
245
|
+
this.switchToBranch.emit(props);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface UserMessage {
|
|
2
|
+
id: string;
|
|
3
|
+
content?: string;
|
|
4
|
+
role: 'user';
|
|
5
|
+
timestamp?: Date;
|
|
6
|
+
[key: string]: any; // Allow additional properties
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CopilotChatUserMessageOnEditMessageProps {
|
|
10
|
+
message: UserMessage;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CopilotChatUserMessageOnSwitchToBranchProps {
|
|
14
|
+
message: UserMessage;
|
|
15
|
+
branchIndex: number;
|
|
16
|
+
numberOfBranches: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Context interfaces for slots
|
|
20
|
+
export interface MessageRendererContext {
|
|
21
|
+
content: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CopyButtonContext {
|
|
25
|
+
content?: string;
|
|
26
|
+
copied?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface EditButtonContext {
|
|
30
|
+
// Empty context - click handled via outputs map
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface BranchNavigationContext {
|
|
34
|
+
currentBranch: number;
|
|
35
|
+
numberOfBranches: number;
|
|
36
|
+
onSwitchToBranch?: (props: CopilotChatUserMessageOnSwitchToBranchProps) => void;
|
|
37
|
+
message: UserMessage;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ToolbarContext {
|
|
41
|
+
children?: any;
|
|
42
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
Input,
|
|
4
|
+
ChangeDetectionStrategy,
|
|
5
|
+
ViewEncapsulation,
|
|
6
|
+
inject,
|
|
7
|
+
} from "@angular/core";
|
|
8
|
+
import { CommonModule } from "@angular/common";
|
|
9
|
+
import { CopilotChatConfigurationService } from "../../core/chat-configuration/chat-configuration.service";
|
|
10
|
+
import { cn } from "../../lib/utils";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Disclaimer component for CopilotChatView
|
|
14
|
+
* Shows configurable disclaimer text below the input
|
|
15
|
+
* Integrates with CopilotChatConfigurationService for labels
|
|
16
|
+
*/
|
|
17
|
+
@Component({
|
|
18
|
+
selector: "copilot-chat-view-disclaimer",
|
|
19
|
+
standalone: true,
|
|
20
|
+
imports: [CommonModule],
|
|
21
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
22
|
+
encapsulation: ViewEncapsulation.None,
|
|
23
|
+
template: `
|
|
24
|
+
<div [class]="computedClass">
|
|
25
|
+
{{ disclaimerText }}
|
|
26
|
+
</div>
|
|
27
|
+
`,
|
|
28
|
+
})
|
|
29
|
+
export class CopilotChatViewDisclaimerComponent {
|
|
30
|
+
@Input() inputClass?: string;
|
|
31
|
+
@Input() text?: string;
|
|
32
|
+
|
|
33
|
+
private configService = inject(CopilotChatConfigurationService);
|
|
34
|
+
|
|
35
|
+
// Get disclaimer text from input or configuration
|
|
36
|
+
get disclaimerText(): string {
|
|
37
|
+
if (this.text) {
|
|
38
|
+
return this.text;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return this.configService.labels().chatDisclaimerText;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Computed class matching React exactly
|
|
45
|
+
get computedClass(): string {
|
|
46
|
+
return cn(
|
|
47
|
+
"text-center text-xs text-muted-foreground py-3 px-4 max-w-3xl mx-auto",
|
|
48
|
+
this.inputClass
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
Input,
|
|
4
|
+
ChangeDetectionStrategy,
|
|
5
|
+
ViewEncapsulation
|
|
6
|
+
} from '@angular/core';
|
|
7
|
+
import { CommonModule } from '@angular/common';
|
|
8
|
+
import { cn } from '../../lib/utils';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Feather component for CopilotChatView
|
|
12
|
+
* Creates a gradient overlay effect between messages and input
|
|
13
|
+
* Matches React implementation exactly with same Tailwind classes
|
|
14
|
+
*/
|
|
15
|
+
@Component({
|
|
16
|
+
selector: 'copilot-chat-view-feather',
|
|
17
|
+
standalone: true,
|
|
18
|
+
imports: [CommonModule],
|
|
19
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
20
|
+
encapsulation: ViewEncapsulation.None,
|
|
21
|
+
template: `
|
|
22
|
+
<div
|
|
23
|
+
[class]="computedClass"
|
|
24
|
+
[style]="style">
|
|
25
|
+
</div>
|
|
26
|
+
`
|
|
27
|
+
})
|
|
28
|
+
export class CopilotChatViewFeatherComponent {
|
|
29
|
+
@Input() inputClass?: string;
|
|
30
|
+
@Input() style?: { [key: string]: any };
|
|
31
|
+
|
|
32
|
+
// Computed class matching React exactly
|
|
33
|
+
get computedClass(): string {
|
|
34
|
+
return cn(
|
|
35
|
+
// Positioning
|
|
36
|
+
'absolute bottom-0 left-0 right-4 h-24 pointer-events-none z-10',
|
|
37
|
+
// Gradient
|
|
38
|
+
'bg-gradient-to-t',
|
|
39
|
+
// Light mode colors
|
|
40
|
+
'from-white via-white to-transparent',
|
|
41
|
+
// Dark mode colors
|
|
42
|
+
'dark:from-[rgb(33,33,33)] dark:via-[rgb(33,33,33)]',
|
|
43
|
+
// Custom classes
|
|
44
|
+
this.inputClass
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Injectable, signal } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Injectable({ providedIn: 'root' })
|
|
4
|
+
export class CopilotChatViewHandlersService {
|
|
5
|
+
// Assistant message handler availability
|
|
6
|
+
hasAssistantThumbsUpHandler = signal(false);
|
|
7
|
+
hasAssistantThumbsDownHandler = signal(false);
|
|
8
|
+
hasAssistantReadAloudHandler = signal(false);
|
|
9
|
+
hasAssistantRegenerateHandler = signal(false);
|
|
10
|
+
|
|
11
|
+
// User message handler availability
|
|
12
|
+
hasUserCopyHandler = signal(false);
|
|
13
|
+
hasUserEditHandler = signal(false);
|
|
14
|
+
}
|