@aleph-alpha/chat-kit 5.12.0 → 6.0.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/dist/{CkHistory.vue_vue_type_script_setup_true_lang-CImSzLYs.js → CkHistory.vue_vue_type_script_setup_true_lang-D9Ph9eYp.js} +115 -31
- package/dist/adapters/responses-api.d.ts +1 -1
- package/dist/adapters/responses-api.d.ts.map +1 -1
- package/dist/adapters/responses-api.js +9 -7
- package/dist/chat-kit.css +12 -12
- package/dist/components/base/CkCitation/CkCitation.stories.d.ts +1 -4
- package/dist/components/base/CkCitation/CkCitation.stories.d.ts.map +1 -1
- package/dist/components/base/CkCitation/CkCitation.vue.d.ts.map +1 -1
- package/dist/components/base/CkCitation/types.d.ts +6 -1
- package/dist/components/base/CkCitation/types.d.ts.map +1 -1
- package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts +13 -2
- package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts.map +1 -1
- package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts +1 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts.map +1 -1
- package/dist/components/base/CkCitationCard/types.d.ts +6 -1
- package/dist/components/base/CkCitationCard/types.d.ts.map +1 -1
- package/dist/components/base/CkCitationLabel/CkCitationLabel.vue.d.ts.map +1 -1
- package/dist/components/base/CkHistoryItem/CkHistoryItem.vue.d.ts.map +1 -1
- package/dist/components/base/CkHistoryWrapper/CkHistoryWrapper.vue.d.ts.map +1 -1
- package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/composables/fileUpload/useFileUpload.d.ts.map +1 -1
- package/dist/composables/index.js +1 -1
- package/dist/composables/useChat.d.ts.map +1 -1
- package/dist/composables/useConversations.d.ts.map +1 -1
- package/dist/composables/useIsTruncated.d.ts +22 -0
- package/dist/composables/useIsTruncated.d.ts.map +1 -0
- package/dist/handlers/index.js +1 -1
- package/dist/handlers/useChatKitLabels.d.ts +35 -1
- package/dist/handlers/useChatKitLabels.d.ts.map +1 -1
- package/dist/{index-Dn4ctxk8.js → index-C72e57-5.js} +48 -24
- package/dist/index.js +3 -3
- package/dist/test-utils/createTextPlugin.d.ts +7 -1
- package/dist/test-utils/createTextPlugin.d.ts.map +1 -1
- package/dist/{useChatKitLabels-CMOr3Kjq.js → useChatKitLabels-368lodS5.js} +1 -1
- package/package.json +4 -4
- package/src/adapters/responses-api.spec.ts +86 -0
- package/src/adapters/responses-api.ts +13 -9
- package/src/components/base/CkCitation/CkCitation.spec.ts +3 -3
- package/src/components/base/CkCitation/CkCitation.stories.ts +85 -3
- package/src/components/base/CkCitation/CkCitation.vue +5 -1
- package/src/components/base/CkCitation/types.ts +6 -1
- package/src/components/base/CkCitationCard/CkCitationCard.spec.ts +37 -0
- package/src/components/base/CkCitationCard/CkCitationCard.stories.ts +30 -3
- package/src/components/base/CkCitationCard/CkCitationCard.vue +54 -12
- package/src/components/base/CkCitationCard/types.ts +6 -1
- package/src/components/base/CkCitationLabel/CkCitationLabel.spec.ts +3 -3
- package/src/components/base/CkCitationLabel/CkCitationLabel.vue +7 -6
- package/src/components/base/CkConversationLayout/CkConversationLayout.spec.ts +1 -5
- package/src/components/base/CkCopyMessageButton/CkCopyMessageButton.spec.ts +1 -1
- package/src/components/base/CkFeedbackButton/CkFeedbackButton.vue +3 -3
- package/src/components/base/CkFeedbackDialog/CkFeedbackDialog.spec.ts +1 -1
- package/src/components/base/CkFeedbackDialog/CkFeedbackDialog.vue +9 -9
- package/src/components/base/CkHistoryItem/CkHistoryItem.vue +5 -7
- package/src/components/base/CkHistoryWrapper/CkHistoryWrapper.vue +2 -1
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.ts +9 -4
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue +1 -1
- package/src/components/base/CkModelSelector/CkModelSelector.vue +3 -3
- package/src/composables/fileUpload/useFileUpload.ts +45 -30
- package/src/composables/fileUpload/useFileUploadWrapper.spec.ts +1 -1
- package/src/composables/fileUpload/useFileUploadWrapper.ts +3 -3
- package/src/composables/useChat.ts +3 -1
- package/src/composables/useConversations.ts +8 -5
- package/src/composables/useIsTruncated.ts +82 -0
- package/src/handlers/useChatKitLabels.spec.ts +0 -1
- package/src/handlers/useChatKitLabels.ts +2 -2
- package/src/handlers/useMarkdownParser.ts +1 -1
- package/src/test-setup.ts +3 -3
- package/src/test-utils/createTextPlugin.ts +11 -3
|
@@ -141,7 +141,11 @@ export type ResponseOutputToolType =
|
|
|
141
141
|
| 'file_search_call'
|
|
142
142
|
| 'code_interpreter_call'
|
|
143
143
|
| 'image_generation_call'
|
|
144
|
-
| 'local_shell_call'
|
|
144
|
+
| 'local_shell_call'
|
|
145
|
+
// Hosted Aleph Alpha extras. `shell_call` is the stored skill-fetch
|
|
146
|
+
// wrapper; `fetch_url` is the page-read behind hosted web search.
|
|
147
|
+
| 'shell_call'
|
|
148
|
+
| 'fetch_url';
|
|
145
149
|
|
|
146
150
|
/**
|
|
147
151
|
* Server-provided rendering hints for a tool invocation. The server emits a
|
|
@@ -377,16 +381,16 @@ function toAssistantParts(resp: StoredResponse): MessageContent[] {
|
|
|
377
381
|
parts.push(textPart(text, out.id || undefined));
|
|
378
382
|
break;
|
|
379
383
|
}
|
|
380
|
-
//
|
|
381
|
-
|
|
382
|
-
// a call the assistant made, so it is intentionally skipped.
|
|
383
|
-
case 'mcp_call':
|
|
384
|
-
case 'function_call':
|
|
385
|
-
case 'tool_call': {
|
|
386
|
-
parts.push(toolPart(out));
|
|
384
|
+
// Discovery catalog, not a call the assistant made.
|
|
385
|
+
case 'mcp_list_tools':
|
|
387
386
|
break;
|
|
388
|
-
|
|
387
|
+
// Every other `ResponseOutputTool` is an invocation — function /
|
|
388
|
+
// MCP / hosted builtins (`web_search_call`, `file_search_call`,
|
|
389
|
+
// `shell_call`, …). Hosts used to coerce those to `tool_call`
|
|
390
|
+
// before calling this adapter; converting them here keeps the
|
|
391
|
+
// stored item type intact for citations.
|
|
389
392
|
default:
|
|
393
|
+
parts.push(toolPart(out));
|
|
390
394
|
break;
|
|
391
395
|
}
|
|
392
396
|
}
|
|
@@ -72,11 +72,11 @@ describe('CkCitation', () => {
|
|
|
72
72
|
expect(marker).toHaveAttribute('aria-expanded', 'false');
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it('renders the default (
|
|
75
|
+
it('renders the default (neutral) marker state by default', () => {
|
|
76
76
|
render(CkCitation, { props: base });
|
|
77
77
|
|
|
78
78
|
const marker = screen.getByRole('button', { name: 'Source 1' });
|
|
79
|
-
expect(marker.className).toContain('bg-background-
|
|
79
|
+
expect(marker.className).toContain('bg-background-surface-citation');
|
|
80
80
|
expect(marker.className).not.toContain('bg-background-accent-soft');
|
|
81
81
|
});
|
|
82
82
|
|
|
@@ -85,6 +85,6 @@ describe('CkCitation', () => {
|
|
|
85
85
|
|
|
86
86
|
const marker = screen.getByRole('button', { name: 'Source 1' });
|
|
87
87
|
expect(marker.className).toContain('bg-background-accent-soft');
|
|
88
|
-
expect(marker.className).not.toContain('bg-background-
|
|
88
|
+
expect(marker.className).not.toContain('bg-background-surface-citation');
|
|
89
89
|
});
|
|
90
90
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import CkCitation from './CkCitation.vue';
|
|
2
|
+
import { CkCitationLabel } from '../CkCitationLabel';
|
|
2
3
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
3
4
|
|
|
4
5
|
const SNIPPET =
|
|
@@ -44,10 +45,91 @@ export default meta;
|
|
|
44
45
|
type Story = StoryObj<typeof meta>;
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
|
-
* A single marker in its default (
|
|
48
|
-
* press Enter) to reveal the source card.
|
|
48
|
+
* A single marker in its default (neutral) state. Hover the chip (or focus it
|
|
49
|
+
* and press Enter) to reveal the source card.
|
|
49
50
|
*/
|
|
50
|
-
|
|
51
|
+
const defaultTemplateSource = `<script setup lang="ts">
|
|
52
|
+
import { CkCitation } from '@aleph-alpha/chat-kit';
|
|
53
|
+
|
|
54
|
+
function openSource(url: string) {
|
|
55
|
+
// The source URL is often auth-proxied, so the host opens it.
|
|
56
|
+
window.open(url, '_blank', 'noopener');
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<p>
|
|
62
|
+
Departments with tailored training adopted the tools faster.<CkCitation
|
|
63
|
+
:index="1"
|
|
64
|
+
file-name="Q2_Business_Plan.pdf"
|
|
65
|
+
snippet="Lorem ipsum dolor sit amet consectetur…"
|
|
66
|
+
location-label="Page 3"
|
|
67
|
+
collection-name="Collection name"
|
|
68
|
+
url="/api/v1/search-stores/ss_abc/files/file_123/public-urls"
|
|
69
|
+
@open-source="openSource"
|
|
70
|
+
/>
|
|
71
|
+
</p>
|
|
72
|
+
</template>`;
|
|
73
|
+
|
|
74
|
+
export const Default: Story = {
|
|
75
|
+
parameters: { docs: { source: { code: defaultTemplateSource } } },
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The four marker states side by side, as specified in the design: default,
|
|
80
|
+
* hover, focus and selected. Hover and focus are live — mouse over the second
|
|
81
|
+
* chip or tab to the third to see them.
|
|
82
|
+
*/
|
|
83
|
+
const statesTemplateSource = `<script setup lang="ts">
|
|
84
|
+
import { CkCitationLabel } from '@aleph-alpha/chat-kit';
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<template>
|
|
88
|
+
<!-- \`hover-layer-active\` pins the hover overlay open; focus is a real
|
|
89
|
+
:focus-visible, so it only shows when the chip is focused. -->
|
|
90
|
+
<CkCitationLabel as="button" :index="1" />
|
|
91
|
+
<CkCitationLabel as="button" :index="1" class="hover-layer-active" />
|
|
92
|
+
<CkCitationLabel as="button" :index="1" />
|
|
93
|
+
<CkCitationLabel as="button" :index="1" selected />
|
|
94
|
+
</template>`;
|
|
95
|
+
|
|
96
|
+
export const States: Story = {
|
|
97
|
+
parameters: { docs: { source: { code: statesTemplateSource } } },
|
|
98
|
+
render: (args) => ({
|
|
99
|
+
components: { CkCitationLabel },
|
|
100
|
+
setup() {
|
|
101
|
+
return { args };
|
|
102
|
+
},
|
|
103
|
+
// `CkCitationLabel` renders the chip on its own, so each state can be shown
|
|
104
|
+
// at rest. Hover is forced with `hover-layer-active` (the class ui-library
|
|
105
|
+
// uses to pin its overlay open); focus is real, applied by the play
|
|
106
|
+
// function below, because `:focus-visible` cannot be faked with a class.
|
|
107
|
+
template: `
|
|
108
|
+
<div style="display: flex; align-items: flex-start; gap: 32px;">
|
|
109
|
+
<div style="display: grid; justify-items: center; gap: 8px;">
|
|
110
|
+
<CkCitationLabel v-bind="args" :index="1" as="button" />
|
|
111
|
+
<small style="font-size: 11px; opacity: 0.6;">default</small>
|
|
112
|
+
</div>
|
|
113
|
+
<div style="display: grid; justify-items: center; gap: 8px;">
|
|
114
|
+
<CkCitationLabel v-bind="args" :index="1" as="button" class="hover-layer-active" />
|
|
115
|
+
<small style="font-size: 11px; opacity: 0.6;">hover</small>
|
|
116
|
+
</div>
|
|
117
|
+
<div style="display: grid; justify-items: center; gap: 8px;">
|
|
118
|
+
<CkCitationLabel v-bind="args" :index="1" as="button" data-focus-demo />
|
|
119
|
+
<small style="font-size: 11px; opacity: 0.6;">focus</small>
|
|
120
|
+
</div>
|
|
121
|
+
<div style="display: grid; justify-items: center; gap: 8px;">
|
|
122
|
+
<CkCitationLabel v-bind="args" :index="1" as="button" selected />
|
|
123
|
+
<small style="font-size: 11px; opacity: 0.6;">selected</small>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
`,
|
|
127
|
+
}),
|
|
128
|
+
play: async ({ canvasElement }) => {
|
|
129
|
+
// A real focus, so the ring is the one keyboard users actually get.
|
|
130
|
+
canvasElement.querySelector<HTMLElement>('[data-focus-demo]')?.focus();
|
|
131
|
+
},
|
|
132
|
+
};
|
|
51
133
|
|
|
52
134
|
/**
|
|
53
135
|
* The selected (teal) state — set `selected` when the citation's source is the
|
|
@@ -109,10 +109,13 @@ onBeforeUnmount(() => {
|
|
|
109
109
|
<template>
|
|
110
110
|
<UiPopover v-model:open="open">
|
|
111
111
|
<UiPopoverTrigger as-child>
|
|
112
|
+
<!-- An open card is itself a selection: the chip the user is reading
|
|
113
|
+
about shows the selected state, so it stands out from its neighbours
|
|
114
|
+
while the card is up. -->
|
|
112
115
|
<CkCitationLabel
|
|
113
116
|
as="button"
|
|
114
117
|
:index="index"
|
|
115
|
-
:selected="selected"
|
|
118
|
+
:selected="selected || open"
|
|
116
119
|
:aria-label="ariaLabel"
|
|
117
120
|
@keydown="onTriggerKeydown"
|
|
118
121
|
@mouseenter="onPointerEnter"
|
|
@@ -134,6 +137,7 @@ onBeforeUnmount(() => {
|
|
|
134
137
|
:file-name="fileName"
|
|
135
138
|
:snippet="snippet"
|
|
136
139
|
:location-label="locationLabel"
|
|
140
|
+
:collection-name="collectionName"
|
|
137
141
|
:url="url"
|
|
138
142
|
:open-source-label="openSourceLabel"
|
|
139
143
|
@open-source="(u: string) => emit('open-source', u)"
|
|
@@ -27,6 +27,11 @@ export interface CkCitationSource {
|
|
|
27
27
|
* non-paginated sources.
|
|
28
28
|
*/
|
|
29
29
|
locationLabel?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Name of the collection the source belongs to, shown in the card footer
|
|
32
|
+
* before the location. Omit when the source has no collection.
|
|
33
|
+
*/
|
|
34
|
+
collectionName?: string;
|
|
30
35
|
/**
|
|
31
36
|
* Source URL for the card's external-link action. Activating it emits
|
|
32
37
|
* `open-source`. Omit to hide the action.
|
|
@@ -53,7 +58,7 @@ export interface CkCitationProps extends CkCitationSource {
|
|
|
53
58
|
/**
|
|
54
59
|
* Marks the citation as selected/active (e.g. the source it points to is
|
|
55
60
|
* currently open or highlighted). Renders the marker in its selected (teal)
|
|
56
|
-
* state instead of the default
|
|
61
|
+
* state instead of the default neutral one.
|
|
57
62
|
* @default false
|
|
58
63
|
*/
|
|
59
64
|
selected?: boolean;
|
|
@@ -69,6 +69,43 @@ describe('CkCitationCard', () => {
|
|
|
69
69
|
expect(screen.getByText(snippet).className).toContain('line-clamp-6');
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
+
it('shows the collection name before the location in the footer', () => {
|
|
73
|
+
render(CkCitationCard, {
|
|
74
|
+
props: { ...base, collectionName: 'EU AI Act', locationLabel: 'Page 3' },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const footer = screen.getByText('EU AI Act').closest('p');
|
|
78
|
+
expect(footer).toHaveTextContent('EU AI Act | Page 3');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('drops the separator when only one footer part is present', () => {
|
|
82
|
+
render(CkCitationCard, { props: { ...base, collectionName: 'EU AI Act' } });
|
|
83
|
+
|
|
84
|
+
expect(screen.getByText('EU AI Act').closest('p')).not.toHaveTextContent(
|
|
85
|
+
'|',
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('hides the footer entirely with neither a collection nor a location', () => {
|
|
90
|
+
render(CkCitationCard, { props: base });
|
|
91
|
+
|
|
92
|
+
expect(screen.queryByText('Page 3')).not.toBeInTheDocument();
|
|
93
|
+
expect(screen.queryByText('|')).not.toBeInTheDocument();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('keeps the location intact when the collection name is too long', () => {
|
|
97
|
+
const collectionName =
|
|
98
|
+
'Public Sector Knowledge Base — European Union Regulatory Corpus 2026';
|
|
99
|
+
render(CkCitationCard, {
|
|
100
|
+
props: { ...base, collectionName, locationLabel: 'Page 3' },
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// jsdom has no layout, so the guarantee is asserted through the classes
|
|
104
|
+
// that produce it: the name is the only part allowed to give way.
|
|
105
|
+
expect(screen.getByText(collectionName).className).toContain('truncate');
|
|
106
|
+
expect(screen.getByText('Page 3').className).toContain('shrink-0');
|
|
107
|
+
});
|
|
108
|
+
|
|
72
109
|
it('uses the injected citationOpenSource label via provideChatKitLabels', () => {
|
|
73
110
|
const Wrapper = defineComponent({
|
|
74
111
|
setup() {
|
|
@@ -20,6 +20,7 @@ const meta: Meta<typeof CkCitationCard> = {
|
|
|
20
20
|
fileName: { control: 'text' },
|
|
21
21
|
snippet: { control: 'text' },
|
|
22
22
|
locationLabel: { control: 'text' },
|
|
23
|
+
collectionName: { control: 'text' },
|
|
23
24
|
url: { control: 'text' },
|
|
24
25
|
openSourceLabel: { control: 'text' },
|
|
25
26
|
},
|
|
@@ -27,6 +28,7 @@ const meta: Meta<typeof CkCitationCard> = {
|
|
|
27
28
|
fileName: 'Q2_Business_Plan.pdf',
|
|
28
29
|
snippet: LOREM,
|
|
29
30
|
locationLabel: 'Page 3',
|
|
31
|
+
collectionName: 'Collection name',
|
|
30
32
|
url: '/api/v1/search-stores/ss_abc/files/file_123/public-urls',
|
|
31
33
|
},
|
|
32
34
|
decorators: [
|
|
@@ -76,19 +78,44 @@ export const WithoutLink: Story = {
|
|
|
76
78
|
};
|
|
77
79
|
|
|
78
80
|
/**
|
|
79
|
-
* No `locationLabel` — the footer
|
|
80
|
-
* such as a plain web page
|
|
81
|
+
* No `locationLabel` — the footer keeps just the collection. Use for
|
|
82
|
+
* non-paginated sources such as a plain web page.
|
|
81
83
|
*/
|
|
82
84
|
export const WithoutLocation: Story = {
|
|
83
85
|
args: { locationLabel: undefined },
|
|
84
86
|
};
|
|
85
87
|
|
|
88
|
+
/**
|
|
89
|
+
* No `collectionName` — the footer keeps just the location, and the separator
|
|
90
|
+
* goes with it. Use for sources that don't come from a collection.
|
|
91
|
+
*/
|
|
92
|
+
export const WithoutCollection: Story = {
|
|
93
|
+
args: { collectionName: undefined },
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A collection name longer than the card is wide. The name truncates and the
|
|
98
|
+
* location stays on the same line — the page a citation points at is the more
|
|
99
|
+
* useful half, so it must not be pushed out or wrapped away.
|
|
100
|
+
*/
|
|
101
|
+
export const LongCollectionName: Story = {
|
|
102
|
+
args: {
|
|
103
|
+
collectionName:
|
|
104
|
+
'Public Sector Knowledge Base — European Union Regulatory Corpus 2026',
|
|
105
|
+
locationLabel: 'Page 3',
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
86
109
|
/**
|
|
87
110
|
* Minimal: title + excerpt only (no link, no location). The leanest source a
|
|
88
111
|
* card can describe.
|
|
89
112
|
*/
|
|
90
113
|
export const MinimalSnippetOnly: Story = {
|
|
91
|
-
args: {
|
|
114
|
+
args: {
|
|
115
|
+
url: undefined,
|
|
116
|
+
locationLabel: undefined,
|
|
117
|
+
collectionName: undefined,
|
|
118
|
+
},
|
|
92
119
|
};
|
|
93
120
|
|
|
94
121
|
/**
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'vue';
|
|
3
|
-
import {
|
|
2
|
+
import { computed, useTemplateRef } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
UiFileType,
|
|
5
|
+
UiButton,
|
|
6
|
+
UiIcon,
|
|
7
|
+
UiTooltip,
|
|
8
|
+
} from '@aleph-alpha/ui-library';
|
|
9
|
+
import { useIsTruncated } from '../../../composables/useIsTruncated';
|
|
4
10
|
import {
|
|
5
11
|
defaultChatKitLabels,
|
|
6
12
|
useChatKitLabels,
|
|
@@ -13,6 +19,7 @@ defineOptions({
|
|
|
13
19
|
|
|
14
20
|
const props = withDefaults(defineProps<CkCitationCardProps>(), {
|
|
15
21
|
locationLabel: undefined,
|
|
22
|
+
collectionName: undefined,
|
|
16
23
|
url: undefined,
|
|
17
24
|
openSourceLabel: undefined,
|
|
18
25
|
});
|
|
@@ -28,7 +35,17 @@ const openSourceAriaLabel = computed(
|
|
|
28
35
|
() =>
|
|
29
36
|
props.openSourceLabel ??
|
|
30
37
|
labels.value.citationOpenSource ??
|
|
31
|
-
defaultChatKitLabels.citationOpenSource
|
|
38
|
+
defaultChatKitLabels.citationOpenSource,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Both labels are clipped to the card width, so each gets the same tooltip
|
|
42
|
+
// treatment as a file row: revealed only when the text is actually cut off.
|
|
43
|
+
const fileNameRef = useTemplateRef<HTMLElement>('fileNameRef');
|
|
44
|
+
const collectionRef = useTemplateRef<HTMLElement>('collectionRef');
|
|
45
|
+
const isFileNameTruncated = useIsTruncated(fileNameRef, () => props.fileName);
|
|
46
|
+
const isCollectionTruncated = useIsTruncated(
|
|
47
|
+
collectionRef,
|
|
48
|
+
() => props.collectionName,
|
|
32
49
|
);
|
|
33
50
|
|
|
34
51
|
function handleOpen(): void {
|
|
@@ -42,14 +59,20 @@ function handleOpen(): void {
|
|
|
42
59
|
<div
|
|
43
60
|
class="ck-citation-card flex w-[22.5rem] max-w-[90vw] flex-col gap-2 rounded-md bg-background-surface-floating px-6 pb-6 pt-4 shadow-md"
|
|
44
61
|
>
|
|
45
|
-
<div class="flex items-center gap-
|
|
62
|
+
<div class="flex min-w-0 items-center gap-3 py-0.5">
|
|
46
63
|
<UiFileType :filename="fileName" class="shrink-0" />
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
:
|
|
64
|
+
<UiTooltip
|
|
65
|
+
:content="fileName"
|
|
66
|
+
:disabled="!isFileNameTruncated"
|
|
67
|
+
align="start"
|
|
50
68
|
>
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
<p
|
|
70
|
+
ref="fileNameRef"
|
|
71
|
+
class="min-w-0 truncate text-sm font-medium leading-4 text-content-on-surface-primary"
|
|
72
|
+
>
|
|
73
|
+
{{ fileName }}
|
|
74
|
+
</p>
|
|
75
|
+
</UiTooltip>
|
|
53
76
|
<UiButton
|
|
54
77
|
v-if="url"
|
|
55
78
|
variant="ghost"
|
|
@@ -68,11 +91,30 @@ function handleOpen(): void {
|
|
|
68
91
|
{{ snippet }}
|
|
69
92
|
</p>
|
|
70
93
|
|
|
94
|
+
<!-- The location is the more useful half, so the collection name is the
|
|
95
|
+
part that gives way when the two don't fit on one line. -->
|
|
71
96
|
<p
|
|
72
|
-
v-if="locationLabel"
|
|
73
|
-
class="text-sm leading-5 text-content-on-surface-muted"
|
|
97
|
+
v-if="collectionName || locationLabel"
|
|
98
|
+
class="flex items-center gap-1.5 text-sm leading-5 text-content-on-surface-muted"
|
|
74
99
|
>
|
|
75
|
-
|
|
100
|
+
<UiTooltip
|
|
101
|
+
v-if="collectionName"
|
|
102
|
+
:content="collectionName"
|
|
103
|
+
:disabled="!isCollectionTruncated"
|
|
104
|
+
align="start"
|
|
105
|
+
>
|
|
106
|
+
<span ref="collectionRef" class="min-w-0 truncate">
|
|
107
|
+
{{ collectionName }}
|
|
108
|
+
</span>
|
|
109
|
+
</UiTooltip>
|
|
110
|
+
<span
|
|
111
|
+
v-if="collectionName && locationLabel"
|
|
112
|
+
aria-hidden="true"
|
|
113
|
+
class="shrink-0 text-border-input-strong"
|
|
114
|
+
>
|
|
115
|
+
|
|
|
116
|
+
</span>
|
|
117
|
+
<span v-if="locationLabel" class="shrink-0">{{ locationLabel }}</span>
|
|
76
118
|
</p>
|
|
77
119
|
</div>
|
|
78
120
|
</template>
|
|
@@ -25,9 +25,14 @@ export interface CkCitationCardProps {
|
|
|
25
25
|
/**
|
|
26
26
|
* Location label shown in the footer, e.g. `"Page 3"`. Pass a fully
|
|
27
27
|
* formatted, localized string — the component does no number formatting.
|
|
28
|
-
* Omit for non-paginated sources
|
|
28
|
+
* Omit for non-paginated sources.
|
|
29
29
|
*/
|
|
30
30
|
locationLabel?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Name of the collection the source belongs to, shown in the footer before
|
|
33
|
+
* the location. Omit when the source has no collection.
|
|
34
|
+
*/
|
|
35
|
+
collectionName?: string;
|
|
31
36
|
/**
|
|
32
37
|
* When set, the external-link action is shown in the header. Activating it
|
|
33
38
|
* emits `open-source` with this value; the host opens it (it may be an
|
|
@@ -53,11 +53,11 @@ describe('CkCitationLabel', () => {
|
|
|
53
53
|
).toBeInTheDocument();
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
it('renders the default (
|
|
56
|
+
it('renders the default (neutral) state by default', () => {
|
|
57
57
|
const { container } = render(CkCitationLabel, { props: { index: 1 } });
|
|
58
58
|
|
|
59
59
|
const marker = container.querySelector('.ck-citation')!;
|
|
60
|
-
expect(marker.className).toContain('bg-background-
|
|
60
|
+
expect(marker.className).toContain('bg-background-surface-citation');
|
|
61
61
|
expect(marker.className).not.toContain('bg-background-accent-soft');
|
|
62
62
|
});
|
|
63
63
|
|
|
@@ -68,6 +68,6 @@ describe('CkCitationLabel', () => {
|
|
|
68
68
|
|
|
69
69
|
const marker = container.querySelector('.ck-citation')!;
|
|
70
70
|
expect(marker.className).toContain('bg-background-accent-soft');
|
|
71
|
-
expect(marker.className).not.toContain('bg-background-
|
|
71
|
+
expect(marker.className).not.toContain('bg-background-surface-citation');
|
|
72
72
|
});
|
|
73
73
|
});
|
|
@@ -25,7 +25,7 @@ const isButton = computed(() => props.as === 'button');
|
|
|
25
25
|
const resolvedAriaLabel = computed(
|
|
26
26
|
() =>
|
|
27
27
|
props.ariaLabel ??
|
|
28
|
-
`${labels.value.citationSourceLabel ?? defaultChatKitLabels.citationSourceLabel
|
|
28
|
+
`${labels.value.citationSourceLabel ?? defaultChatKitLabels.citationSourceLabel} ${props.index}`,
|
|
29
29
|
);
|
|
30
30
|
</script>
|
|
31
31
|
|
|
@@ -46,17 +46,18 @@ const resolvedAriaLabel = computed(
|
|
|
46
46
|
:role="isButton ? undefined : 'img'"
|
|
47
47
|
:aria-label="resolvedAriaLabel"
|
|
48
48
|
:class="[
|
|
49
|
-
'ck-citation mx-px inline-flex h-5 min-w-5 items-center justify-center rounded-sm px-1 align-middle text-sm leading-4 tabular-nums transition-colors
|
|
49
|
+
'ck-citation ui-focus-ring mx-px inline-flex h-5 min-w-5 items-center justify-center rounded-sm border border-transparent px-1 align-middle text-sm leading-4 tabular-nums transition-colors',
|
|
50
50
|
// The static chip is part of the prose: it must stay selectable so the
|
|
51
51
|
// number survives a copy of the surrounding text. A control shouldn't
|
|
52
52
|
// start a text selection on click, so button mode keeps `select-none`.
|
|
53
|
-
|
|
53
|
+
// Only the control gets the hover layer; a static chip has no hover state.
|
|
54
|
+
isButton ? 'select-none hover-layer hover-layer-default' : '',
|
|
54
55
|
selected
|
|
55
|
-
? 'bg-background-accent-soft text-
|
|
56
|
-
: 'bg-background-
|
|
56
|
+
? 'bg-background-accent-soft text-content-on-accent-soft'
|
|
57
|
+
: 'bg-background-surface-citation text-content-on-surface-primary',
|
|
57
58
|
]"
|
|
58
59
|
>
|
|
59
|
-
{{ index }}
|
|
60
|
+
<span>{{ index }}</span>
|
|
60
61
|
</component>
|
|
61
62
|
</template>
|
|
62
63
|
|
|
@@ -26,7 +26,6 @@ const messages = [
|
|
|
26
26
|
function renderLayout(
|
|
27
27
|
msgs: Array<{ role: string; content: string }> = messages,
|
|
28
28
|
) {
|
|
29
|
-
// eslint-disable-next-line vue/one-component-per-file
|
|
30
29
|
const Wrapper = defineComponent({
|
|
31
30
|
setup() {
|
|
32
31
|
return () =>
|
|
@@ -55,7 +54,7 @@ function renderWithInstance(
|
|
|
55
54
|
{ withFooter = false }: { withFooter?: boolean } = {},
|
|
56
55
|
) {
|
|
57
56
|
let instance: LayoutInstance | undefined;
|
|
58
|
-
|
|
57
|
+
|
|
59
58
|
const Wrapper = defineComponent({
|
|
60
59
|
setup() {
|
|
61
60
|
const layoutRef = ref<LayoutInstance>();
|
|
@@ -167,7 +166,6 @@ describe('CkConversationLayout', () => {
|
|
|
167
166
|
}
|
|
168
167
|
|
|
169
168
|
it('provides the full message object including custom fields to scoped slots', () => {
|
|
170
|
-
// eslint-disable-next-line vue/one-component-per-file
|
|
171
169
|
const Wrapper = defineComponent({ setup: () => renderCustomSlotWrapper });
|
|
172
170
|
|
|
173
171
|
render(Wrapper);
|
|
@@ -206,7 +204,6 @@ describe('CkConversationLayout', () => {
|
|
|
206
204
|
});
|
|
207
205
|
|
|
208
206
|
it('gives the thread-footer the larger top margin when messages exist', () => {
|
|
209
|
-
// eslint-disable-next-line vue/one-component-per-file
|
|
210
207
|
const Wrapper = defineComponent({
|
|
211
208
|
setup() {
|
|
212
209
|
return () =>
|
|
@@ -233,7 +230,6 @@ describe('CkConversationLayout', () => {
|
|
|
233
230
|
});
|
|
234
231
|
|
|
235
232
|
it('gives the thread-footer the smaller top margin when there are no messages', () => {
|
|
236
|
-
// eslint-disable-next-line vue/one-component-per-file
|
|
237
233
|
const Wrapper = defineComponent({
|
|
238
234
|
setup() {
|
|
239
235
|
return () =>
|
|
@@ -5,7 +5,7 @@ import { flushPromises } from '@vue/test-utils';
|
|
|
5
5
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
6
|
|
|
7
7
|
describe('CkCopyMessageButton', () => {
|
|
8
|
-
const writeText = vi.fn((
|
|
8
|
+
const writeText = vi.fn(() => Promise.resolve());
|
|
9
9
|
|
|
10
10
|
beforeEach(() => {
|
|
11
11
|
writeText.mockReset();
|
|
@@ -32,19 +32,19 @@ const thumbsUpLabel = computed(
|
|
|
32
32
|
() =>
|
|
33
33
|
props.ariaLabelThumbsUp ??
|
|
34
34
|
labels.value.feedbackThumbsUp ??
|
|
35
|
-
defaultChatKitLabels.feedbackThumbsUp
|
|
35
|
+
defaultChatKitLabels.feedbackThumbsUp,
|
|
36
36
|
);
|
|
37
37
|
const thumbsDownLabel = computed(
|
|
38
38
|
() =>
|
|
39
39
|
props.ariaLabelThumbsDown ??
|
|
40
40
|
labels.value.feedbackThumbsDown ??
|
|
41
|
-
defaultChatKitLabels.feedbackThumbsDown
|
|
41
|
+
defaultChatKitLabels.feedbackThumbsDown,
|
|
42
42
|
);
|
|
43
43
|
const groupLabel = computed(
|
|
44
44
|
() =>
|
|
45
45
|
props.ariaLabelGroup ??
|
|
46
46
|
labels.value.feedbackGroup ??
|
|
47
|
-
defaultChatKitLabels.feedbackGroup
|
|
47
|
+
defaultChatKitLabels.feedbackGroup,
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
const isUpSelected = computed(() => props.value === 'up');
|
|
@@ -257,7 +257,7 @@ describe('CkFeedbackDialog', () => {
|
|
|
257
257
|
const marker = document.body.querySelector('.ck-citation')!;
|
|
258
258
|
expect(marker.tagName).toBe('SPAN');
|
|
259
259
|
expect(marker).toHaveTextContent('1');
|
|
260
|
-
expect(marker.className).toContain('bg-background-
|
|
260
|
+
expect(marker.className).toContain('bg-background-surface-citation');
|
|
261
261
|
// Announced as its own labelled object, and never as a control.
|
|
262
262
|
expect(screen.getByRole('img', { name: 'Source 1' })).toBeInTheDocument();
|
|
263
263
|
expect(
|
|
@@ -61,56 +61,56 @@ const title = computed(() => {
|
|
|
61
61
|
return (
|
|
62
62
|
titlePositive ??
|
|
63
63
|
labels.value.feedbackDialogTitlePositive ??
|
|
64
|
-
defaultChatKitLabels.feedbackDialogTitlePositive
|
|
64
|
+
defaultChatKitLabels.feedbackDialogTitlePositive
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
return (
|
|
68
68
|
titleNegative ??
|
|
69
69
|
labels.value.feedbackDialogTitleNegative ??
|
|
70
|
-
defaultChatKitLabels.feedbackDialogTitleNegative
|
|
70
|
+
defaultChatKitLabels.feedbackDialogTitleNegative
|
|
71
71
|
);
|
|
72
72
|
});
|
|
73
73
|
const responseHeading = computed(
|
|
74
74
|
() =>
|
|
75
75
|
responseHeadingProp ??
|
|
76
76
|
labels.value.feedbackDialogResponseHeading ??
|
|
77
|
-
defaultChatKitLabels.feedbackDialogResponseHeading
|
|
77
|
+
defaultChatKitLabels.feedbackDialogResponseHeading,
|
|
78
78
|
);
|
|
79
79
|
const description = computed(
|
|
80
80
|
() =>
|
|
81
81
|
descriptionProp ??
|
|
82
82
|
labels.value.feedbackDialogDescription ??
|
|
83
|
-
defaultChatKitLabels.feedbackDialogDescription
|
|
83
|
+
defaultChatKitLabels.feedbackDialogDescription,
|
|
84
84
|
);
|
|
85
85
|
const otherLabel = computed(
|
|
86
86
|
() =>
|
|
87
87
|
otherLabelProp ??
|
|
88
88
|
labels.value.feedbackDialogOtherLabel ??
|
|
89
|
-
defaultChatKitLabels.feedbackDialogOtherLabel
|
|
89
|
+
defaultChatKitLabels.feedbackDialogOtherLabel,
|
|
90
90
|
);
|
|
91
91
|
const otherTooltip = computed(
|
|
92
92
|
() =>
|
|
93
93
|
otherTooltipProp ??
|
|
94
94
|
labels.value.feedbackDialogOtherTooltip ??
|
|
95
|
-
defaultChatKitLabels.feedbackDialogOtherTooltip
|
|
95
|
+
defaultChatKitLabels.feedbackDialogOtherTooltip,
|
|
96
96
|
);
|
|
97
97
|
const freeTextPlaceholder = computed(
|
|
98
98
|
() =>
|
|
99
99
|
freeTextPlaceholderProp ??
|
|
100
100
|
labels.value.feedbackDialogFreeTextPlaceholder ??
|
|
101
|
-
defaultChatKitLabels.feedbackDialogFreeTextPlaceholder
|
|
101
|
+
defaultChatKitLabels.feedbackDialogFreeTextPlaceholder,
|
|
102
102
|
);
|
|
103
103
|
const cancelLabel = computed(
|
|
104
104
|
() =>
|
|
105
105
|
cancelLabelProp ??
|
|
106
106
|
labels.value.feedbackDialogCancelLabel ??
|
|
107
|
-
defaultChatKitLabels.feedbackDialogCancelLabel
|
|
107
|
+
defaultChatKitLabels.feedbackDialogCancelLabel,
|
|
108
108
|
);
|
|
109
109
|
const submitLabel = computed(
|
|
110
110
|
() =>
|
|
111
111
|
submitLabelProp ??
|
|
112
112
|
labels.value.feedbackDialogSubmitLabel ??
|
|
113
|
-
defaultChatKitLabels.feedbackDialogSubmitLabel
|
|
113
|
+
defaultChatKitLabels.feedbackDialogSubmitLabel,
|
|
114
114
|
);
|
|
115
115
|
|
|
116
116
|
// Multi-select: the user may pick zero or more reason codes. Backed by an
|
|
@@ -138,13 +138,11 @@ const actionPopoverPanelClass = computed(() => [
|
|
|
138
138
|
]);
|
|
139
139
|
|
|
140
140
|
const passthroughAttrs = computed(() => {
|
|
141
|
-
const {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
...rest
|
|
147
|
-
} = attrs as Record<string, unknown>;
|
|
141
|
+
const rest = { ...(attrs as Record<string, unknown>) };
|
|
142
|
+
delete rest.class;
|
|
143
|
+
delete rest.as;
|
|
144
|
+
delete rest.asChild;
|
|
145
|
+
delete rest['as-child'];
|
|
148
146
|
return rest;
|
|
149
147
|
});
|
|
150
148
|
|