@epam/ai-dial-quotations 1.1.0-dev.88
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/components/CitationCard/CitationCard.d.ts +59 -0
- package/components/CitationCard/CitationCard.d.ts.map +1 -0
- package/components/CitationDropdown/CitationDropdown.d.ts +32 -0
- package/components/CitationDropdown/CitationDropdown.d.ts.map +1 -0
- package/components/CitationMarker/CitationMarker.d.ts +28 -0
- package/components/CitationMarker/CitationMarker.d.ts.map +1 -0
- package/context/CitationCardContext.d.ts +14 -0
- package/context/CitationCardContext.d.ts.map +1 -0
- package/index.d.ts +18 -0
- package/index.d.ts.map +1 -0
- package/index.js +320 -0
- package/package.json +30 -0
- package/test-setup.d.ts +2 -0
- package/test-setup.d.ts.map +1 -0
- package/utils/annotation.d.ts +34 -0
- package/utils/annotation.d.ts.map +1 -0
- package/utils/citation-injection.d.ts +15 -0
- package/utils/citation-injection.d.ts.map +1 -0
- package/utils/group-annotations-by-source.d.ts +18 -0
- package/utils/group-annotations-by-source.d.ts.map +1 -0
- package/utils/reference-attachment.d.ts +24 -0
- package/utils/reference-attachment.d.ts.map +1 -0
- package/utils/useAnnotations.d.ts +7 -0
- package/utils/useAnnotations.d.ts.map +1 -0
- package/utils/useCitationCard.d.ts +12 -0
- package/utils/useCitationCard.d.ts.map +1 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Annotation } from '@epam/ai-dial-chat-shared';
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
|
+
import { AnnotationGroup } from '../../utils/group-annotations-by-source';
|
|
4
|
+
/** User-visible strings for `CitationCard`. */
|
|
5
|
+
export interface CitationCardLabels {
|
|
6
|
+
/** Dialog aria-label (already includes the source name). */
|
|
7
|
+
ariaLabel: string;
|
|
8
|
+
/** Accessible label for the "previous citation" button. */
|
|
9
|
+
previousCitation: string;
|
|
10
|
+
/** Accessible label for the "next citation" button. */
|
|
11
|
+
nextCitation: string;
|
|
12
|
+
/** Returns the switcher text given the 1-based current index and total count, e.g. `(1, 3) => "1 / 3"`. */
|
|
13
|
+
formatSwitcherText: (current: number, total: number) => string;
|
|
14
|
+
/** Label for the "Preview" button. */
|
|
15
|
+
preview: string;
|
|
16
|
+
/** Label for the "Open in browser" button. */
|
|
17
|
+
openInBrowser: string;
|
|
18
|
+
/** Label for the "Download" button. */
|
|
19
|
+
download: string;
|
|
20
|
+
}
|
|
21
|
+
/** Typography (font utility class) overrides for `CitationCard`. */
|
|
22
|
+
export interface CitationCardTypography {
|
|
23
|
+
/** CSS class applied to the source name ellipsis. Defaults to `'dial-tiny-text'`. */
|
|
24
|
+
sourceNameClassName?: string;
|
|
25
|
+
/** CSS class applied to the annotation title. Defaults to `'dial-body-semi-text'`. */
|
|
26
|
+
titleClassName?: string;
|
|
27
|
+
/** CSS class applied to the quoted excerpt. Defaults to `'dial-small-text'`. */
|
|
28
|
+
quoteClassName?: string;
|
|
29
|
+
/** CSS class applied to the pagination switcher text. Defaults to `'dial-tiny-text'`. */
|
|
30
|
+
switcherClassName?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Props for the `CitationCard` component. */
|
|
33
|
+
export interface CitationCardProps {
|
|
34
|
+
/** The annotation group whose citations are displayed in this popup. */
|
|
35
|
+
group: AnnotationGroup;
|
|
36
|
+
/** Zero-based index into `group.annotations` for the currently shown citation. */
|
|
37
|
+
activeIndex: number;
|
|
38
|
+
/** Called when the user navigates to a different annotation within the group. */
|
|
39
|
+
onIndexChange: (index: number) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Called when the user clicks the "Preview" button. Omit when the group has
|
|
42
|
+
* nothing previewable (e.g. reference-only chunks) — the "Preview" button is
|
|
43
|
+
* hidden and the remaining button is always labelled "Open in browser".
|
|
44
|
+
*/
|
|
45
|
+
onPreview?: (annotation: Annotation) => void;
|
|
46
|
+
/** Called when the user clicks the "Open in browser"/"Download" button. */
|
|
47
|
+
onOpenInBrowser: (annotation: Annotation) => void;
|
|
48
|
+
/** Optional icon rendered before the source name in the card header. */
|
|
49
|
+
headerIcon?: ReactNode;
|
|
50
|
+
/** User-visible strings. */
|
|
51
|
+
labels: CitationCardLabels;
|
|
52
|
+
/** Optional typography class overrides. */
|
|
53
|
+
typography?: CitationCardTypography;
|
|
54
|
+
}
|
|
55
|
+
/** Popup card displaying a citation's title, quoted excerpt, and navigation controls. */
|
|
56
|
+
export declare const CitationCard: FC<CitationCardProps>;
|
|
57
|
+
declare const _default: import('react').NamedExoticComponent<CitationCardProps>;
|
|
58
|
+
export default _default;
|
|
59
|
+
//# sourceMappingURL=CitationCard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CitationCard.d.ts","sourceRoot":"","sources":["../../../src/components/CitationCard/CitationCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAa5D,OAAO,EAAE,EAAE,EAAQ,SAAS,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE/E,+CAA+C;AAC/C,MAAM,WAAW,kBAAkB;IACjC,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,gBAAgB,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IACrB,2GAA2G;IAC3G,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/D,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,oEAAoE;AACpE,MAAM,WAAW,sBAAsB;IACrC,qFAAqF;IACrF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sFAAsF;IACtF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gFAAgF;IAChF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yFAAyF;IACzF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,KAAK,EAAE,eAAe,CAAC;IACvB,kFAAkF;IAClF,WAAW,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IAC7C,2EAA2E;IAC3E,eAAe,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IAClD,wEAAwE;IACxE,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,4BAA4B;IAC5B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,2CAA2C;IAC3C,UAAU,CAAC,EAAE,sBAAsB,CAAC;CACrC;AAED,yFAAyF;AACzF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAmH9C,CAAC;;AAEF,wBAAkC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Annotation } from '@epam/ai-dial-chat-shared';
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
|
+
import { AnnotationGroup } from '../../utils/group-annotations-by-source';
|
|
4
|
+
import { CitationCardLabels, CitationCardTypography } from '../CitationCard/CitationCard';
|
|
5
|
+
import { CitationMarkerLabels } from '../CitationMarker/CitationMarker';
|
|
6
|
+
/** Props for the `CitationDropdown` component. */
|
|
7
|
+
export interface CitationDropdownProps {
|
|
8
|
+
/** The annotation group represented by this marker+popup pair. */
|
|
9
|
+
group: AnnotationGroup;
|
|
10
|
+
/**
|
|
11
|
+
* Called when the user clicks "Preview" for an annotation. Omit when the
|
|
12
|
+
* group has nothing previewable — the "Preview" button is hidden.
|
|
13
|
+
*/
|
|
14
|
+
onPreview?: (annotation: Annotation) => void;
|
|
15
|
+
/** Called when the user clicks "Open in browser" for an annotation. */
|
|
16
|
+
onOpenInBrowser: (annotation: Annotation) => void;
|
|
17
|
+
/** Optional icon rendered before the marker's label. */
|
|
18
|
+
icon?: ReactNode;
|
|
19
|
+
/** Optional icon rendered in the card header. When absent, no header icon is shown. */
|
|
20
|
+
headerIcon?: ReactNode;
|
|
21
|
+
/** User-visible strings for the card popup. */
|
|
22
|
+
cardLabels: CitationCardLabels;
|
|
23
|
+
/** User-visible strings for the inline marker button. */
|
|
24
|
+
markerLabels: CitationMarkerLabels;
|
|
25
|
+
/** Optional typography overrides forwarded to the card. */
|
|
26
|
+
cardTypography?: CitationCardTypography;
|
|
27
|
+
}
|
|
28
|
+
/** Combines `CitationMarker` and `CitationCard` into a tooltip-based dropdown. Requires a `CitationCardProvider` ancestor. */
|
|
29
|
+
export declare const CitationDropdown: FC<CitationDropdownProps>;
|
|
30
|
+
declare const _default: import('react').NamedExoticComponent<CitationDropdownProps>;
|
|
31
|
+
export default _default;
|
|
32
|
+
//# sourceMappingURL=CitationDropdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CitationDropdown.d.ts","sourceRoot":"","sources":["../../../src/components/CitationDropdown/CitationDropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,EAAE,EAAQ,SAAS,EAAwB,MAAM,OAAO,CAAC;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,kCAAkC,CAAC;AAE1C,kDAAkD;AAClD,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,KAAK,EAAE,eAAe,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IAC7C,uEAAuE;IACvE,eAAe,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IAClD,wDAAwD;IACxD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,uFAAuF;IACvF,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,+CAA+C;IAC/C,UAAU,EAAE,kBAAkB,CAAC;IAC/B,yDAAyD;IACzD,YAAY,EAAE,oBAAoB,CAAC;IACnC,2DAA2D;IAC3D,cAAc,CAAC,EAAE,sBAAsB,CAAC;CACzC;AAED,8HAA8H;AAC9H,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,CA6DtD,CAAC;;AAEF,wBAAsC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
/** User-visible strings for `CitationMarker`. */
|
|
3
|
+
export interface CitationMarkerLabels {
|
|
4
|
+
/** Accessible label for the marker button. */
|
|
5
|
+
ariaLabel: string;
|
|
6
|
+
/** Button text when `annotationCount === 1`. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Button text when `annotationCount > 1`. */
|
|
9
|
+
labelWithOverflow: string;
|
|
10
|
+
}
|
|
11
|
+
/** Props for the `CitationMarker` component. */
|
|
12
|
+
export interface CitationMarkerProps {
|
|
13
|
+
/** Human-readable source name derived from the attachment URL. */
|
|
14
|
+
sourceName: string;
|
|
15
|
+
/** Total number of annotations in this citation group. */
|
|
16
|
+
annotationCount: number;
|
|
17
|
+
/** Called when the user clicks the marker to open the citation popup. */
|
|
18
|
+
onOpen: () => void;
|
|
19
|
+
/** Optional icon rendered before the label; omitted by default. */
|
|
20
|
+
icon?: ReactNode;
|
|
21
|
+
/** User-visible strings. */
|
|
22
|
+
labels: CitationMarkerLabels;
|
|
23
|
+
}
|
|
24
|
+
/** Inline button that opens the citation popup for a source group. */
|
|
25
|
+
export declare const CitationMarker: FC<CitationMarkerProps>;
|
|
26
|
+
declare const _default: import('react').NamedExoticComponent<CitationMarkerProps>;
|
|
27
|
+
export default _default;
|
|
28
|
+
//# sourceMappingURL=CitationMarker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CitationMarker.d.ts","sourceRoot":"","sources":["../../../src/components/CitationMarker/CitationMarker.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAQ,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5C,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACnC,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,gDAAgD;AAChD,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,eAAe,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,mEAAmE;IACnE,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,4BAA4B;IAC5B,MAAM,EAAE,oBAAoB,CAAC;CAC9B;AAED,sEAAsE;AACtE,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,CAuBlD,CAAC;;AAEF,wBAAoC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useCitationCard } from '../utils/useCitationCard';
|
|
2
|
+
/** The shape returned by `useCitationCard`. */
|
|
3
|
+
export type CitationCardHook = ReturnType<typeof useCitationCard>;
|
|
4
|
+
/** Provider that supplies `CitationCardHook` state to a citation subtree. */
|
|
5
|
+
export declare const CitationCardProvider: import('react').Provider<{
|
|
6
|
+
openPopup: (sourceUrl: string) => void;
|
|
7
|
+
closePopup: () => void;
|
|
8
|
+
setActiveIndex: (sourceUrl: string, index: number) => void;
|
|
9
|
+
isOpen: (sourceUrl: string) => boolean;
|
|
10
|
+
getActiveIndex: (sourceUrl: string) => number;
|
|
11
|
+
} | null>;
|
|
12
|
+
/** Returns the nearest `CitationCardHook` from context. Throws when used outside a `CitationCardProvider`. */
|
|
13
|
+
export declare const useCitationCardContext: () => CitationCardHook;
|
|
14
|
+
//# sourceMappingURL=CitationCardContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CitationCardContext.d.ts","sourceRoot":"","sources":["../../src/context/CitationCardContext.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEhE,+CAA+C;AAC/C,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAIlE,6EAA6E;AAC7E,eAAO,MAAM,oBAAoB;;;;;;SAA+B,CAAC;AAEjE,8GAA8G;AAC9G,eAAO,MAAM,sBAAsB,QAAO,gBAOzC,CAAC"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { CitationCard } from './components/CitationCard/CitationCard';
|
|
2
|
+
export type { CitationCardLabels, CitationCardProps, CitationCardTypography, } from './components/CitationCard/CitationCard';
|
|
3
|
+
export { CitationMarker } from './components/CitationMarker/CitationMarker';
|
|
4
|
+
export type { CitationMarkerLabels, CitationMarkerProps, } from './components/CitationMarker/CitationMarker';
|
|
5
|
+
export { CitationDropdown } from './components/CitationDropdown/CitationDropdown';
|
|
6
|
+
export type { CitationDropdownProps } from './components/CitationDropdown/CitationDropdown';
|
|
7
|
+
export { CitationCardProvider, useCitationCardContext, } from './context/CitationCardContext';
|
|
8
|
+
export type { CitationCardHook } from './context/CitationCardContext';
|
|
9
|
+
export { useAnnotations } from './utils/useAnnotations';
|
|
10
|
+
export { useCitationCard } from './utils/useCitationCard';
|
|
11
|
+
export { groupAnnotationsBySource } from './utils/group-annotations-by-source';
|
|
12
|
+
export type { AnnotationGroup } from './utils/group-annotations-by-source';
|
|
13
|
+
export { annotationsToPdfHighlights, annotationHighlightId, normalizeRawAnnotations, resolveMessageAnnotations, } from './utils/annotation';
|
|
14
|
+
export type { AttachmentResource } from './utils/annotation';
|
|
15
|
+
export { injectCitationSentinels, replaceSentinelsInChildren, } from './utils/citation-injection';
|
|
16
|
+
export { isReferenceOnlyAttachment, parsePdfPageReference, getReferenceAttachmentGroups, } from './utils/reference-attachment';
|
|
17
|
+
export type { PdfPageReference } from './utils/reference-attachment';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAC5E,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF,YAAY,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AAG5F,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,+BAA+B,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,YAAY,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { MIMEType as e, MarkdownRenderer as t, mergeClasses as n } from "@epam/ai-dial-chat-shared";
|
|
2
|
+
import { DialEllipsisTooltip as r, DialTooltip as i, ElementSize as a, GhostIconButton as o, NeutralButton as s, PrimaryButton as c } from "@epam/ai-dial-ui-kit";
|
|
3
|
+
import { IconChevronLeft as l, IconChevronRight as u } from "@tabler/icons-react";
|
|
4
|
+
import { createContext as d, memo as f, useCallback as p, useContext as m, useMemo as h, useState as g } from "react";
|
|
5
|
+
import { jsx as _, jsxs as v } from "react/jsx-runtime";
|
|
6
|
+
//#region src/components/CitationCard/CitationCard.tsx
|
|
7
|
+
var y = ({ group: i, activeIndex: s, onIndexChange: d, onPreview: f, onOpenInBrowser: p, headerIcon: m, labels: h, typography: g }) => {
|
|
8
|
+
let y = i.annotations.length, b = i.annotations[s] ?? i.primaryAnnotation, x = y > 1, S = i.annotations.some((e) => e.body?.title), C = i.primaryAnnotation.body?.source?.attachment?.type, w = f == null || C === e.HTML || C === e.XHTML, T = g?.sourceNameClassName ?? "dial-tiny-text", E = g?.titleClassName ?? "dial-body-semi-text", D = g?.quoteClassName ?? "dial-small-text", O = g?.switcherClassName ?? "dial-tiny-text";
|
|
9
|
+
return /* @__PURE__ */ v("div", {
|
|
10
|
+
role: "dialog",
|
|
11
|
+
"aria-modal": "true",
|
|
12
|
+
"aria-label": h.ariaLabel,
|
|
13
|
+
className: "flex w-[400px] flex-col gap-3 rounded-lg border border-primary bg-layer-0 p-4 shadow-lg",
|
|
14
|
+
children: [
|
|
15
|
+
/* @__PURE__ */ v("div", {
|
|
16
|
+
className: "flex items-center justify-between gap-2",
|
|
17
|
+
children: [/* @__PURE__ */ v("div", {
|
|
18
|
+
className: "flex min-w-0 items-center gap-1",
|
|
19
|
+
children: [m, /* @__PURE__ */ _(r, {
|
|
20
|
+
text: i.sourceName,
|
|
21
|
+
className: n(T, "min-w-0 text-primary")
|
|
22
|
+
})]
|
|
23
|
+
}), x && /* @__PURE__ */ v("div", {
|
|
24
|
+
className: "flex shrink-0 items-center gap-1",
|
|
25
|
+
children: [
|
|
26
|
+
/* @__PURE__ */ _(o, {
|
|
27
|
+
icon: /* @__PURE__ */ _(l, {
|
|
28
|
+
size: 14,
|
|
29
|
+
className: "rtl:scale-x-[-1]"
|
|
30
|
+
}),
|
|
31
|
+
size: a.Small,
|
|
32
|
+
"aria-label": h.previousCitation,
|
|
33
|
+
onClick: () => d((s - 1 + y) % y)
|
|
34
|
+
}),
|
|
35
|
+
/* @__PURE__ */ _("span", {
|
|
36
|
+
className: n(O, "text-secondary"),
|
|
37
|
+
children: h.formatSwitcherText(s + 1, y)
|
|
38
|
+
}),
|
|
39
|
+
/* @__PURE__ */ _(o, {
|
|
40
|
+
icon: /* @__PURE__ */ _(u, {
|
|
41
|
+
size: 14,
|
|
42
|
+
className: "rtl:scale-x-[-1]"
|
|
43
|
+
}),
|
|
44
|
+
size: a.Small,
|
|
45
|
+
"aria-label": h.nextCitation,
|
|
46
|
+
onClick: () => d((s + 1) % y)
|
|
47
|
+
})
|
|
48
|
+
]
|
|
49
|
+
})]
|
|
50
|
+
}),
|
|
51
|
+
(b.body?.title || b.body?.quote || x) && /* @__PURE__ */ v("div", {
|
|
52
|
+
className: "flex flex-col gap-3",
|
|
53
|
+
children: [(b.body?.title || x && S) && /* @__PURE__ */ _("p", {
|
|
54
|
+
className: n(E, "text-primary", x && S && "min-h-[1lh]"),
|
|
55
|
+
children: b.body?.title
|
|
56
|
+
}), (b.body?.quote || x) && /* @__PURE__ */ _("div", {
|
|
57
|
+
className: n(x && "min-h-[3lh]"),
|
|
58
|
+
children: b.body?.quote && /* @__PURE__ */ _(t, {
|
|
59
|
+
content: b.body.quote,
|
|
60
|
+
classNames: { p: n(D, "line-clamp-6 text-secondary") }
|
|
61
|
+
})
|
|
62
|
+
})]
|
|
63
|
+
}),
|
|
64
|
+
/* @__PURE__ */ v("div", {
|
|
65
|
+
className: "flex justify-start gap-2",
|
|
66
|
+
children: [f && /* @__PURE__ */ _(c, {
|
|
67
|
+
label: h.preview,
|
|
68
|
+
size: a.Small,
|
|
69
|
+
onClick: () => f(b)
|
|
70
|
+
}), /* @__PURE__ */ _(c, {
|
|
71
|
+
label: w ? h.openInBrowser : h.download,
|
|
72
|
+
size: a.Small,
|
|
73
|
+
onClick: () => p(b)
|
|
74
|
+
})]
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
f(y);
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/components/CitationMarker/CitationMarker.tsx
|
|
82
|
+
var b = ({ annotationCount: e, onOpen: t, icon: n, labels: r }) => {
|
|
83
|
+
let i = /* @__PURE__ */ v("span", {
|
|
84
|
+
className: "flex items-center gap-1",
|
|
85
|
+
children: [n, /* @__PURE__ */ _("span", {
|
|
86
|
+
className: "dial-caption-text",
|
|
87
|
+
children: e > 1 ? r.labelWithOverflow : r.label
|
|
88
|
+
})]
|
|
89
|
+
});
|
|
90
|
+
return /* @__PURE__ */ _(s, {
|
|
91
|
+
size: a.Small,
|
|
92
|
+
label: i,
|
|
93
|
+
"aria-label": r.ariaLabel,
|
|
94
|
+
onClick: t
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
f(b);
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/context/CitationCardContext.tsx
|
|
100
|
+
var x = d(null), S = x.Provider, C = () => {
|
|
101
|
+
let e = m(x);
|
|
102
|
+
if (e == null) throw Error("useCitationCardContext must be used within a CitationCardProvider");
|
|
103
|
+
return e;
|
|
104
|
+
}, w = ({ group: e, onPreview: t, onOpenInBrowser: n, icon: r, headerIcon: a, cardLabels: o, markerLabels: s, cardTypography: c }) => {
|
|
105
|
+
let l = C(), u = l.isOpen(e.sourceUrl), d = l.getActiveIndex(e.sourceUrl);
|
|
106
|
+
return /* @__PURE__ */ _(i, {
|
|
107
|
+
open: u,
|
|
108
|
+
onOpenChange: p((e) => {
|
|
109
|
+
e || l.closePopup();
|
|
110
|
+
}, [l]),
|
|
111
|
+
placement: "bottom-end",
|
|
112
|
+
triggerClassName: "ms-1 inline-flex align-middle",
|
|
113
|
+
contentClassName: "!p-0 !bg-transparent !border-0 !shadow-none !max-w-none !rounded-none",
|
|
114
|
+
tooltip: /* @__PURE__ */ _(y, {
|
|
115
|
+
group: e,
|
|
116
|
+
activeIndex: d,
|
|
117
|
+
onIndexChange: (t) => l.setActiveIndex(e.sourceUrl, t),
|
|
118
|
+
onPreview: h(() => t ? (e) => {
|
|
119
|
+
t(e), l.closePopup();
|
|
120
|
+
} : void 0, [t, l]),
|
|
121
|
+
onOpenInBrowser: n,
|
|
122
|
+
headerIcon: a,
|
|
123
|
+
labels: o,
|
|
124
|
+
typography: c
|
|
125
|
+
}),
|
|
126
|
+
children: /* @__PURE__ */ _(b, {
|
|
127
|
+
sourceName: e.sourceName,
|
|
128
|
+
annotationCount: e.annotations.length,
|
|
129
|
+
onOpen: () => l.openPopup(e.sourceUrl),
|
|
130
|
+
icon: r,
|
|
131
|
+
labels: s
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
f(w);
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/utils/annotation.ts
|
|
138
|
+
var T = {
|
|
139
|
+
backgroundColor: "transparent",
|
|
140
|
+
borderColor: "#124ACE",
|
|
141
|
+
borderWidth: "2px",
|
|
142
|
+
opacity: .5,
|
|
143
|
+
hoverOpacity: .5
|
|
144
|
+
}, E = (e) => e.flatMap((e, t) => {
|
|
145
|
+
let n = e.body?.selector;
|
|
146
|
+
if (n == null) return [];
|
|
147
|
+
let r = (Array.isArray(n) ? n : [n]).flatMap((e) => {
|
|
148
|
+
if (e.type !== "pdf_bbox") return [];
|
|
149
|
+
let { page: t, x1: n, y1: r, x2: i, y2: a } = e;
|
|
150
|
+
return [{
|
|
151
|
+
page: t,
|
|
152
|
+
x1: n,
|
|
153
|
+
y1: r,
|
|
154
|
+
x2: i,
|
|
155
|
+
y2: a
|
|
156
|
+
}];
|
|
157
|
+
});
|
|
158
|
+
return r.length === 0 ? [] : [{
|
|
159
|
+
id: String(e.index ?? t),
|
|
160
|
+
bboxes: r,
|
|
161
|
+
style: T
|
|
162
|
+
}];
|
|
163
|
+
}), D = (e, t) => String(e.index ?? t), O = (e) => typeof e == "number" ? e : null, k = (e) => {
|
|
164
|
+
if (typeof e != "object" || !e) return null;
|
|
165
|
+
let t = e;
|
|
166
|
+
if (t.type !== "pdf_region") return null;
|
|
167
|
+
let n = t.bbox;
|
|
168
|
+
if (typeof n != "object" || !n) return null;
|
|
169
|
+
let r = n, i = O(r.left), a = O(r.top), o = O(r.width), s = O(r.height);
|
|
170
|
+
return i === null || a === null || o === null || s === null ? null : {
|
|
171
|
+
type: "pdf_bbox",
|
|
172
|
+
page: O(t.page) ?? 1,
|
|
173
|
+
x1: i,
|
|
174
|
+
y1: a,
|
|
175
|
+
x2: i + o,
|
|
176
|
+
y2: a + s
|
|
177
|
+
};
|
|
178
|
+
}, A = (t, n) => t.flatMap((t) => {
|
|
179
|
+
if (typeof t != "object" || !t) return [];
|
|
180
|
+
let r = t, i = r.target;
|
|
181
|
+
if (typeof i != "object" || !i) return [];
|
|
182
|
+
let a = i, o = a.source;
|
|
183
|
+
if (typeof o != "object" || !o) return [];
|
|
184
|
+
let s = O(o.attachment_index);
|
|
185
|
+
if (s === null) return [];
|
|
186
|
+
let c = n.find((e) => e.index === s);
|
|
187
|
+
if (c?.url == null) return [];
|
|
188
|
+
let l = k(a.selector);
|
|
189
|
+
if (l === null) return [];
|
|
190
|
+
let u = r.body, d = typeof u == "object" && u ? u : {}, f = typeof d.title == "string" ? d.title : void 0, p = typeof d.quote == "string" ? d.quote : void 0;
|
|
191
|
+
return [{
|
|
192
|
+
index: O(r.index) ?? void 0,
|
|
193
|
+
body: {
|
|
194
|
+
title: f,
|
|
195
|
+
quote: p,
|
|
196
|
+
source: {
|
|
197
|
+
type: "attachment",
|
|
198
|
+
attachment: {
|
|
199
|
+
type: c.type ?? e.PDF,
|
|
200
|
+
url: c.url,
|
|
201
|
+
title: c.title
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
selector: l
|
|
205
|
+
}
|
|
206
|
+
}];
|
|
207
|
+
}), j = (e) => {
|
|
208
|
+
let t = e.custom_content?.annotations;
|
|
209
|
+
if (t?.length) return t.filter((e) => e != null && e.body?.source?.attachment?.url != null);
|
|
210
|
+
let n = e.custom_fields;
|
|
211
|
+
if (typeof n != "object" || !n) return [];
|
|
212
|
+
let r = n.annotations;
|
|
213
|
+
return !Array.isArray(r) || r.length === 0 ? [] : A(r, e.custom_content?.attachments ?? []);
|
|
214
|
+
}, M = (e, t) => h(() => t ? [] : j(e), [t, e]), N = {
|
|
215
|
+
openGroupSourceUrl: null,
|
|
216
|
+
activeIndexByGroup: {}
|
|
217
|
+
}, P = () => {
|
|
218
|
+
let [e, t] = g(N), n = p((e) => {
|
|
219
|
+
t((t) => ({
|
|
220
|
+
...t,
|
|
221
|
+
openGroupSourceUrl: e
|
|
222
|
+
}));
|
|
223
|
+
}, []), r = p(() => {
|
|
224
|
+
t((e) => ({
|
|
225
|
+
...e,
|
|
226
|
+
openGroupSourceUrl: null
|
|
227
|
+
}));
|
|
228
|
+
}, []), i = p((e, n) => {
|
|
229
|
+
t((t) => ({
|
|
230
|
+
...t,
|
|
231
|
+
activeIndexByGroup: {
|
|
232
|
+
...t.activeIndexByGroup,
|
|
233
|
+
[e]: n
|
|
234
|
+
}
|
|
235
|
+
}));
|
|
236
|
+
}, []);
|
|
237
|
+
return h(() => ({
|
|
238
|
+
openPopup: n,
|
|
239
|
+
closePopup: r,
|
|
240
|
+
setActiveIndex: i,
|
|
241
|
+
isOpen: (t) => e.openGroupSourceUrl === t,
|
|
242
|
+
getActiveIndex: (t) => e.activeIndexByGroup[t] ?? 0
|
|
243
|
+
}), [
|
|
244
|
+
n,
|
|
245
|
+
r,
|
|
246
|
+
i,
|
|
247
|
+
e
|
|
248
|
+
]);
|
|
249
|
+
}, F = (e) => {
|
|
250
|
+
try {
|
|
251
|
+
return decodeURIComponent(e);
|
|
252
|
+
} catch {
|
|
253
|
+
return e;
|
|
254
|
+
}
|
|
255
|
+
}, I = (e) => {
|
|
256
|
+
try {
|
|
257
|
+
let t = new URL(e);
|
|
258
|
+
return t.pathname.split("/").map((e) => F(e)).filter(Boolean).at(-1) ?? t.hostname;
|
|
259
|
+
} catch {
|
|
260
|
+
return e.split("/").map((e) => F(e)).filter(Boolean).at(-1) ?? e;
|
|
261
|
+
}
|
|
262
|
+
}, L = (e) => {
|
|
263
|
+
let t = /* @__PURE__ */ new Map();
|
|
264
|
+
for (let n of e) {
|
|
265
|
+
let e = n.body?.source?.attachment?.url;
|
|
266
|
+
if (e == null) continue;
|
|
267
|
+
let r = t.get(e);
|
|
268
|
+
r ? r.annotations.push(n) : t.set(e, {
|
|
269
|
+
sourceUrl: e,
|
|
270
|
+
sourceName: n.body?.source?.attachment?.title ?? I(e),
|
|
271
|
+
annotations: [n],
|
|
272
|
+
primaryAnnotation: n
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return Array.from(t.values());
|
|
276
|
+
}, R = /⟦C(\d+)⟧/g, z = (e, t) => {
|
|
277
|
+
let n = t.map((t, n) => {
|
|
278
|
+
let r = t.primaryAnnotation.target?.selector, i = typeof r == "object" && r && "type" in r && r.type === "text_character_range" ? r.end : e.length;
|
|
279
|
+
return {
|
|
280
|
+
idx: n,
|
|
281
|
+
pos: Math.min(i, e.length)
|
|
282
|
+
};
|
|
283
|
+
}).sort((e, t) => t.pos - e.pos), r = e;
|
|
284
|
+
for (let { idx: e, pos: t } of n) r = `${r.slice(0, t)}⟦C${e}⟧${r.slice(t)}`;
|
|
285
|
+
return r;
|
|
286
|
+
}, B = (e, t) => {
|
|
287
|
+
if (typeof e == "string") {
|
|
288
|
+
let n = e.split(R);
|
|
289
|
+
if (n.length === 1) return e;
|
|
290
|
+
let r = [];
|
|
291
|
+
return n.forEach((e, n) => {
|
|
292
|
+
n % 2 == 1 ? r.push(t(parseInt(e, 10))) : e && r.push(e);
|
|
293
|
+
}), r;
|
|
294
|
+
}
|
|
295
|
+
return Array.isArray(e) ? e.flatMap((e) => {
|
|
296
|
+
let n = B(e, t);
|
|
297
|
+
return Array.isArray(n) ? n : [n];
|
|
298
|
+
}) : e;
|
|
299
|
+
}, V = (e) => e.url == null && e.reference_url != null, H = /^(.*\.pdf)(?:#page=(\d+))?$/i, U = (e) => {
|
|
300
|
+
let t = H.exec(e);
|
|
301
|
+
return t ? {
|
|
302
|
+
baseUrl: t[1],
|
|
303
|
+
page: t[2] == null ? null : Number(t[2])
|
|
304
|
+
} : null;
|
|
305
|
+
}, W = (t) => L((t ?? []).filter(V).map((t) => {
|
|
306
|
+
let n = t.reference_url, r = U(n) != null;
|
|
307
|
+
return { body: {
|
|
308
|
+
quote: t.data,
|
|
309
|
+
source: {
|
|
310
|
+
type: "attachment",
|
|
311
|
+
attachment: {
|
|
312
|
+
type: r ? e.PDF : t.reference_type ?? t.type ?? "",
|
|
313
|
+
url: n,
|
|
314
|
+
title: t.title
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} };
|
|
318
|
+
}));
|
|
319
|
+
//#endregion
|
|
320
|
+
export { y as CitationCard, S as CitationCardProvider, w as CitationDropdown, b as CitationMarker, D as annotationHighlightId, E as annotationsToPdfHighlights, W as getReferenceAttachmentGroups, L as groupAnnotationsBySource, z as injectCitationSentinels, V as isReferenceOnlyAttachment, A as normalizeRawAnnotations, U as parsePdfPageReference, B as replaceSentinelsInChildren, j as resolveMessageAnnotations, M as useAnnotations, P as useCitationCard, C as useCitationCardContext };
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@epam/ai-dial-quotations",
|
|
3
|
+
"description": "Citation and annotation components, hooks, and utilities for AI DIAL conversations",
|
|
4
|
+
"version": "1.1.0-dev.88",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./index.js",
|
|
8
|
+
"module": "./index.js",
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./index.d.ts",
|
|
14
|
+
"import": "./index.js",
|
|
15
|
+
"default": "./index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": "^19.0.0",
|
|
20
|
+
"@tabler/icons-react": "^3.0.0",
|
|
21
|
+
"@epam/ai-dial-chat-shared": "1.1.0-dev.88",
|
|
22
|
+
"@epam/ai-dial-ui-kit": "^0.13.0-dev.26",
|
|
23
|
+
"@epam/pdf-highlighter-kit": ">=0.0.14"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/epam/ai-dial-chat.git",
|
|
28
|
+
"directory": "libs/quotations"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/test-setup.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-setup.d.ts","sourceRoot":"","sources":["../src/test-setup.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Annotation, AttachmentResource, Message, MessageAttachment } from '@epam/ai-dial-chat-shared';
|
|
2
|
+
import { InputHighlightData } from '@epam/pdf-highlighter-kit';
|
|
3
|
+
/**
|
|
4
|
+
* Maps a list of annotations to `InputHighlightData` entries for the PDF viewer.
|
|
5
|
+
* Annotations whose `body.selector` contains no `pdf_bbox` selectors are skipped.
|
|
6
|
+
* The highlight `id` is `annotation.index` when present, otherwise the position
|
|
7
|
+
* in the input array.
|
|
8
|
+
*/
|
|
9
|
+
export declare const annotationsToPdfHighlights: (annotations: Annotation[]) => InputHighlightData[];
|
|
10
|
+
/** Returns a stable string ID for a given annotation, matching the IDs produced by `annotationsToPdfHighlights`. */
|
|
11
|
+
export declare const annotationHighlightId: (annotation: Annotation, fallbackIndex: number) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Normalizes raw annotations from the API wire format (stored in
|
|
14
|
+
* `message.custom_fields.annotations`) to the internal `Annotation` model.
|
|
15
|
+
*
|
|
16
|
+
* The API format uses `target.source.attachment_index` (integer) and a
|
|
17
|
+
* `pdf_region` selector with `{ left, top, width, height }` coordinates.
|
|
18
|
+
* The internal model uses `body.source.attachment.url` (resolved URL) and a
|
|
19
|
+
* `pdf_bbox` selector with `{ x1, y1, x2, y2 }` coordinates.
|
|
20
|
+
*
|
|
21
|
+
* Annotations whose attachment index cannot be resolved or whose selector
|
|
22
|
+
* is not a recognised PDF region are omitted from the result.
|
|
23
|
+
*/
|
|
24
|
+
export declare const normalizeRawAnnotations: (rawAnnotations: unknown[], attachments: MessageAttachment[]) => Annotation[];
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the annotation list for a message regardless of how it was loaded.
|
|
27
|
+
*
|
|
28
|
+
* Prefers `custom_content.annotations` (internal format) when present.
|
|
29
|
+
* Falls back to `custom_fields.annotations` (raw API wire format) and
|
|
30
|
+
* normalises those entries using the message's `custom_content.attachments`.
|
|
31
|
+
*/
|
|
32
|
+
export declare const resolveMessageAnnotations: (message: Message) => Annotation[];
|
|
33
|
+
export type { AttachmentResource };
|
|
34
|
+
//# sourceMappingURL=annotation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotation.d.ts","sourceRoot":"","sources":["../../src/utils/annotation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,OAAO,EACP,iBAAiB,EAElB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAEV,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AAUnC;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GACrC,aAAa,UAAU,EAAE,KACxB,kBAAkB,EAoBjB,CAAC;AAEL,oHAAoH;AACpH,eAAO,MAAM,qBAAqB,GAChC,YAAY,UAAU,EACtB,eAAe,MAAM,KACpB,MAAmD,CAAC;AA+BvD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,GAClC,gBAAgB,OAAO,EAAE,EACzB,aAAa,iBAAiB,EAAE,KAC/B,UAAU,EAmDT,CAAC;AAEL;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,OAAO,KAAG,UAAU,EAkBtE,CAAC;AAGF,YAAY,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AnnotationGroup } from './group-annotations-by-source';
|
|
3
|
+
/**
|
|
4
|
+
* Inserts sentinel strings into `content` at the `end` character offsets of
|
|
5
|
+
* each annotation group's primary selector. Offsets are processed in
|
|
6
|
+
* descending order so earlier insertions do not shift later ones.
|
|
7
|
+
*/
|
|
8
|
+
export declare const injectCitationSentinels: (content: string, groups: AnnotationGroup[]) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Recursively walks a React child tree and replaces sentinel strings with
|
|
11
|
+
* the result of `renderMarker(idx)`. Handles string children, arrays, and
|
|
12
|
+
* React elements whose `children` prop is a string.
|
|
13
|
+
*/
|
|
14
|
+
export declare const replaceSentinelsInChildren: (children: ReactNode, renderMarker: (idx: number) => ReactNode) => ReactNode;
|
|
15
|
+
//# sourceMappingURL=citation-injection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"citation-injection.d.ts","sourceRoot":"","sources":["../../src/utils/citation-injection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAUrE;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,EACf,QAAQ,eAAe,EAAE,KACxB,MAoBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,GACrC,UAAU,SAAS,EACnB,cAAc,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,KACvC,SA0BF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Annotation } from '@epam/ai-dial-chat-shared';
|
|
2
|
+
/** A set of annotations that all cite the same source document. */
|
|
3
|
+
export interface AnnotationGroup {
|
|
4
|
+
/** The attachment URL shared by all annotations in this group. */
|
|
5
|
+
sourceUrl: string;
|
|
6
|
+
/**
|
|
7
|
+
* Human-readable name derived from the URL: the last non-empty path segment
|
|
8
|
+
* (decoded, without query params) when available, otherwise the URL hostname.
|
|
9
|
+
*/
|
|
10
|
+
sourceName: string;
|
|
11
|
+
/** Every annotation in this group, in their original order. */
|
|
12
|
+
annotations: Annotation[];
|
|
13
|
+
/** The first annotation in the group — used for the inline citation marker position. */
|
|
14
|
+
primaryAnnotation: Annotation;
|
|
15
|
+
}
|
|
16
|
+
/** Groups annotations by their source attachment URL. Annotations without a `body.source.attachment.url` are excluded. */
|
|
17
|
+
export declare const groupAnnotationsBySource: (annotations: Annotation[]) => AnnotationGroup[];
|
|
18
|
+
//# sourceMappingURL=group-annotations-by-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-annotations-by-source.d.ts","sourceRoot":"","sources":["../../src/utils/group-annotations-by-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,wFAAwF;IACxF,iBAAiB,EAAE,UAAU,CAAC;CAC/B;AA2BD,0HAA0H;AAC1H,eAAO,MAAM,wBAAwB,GACnC,aAAa,UAAU,EAAE,KACxB,eAAe,EAsBjB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MessageAttachment } from '@epam/ai-dial-chat-shared';
|
|
2
|
+
import { AnnotationGroup } from './group-annotations-by-source';
|
|
3
|
+
/**
|
|
4
|
+
* A `MessageAttachment` is "reference-only" when it carries a `reference_url`
|
|
5
|
+
* (e.g. a RAG/search-grounding chunk) but no directly downloadable `url`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isReferenceOnlyAttachment: (dto: MessageAttachment) => boolean;
|
|
8
|
+
/** A reference URL pointing at a specific (optional) page of a PDF file. */
|
|
9
|
+
export interface PdfPageReference {
|
|
10
|
+
/** The PDF file URL/id with the `#page=` fragment stripped. */
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
/** 1-based page number, or `null` when the reference has no page fragment. */
|
|
13
|
+
page: number | null;
|
|
14
|
+
}
|
|
15
|
+
/** Parses a reference URL that points at a PDF file, optionally with a `#page=N` fragment. Returns `null` when the URL does not target a PDF. */
|
|
16
|
+
export declare const parsePdfPageReference: (url: string) => PdfPageReference | null;
|
|
17
|
+
/**
|
|
18
|
+
* Maps reference-only attachments to synthetic {@link Annotation}s and groups
|
|
19
|
+
* them by `reference_url`, reusing the same grouping core inline citations use,
|
|
20
|
+
* so repeated chunks from the same source collapse into one group with a
|
|
21
|
+
* Prev/Next switcher.
|
|
22
|
+
*/
|
|
23
|
+
export declare const getReferenceAttachmentGroups: (dtos: MessageAttachment[] | undefined) => AnnotationGroup[];
|
|
24
|
+
//# sourceMappingURL=reference-attachment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-attachment.d.ts","sourceRoot":"","sources":["../../src/utils/reference-attachment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,+BAA+B,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,yBAAyB,GAAI,KAAK,iBAAiB,KAAG,OACrB,CAAC;AAE/C,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAID,iJAAiJ;AACjJ,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,KAAG,gBAAgB,GAAG,IAOtE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,GACvC,MAAM,iBAAiB,EAAE,GAAG,SAAS,KACpC,eAAe,EAyBjB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Annotation, Message } from '@epam/ai-dial-chat-shared';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the resolved annotation list for an assistant message.
|
|
4
|
+
* Returns an empty array while streaming is in progress.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useAnnotations: (message: Message, isStreaming: boolean) => Annotation[];
|
|
7
|
+
//# sourceMappingURL=useAnnotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAnnotations.d.ts","sourceRoot":"","sources":["../../src/utils/useAnnotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAIrE;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,OAAO,EAChB,aAAa,OAAO,KACnB,UAAU,EAKZ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages open/close state and per-group active annotation index for citation
|
|
3
|
+
* cards within a single assistant message.
|
|
4
|
+
*/
|
|
5
|
+
export declare const useCitationCard: () => {
|
|
6
|
+
openPopup: (sourceUrl: string) => void;
|
|
7
|
+
closePopup: () => void;
|
|
8
|
+
setActiveIndex: (sourceUrl: string, index: number) => void;
|
|
9
|
+
isOpen: (sourceUrl: string) => boolean;
|
|
10
|
+
getActiveIndex: (sourceUrl: string) => number;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=useCitationCard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCitationCard.d.ts","sourceRoot":"","sources":["../../src/utils/useCitationCard.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,eAAO,MAAM,eAAe;2BAGgB,MAAM;;gCAQD,MAAM,SAAS,MAAM;wBAY5C,MAAM;gCACE,MAAM;CAKvC,CAAC"}
|