@kapaai/support-form-deflector 0.13.0 → 0.14.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/dist/apps/react-sdk/src/hooks/use-user-identifiers.d.ts +13 -0
- package/dist/apps/react-sdk/src/hooks/use-user-identifiers.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/index.d.ts +8 -0
- package/dist/apps/react-sdk/src/index.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/lib/api.d.ts +117 -0
- package/dist/apps/react-sdk/src/lib/api.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/lib/conversation.d.ts +23 -0
- package/dist/apps/react-sdk/src/lib/conversation.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/lib/deep-thinking.d.ts +34 -0
- package/dist/apps/react-sdk/src/lib/deep-thinking.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/lib/utils.d.ts +30 -0
- package/dist/apps/react-sdk/src/lib/utils.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/provider.d.ts +92 -0
- package/dist/apps/react-sdk/src/provider.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/reducer.d.ts +47 -0
- package/dist/apps/react-sdk/src/reducer.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/types/auth.d.ts +8 -0
- package/dist/apps/react-sdk/src/types/auth.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/types/chat.d.ts +2 -0
- package/dist/apps/react-sdk/src/types/chat.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/types/feedback.d.ts +15 -0
- package/dist/apps/react-sdk/src/types/feedback.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/types/index.d.ts +7 -0
- package/dist/apps/react-sdk/src/types/index.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/types/qa.d.ts +49 -0
- package/dist/apps/react-sdk/src/types/qa.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/types/sdk-context.d.ts +110 -0
- package/dist/apps/react-sdk/src/types/sdk-context.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/types/user.d.ts +17 -0
- package/dist/apps/react-sdk/src/types/user.d.ts.map +1 -0
- package/dist/apps/react-sdk/src/use-ask-ai.d.ts +37 -0
- package/dist/apps/react-sdk/src/use-ask-ai.d.ts.map +1 -0
- package/dist/apps/support-form-deflector/src/answer/index.d.ts +2 -2
- package/dist/apps/support-form-deflector/src/answer/index.d.ts.map +1 -1
- package/dist/apps/support-form-deflector/src/config/parse-config.d.ts.map +1 -1
- package/dist/apps/support-form-deflector/src/config/types.d.ts +15 -21
- package/dist/apps/support-form-deflector/src/config/types.d.ts.map +1 -1
- package/dist/apps/support-form-deflector/src/index.d.ts.map +1 -1
- package/dist/apps/support-form-deflector/src/modal/DeflectorModal.d.ts +2 -0
- package/dist/apps/support-form-deflector/src/modal/DeflectorModal.d.ts.map +1 -0
- package/dist/apps/support-form-deflector/src/modal/InputArea.d.ts +12 -0
- package/dist/apps/support-form-deflector/src/modal/InputArea.d.ts.map +1 -0
- package/dist/apps/support-form-deflector/src/modal/MarkdownErrorBoundary.d.ts +18 -0
- package/dist/apps/support-form-deflector/src/modal/MarkdownErrorBoundary.d.ts.map +1 -0
- package/dist/apps/support-form-deflector/src/modal/ModalHeader.d.ts +6 -0
- package/dist/apps/support-form-deflector/src/modal/ModalHeader.d.ts.map +1 -0
- package/dist/apps/support-form-deflector/src/state.d.ts +14 -12
- package/dist/apps/support-form-deflector/src/state.d.ts.map +1 -1
- package/dist/apps/support-form-deflector/src/utils/constants.d.ts +2 -0
- package/dist/apps/support-form-deflector/src/utils/constants.d.ts.map +1 -0
- package/dist/apps/support-form-deflector/src/utils/deflection-state-guards.d.ts +7 -0
- package/dist/apps/support-form-deflector/src/utils/deflection-state-guards.d.ts.map +1 -0
- package/dist/apps/support-form-deflector/src/utils/deflection-state-guards.test.d.ts +2 -0
- package/dist/apps/support-form-deflector/src/utils/deflection-state-guards.test.d.ts.map +1 -0
- package/dist/kapa-support-form-deflector.bundle.js +1 -1
- package/dist/kapa-support-form-deflector.bundle.js.LICENSE.txt +2 -0
- package/dist/packages/utils/src/components/KapaIcon.d.ts +9 -0
- package/dist/packages/utils/src/components/KapaIcon.d.ts.map +1 -0
- package/dist/packages/utils/src/config/style-parser.d.ts +32 -42
- package/dist/packages/utils/src/config/style-parser.d.ts.map +1 -1
- package/dist/packages/utils/src/helpers/stream-processor.d.ts +13 -0
- package/dist/packages/utils/src/helpers/stream-processor.d.ts.map +1 -0
- package/dist/packages/utils/src/helpers/streaming-types.d.ts +33 -0
- package/dist/packages/utils/src/helpers/streaming-types.d.ts.map +1 -0
- package/dist/packages/utils/src/hooks/use-auto-scroll.d.ts +26 -0
- package/dist/packages/utils/src/hooks/use-auto-scroll.d.ts.map +1 -0
- package/dist/packages/utils/src/index.d.ts +5 -0
- package/dist/packages/utils/src/index.d.ts.map +1 -1
- package/package.json +18 -16
- package/dist/apps/support-form-deflector/src/answer/answer-box.d.ts +0 -3
- package/dist/apps/support-form-deflector/src/answer/answer-box.d.ts.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UserTrackingMode, UserIdentifiers, UserMetadata } from "../types";
|
|
2
|
+
interface UseUserIdentifiersConfig {
|
|
3
|
+
mode: UserTrackingMode;
|
|
4
|
+
}
|
|
5
|
+
interface UseUserIdentifiersReturn {
|
|
6
|
+
buildIdentifiers: () => Promise<{
|
|
7
|
+
identifiers: UserIdentifiers;
|
|
8
|
+
metadata: UserMetadata;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export declare const useUserIdentifiers: (config: UseUserIdentifiersConfig) => UseUserIdentifiersReturn;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=use-user-identifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-user-identifiers.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/hooks/use-user-identifiers.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAI3E,UAAU,wBAAwB;IAChC,IAAI,EAAE,gBAAgB,CAAC;CACxB;AAED,UAAU,wBAAwB;IAChC,gBAAgB,EAAE,MAAM,OAAO,CAAC;QAC9B,WAAW,EAAE,eAAe,CAAC;QAC7B,QAAQ,EAAE,YAAY,CAAC;KACxB,CAAC,CAAC;CACJ;AAED,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,wBAAwB,KAC/B,wBA4DF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useCaptcha, CaptchaAction, processStream } from "@kapaai/utils";
|
|
2
|
+
import { DefaultKapaApiService } from "./lib/api";
|
|
3
|
+
import { useDeepThinking } from "./lib/deep-thinking";
|
|
4
|
+
import { KapaSDKProvider } from "./provider";
|
|
5
|
+
import useChat from "./use-ask-ai";
|
|
6
|
+
export { useChat, useDeepThinking, KapaSDKProvider as KapaProvider, DefaultKapaApiService, processStream, useCaptcha, CaptchaAction, };
|
|
7
|
+
export * from "./types";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../react-sdk/src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EACL,OAAO,EACP,eAAe,EACf,eAAe,IAAI,YAAY,EAC/B,qBAAqB,EACrB,aAAa,EACb,UAAU,EACV,aAAa,GACd,CAAC;AAEF,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { processStream } from "@kapaai/utils";
|
|
2
|
+
import type { StreamSource } from "@kapaai/utils";
|
|
3
|
+
import { CaptchaToken, FeedbackComment, Reaction, UserIdentifiers, UserMetadata } from "../types";
|
|
4
|
+
import { QueryMode } from "../types/chat";
|
|
5
|
+
export interface SubmitQueryArgs {
|
|
6
|
+
/** User's question */
|
|
7
|
+
query: string;
|
|
8
|
+
mode?: QueryMode;
|
|
9
|
+
/**
|
|
10
|
+
* Optional thread ID for continuing a conversation.
|
|
11
|
+
* If null, a new conversation thread will be created.
|
|
12
|
+
*/
|
|
13
|
+
threadId: string | null;
|
|
14
|
+
/** reCAPTCHA/hCaptcha verification token for bot protection */
|
|
15
|
+
captcha: CaptchaToken;
|
|
16
|
+
/** Your Kapa integration ID */
|
|
17
|
+
integrationId: string;
|
|
18
|
+
/** Source groups to include in the answer */
|
|
19
|
+
sourceGroupIDsInclude?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* User identification data that helps with personalization
|
|
22
|
+
* and tracking conversation history
|
|
23
|
+
*/
|
|
24
|
+
userIdentifiers: UserIdentifiers;
|
|
25
|
+
/** Additional user metadata for analytics/tracking */
|
|
26
|
+
userMetadata: UserMetadata;
|
|
27
|
+
/** The URL where the query was initiated */
|
|
28
|
+
originUrl: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parameters for submitting user feedback on answers.
|
|
32
|
+
*/
|
|
33
|
+
export interface SubmitFeedbackArgs {
|
|
34
|
+
/** Unique identifier for the question-answer pair */
|
|
35
|
+
questionAnswerId: string;
|
|
36
|
+
/** User's reaction to an answer */
|
|
37
|
+
reaction: Reaction;
|
|
38
|
+
/** reCAPTCHA/hCaptcha verification token for bot protection */
|
|
39
|
+
captcha: CaptchaToken;
|
|
40
|
+
/** Your Kapa integration ID */
|
|
41
|
+
integrationId: string;
|
|
42
|
+
/** Optional user-provided comment/reason */
|
|
43
|
+
comment?: FeedbackComment;
|
|
44
|
+
}
|
|
45
|
+
export interface ChatStreamCallbacks {
|
|
46
|
+
/**
|
|
47
|
+
* Called when the first response byte is received.
|
|
48
|
+
* Useful for updating UI to show that streaming has begun.
|
|
49
|
+
*/
|
|
50
|
+
onFirstToken?: () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Called repeatedly with chunks of the answer as they arrive.
|
|
53
|
+
* @param partial - The new text chunk to append to the answer
|
|
54
|
+
*/
|
|
55
|
+
onPartialAnswer?: (partial: string) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Called with the metadata of the answer at the end of the stream.
|
|
58
|
+
* @param metadata - The metadata of the answer
|
|
59
|
+
*/
|
|
60
|
+
onMetadata?: (metadata: {
|
|
61
|
+
is_uncertain: boolean;
|
|
62
|
+
}) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Called with the list of relevant citation sources.
|
|
65
|
+
* @param sources - Array of source documents cited in the answer
|
|
66
|
+
*/
|
|
67
|
+
onRelevantSources?: (sources: StreamSource[]) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Called when an error occurs during streaming.
|
|
70
|
+
* @param msg - The error message
|
|
71
|
+
*/
|
|
72
|
+
onError?: (msg: string) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Called with thread and QA pair identifiers once they're available.
|
|
75
|
+
* @param threadId - The conversation thread ID
|
|
76
|
+
* @param qaPairId - The unique ID for this question-answer pair
|
|
77
|
+
*/
|
|
78
|
+
onIdentifiers?: (threadId: string, qaPairId: string) => void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Interface for API service that handles communication with the Kapa AI backend.
|
|
82
|
+
*/
|
|
83
|
+
export interface KapaApiService {
|
|
84
|
+
/** Post a question to the backend and stream back the answer */
|
|
85
|
+
submitQuery(args: SubmitQueryArgs, cbs: ChatStreamCallbacks): Promise<void>;
|
|
86
|
+
/** Send feedback (👍 / 👎) for a specific QA pair */
|
|
87
|
+
addFeedback(args: SubmitFeedbackArgs): Promise<void>;
|
|
88
|
+
/** Abort the current network request, if any */
|
|
89
|
+
abortCurrent(): void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Default implementation of the KapaApiService interface.
|
|
93
|
+
* Handles API communication with the Kapa backend, including streaming
|
|
94
|
+
* responses and feedback submission.
|
|
95
|
+
*
|
|
96
|
+
* @implements {KapaApiService}
|
|
97
|
+
*/
|
|
98
|
+
export declare class DefaultKapaApiService implements KapaApiService {
|
|
99
|
+
private abortController;
|
|
100
|
+
private proxyURL;
|
|
101
|
+
private processStreamFn;
|
|
102
|
+
constructor(processStreamFn: typeof processStream, proxyURL?: string);
|
|
103
|
+
/**
|
|
104
|
+
* Cancels any ongoing API request.
|
|
105
|
+
* Creates a new AbortController for future requests.
|
|
106
|
+
*/
|
|
107
|
+
abortCurrent(): void;
|
|
108
|
+
/**
|
|
109
|
+
* @inheritdoc
|
|
110
|
+
*/
|
|
111
|
+
submitQuery({ query, threadId, captcha, integrationId, sourceGroupIDsInclude, userIdentifiers, userMetadata, originUrl, mode, }: SubmitQueryArgs, callbacks: ChatStreamCallbacks): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* @inheritdoc
|
|
114
|
+
*/
|
|
115
|
+
addFeedback({ questionAnswerId: qaPairId, reaction, captcha, integrationId, comment, }: SubmitFeedbackArgs): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/lib/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,EACL,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,eAAe,EACf,YAAY,EACb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAM1C,MAAM,WAAW,eAAe;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AE,MAAM,KAAK,IAAI,CAAC;CAC9D;AAMD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,WAAW,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5E,qDAAqD;IACrD,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErD,gDAAgD;IAChD,YAAY,IAAI,IAAI,CAAC;CACtB;AAMD;;;;;;GAMG;AACH,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,eAAe,CAErB;gBAEU,eAAe,EAAE,OAAO,aAAa,EAAE,QAAQ,CAAC,EAAE,MAAM;IAOpE;;;OAGG;IACH,YAAY;IAKZ;;OAEG;IACG,WAAW,CACf,EACE,KAAK,EACL,QAAQ,EACR,OAAO,EACP,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,SAAS,EACT,IAAgB,GACjB,EAAE,eAAe,EAClB,SAAS,EAAE,mBAAmB,GAC7B,OAAO,CAAC,IAAI,CAAC;IA+EhB;;OAEG;IACG,WAAW,CAAC,EAChB,gBAAgB,EAAE,QAAQ,EAC1B,QAAQ,EACR,OAAO,EACP,aAAa,EACb,OAAO,GACR,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAwBtC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EventCallbackQA, QA } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a conversation history with question-answer pairs.
|
|
4
|
+
* @extends Array<QA>
|
|
5
|
+
*/
|
|
6
|
+
export declare class Conversation extends Array<QA> {
|
|
7
|
+
constructor(...items: QA[]);
|
|
8
|
+
getById(id: string): QA | undefined;
|
|
9
|
+
getLatest(): QA | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the latest completed QA item from the collection.
|
|
12
|
+
*
|
|
13
|
+
* A completed QA item is identified by the presence of an `id` property.
|
|
14
|
+
* If the collection is empty or no completed items are found, the method returns `undefined`.
|
|
15
|
+
*
|
|
16
|
+
* @returns {QA | undefined} The latest completed QA item, or `undefined` if none exist.
|
|
17
|
+
*/
|
|
18
|
+
getLatestCompleted(): QA | undefined;
|
|
19
|
+
formatForCallbacks(): EventCallbackQA[];
|
|
20
|
+
setById(id: string, partialItem: Partial<QA>): void;
|
|
21
|
+
setLatest(partialItem: Partial<QA>): void;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/lib/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAE/C;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK,CAAC,EAAE,CAAC;gBAC7B,GAAG,KAAK,EAAE,EAAE,EAAE;IAK1B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,GAAG,SAAS;IAInC,SAAS,IAAI,EAAE,GAAG,SAAS;IAO3B;;;;;;;OAOG;IACH,kBAAkB,IAAI,EAAE,GAAG,SAAS;IAapC,kBAAkB,IAAI,eAAe,EAAE;IAQvC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI;IAOnD,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI;CAS1C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This context is used to manage the deep thinking mode and timer.
|
|
3
|
+
* We do not want to expose this to the SDK users yet until we are sure that,
|
|
4
|
+
* the API will not change, however, there is no way around it, because the
|
|
5
|
+
* widget consumes the SDK.
|
|
6
|
+
* If we were to put the DeepThinkingContext inside the utils package,
|
|
7
|
+
* this would not work, because we bundle the utils package with the SDK
|
|
8
|
+
* and the widget, given that it is not a public package. This leads to
|
|
9
|
+
* the SDK and the widget having different instances of the context.
|
|
10
|
+
* For now, we will keep the DeepThinkingContext inside the react-sdk package,
|
|
11
|
+
* meaning users could theoretically import it, but we will not document it anywhere.
|
|
12
|
+
*/
|
|
13
|
+
interface DeepThinkingContextType {
|
|
14
|
+
active: boolean;
|
|
15
|
+
seconds: number;
|
|
16
|
+
toggle: () => void;
|
|
17
|
+
activate: () => void;
|
|
18
|
+
deactivate: () => void;
|
|
19
|
+
startTimer: () => void;
|
|
20
|
+
stopTimer: () => void;
|
|
21
|
+
}
|
|
22
|
+
export declare const DeepThinkingContext: import("react").Context<DeepThinkingContextType | null>;
|
|
23
|
+
export declare const DeepThinkingProvider: ({ children, }: {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export declare const useDeepThinking: () => {
|
|
27
|
+
active: boolean;
|
|
28
|
+
seconds: number;
|
|
29
|
+
toggle: () => void;
|
|
30
|
+
activate: () => void;
|
|
31
|
+
deactivate: () => void;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=deep-thinking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-thinking.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/lib/deep-thinking.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA8BH,UAAU,uBAAuB;IAC/B,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,eAAO,MAAM,mBAAmB,yDACqB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,GAAI,eAElC;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,4CAkHA,CAAC;AAEF,eAAO,MAAM,eAAe;;;kBAlIZ,IAAI;oBACF,IAAI;sBACF,IAAI;CA+IvB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { StreamSource } from "@kapaai/utils";
|
|
2
|
+
/***
|
|
3
|
+
* Removes a specified character from the beginning and end of a string
|
|
4
|
+
*/
|
|
5
|
+
export declare function strip(str: string, char: string): string;
|
|
6
|
+
export declare const getFaviconUrl: (url: string) => string;
|
|
7
|
+
export declare const humanizeUrl: (url: string) => string;
|
|
8
|
+
export declare function normalizeUrl(url: string): string;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param title
|
|
12
|
+
* Removes the suffix `Part N` of the title.
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeTitle(title: string): string;
|
|
15
|
+
export declare function getSourceTitles(sourceTitle: string): [string, string];
|
|
16
|
+
type SourceWithoutSubtitle = Omit<StreamSource, "subtitle">;
|
|
17
|
+
export declare function splitSourceTitles(sources: SourceWithoutSubtitle[]): StreamSource[];
|
|
18
|
+
export declare const extractUrls: (text: string) => Set<string>;
|
|
19
|
+
export declare function getUniqueSources(sources: StreamSource[]): StreamSource[];
|
|
20
|
+
/**
|
|
21
|
+
* Gets the intersection of all retreived sources and sources cited
|
|
22
|
+
* in the answer by comparing unique links.
|
|
23
|
+
*
|
|
24
|
+
* @param answer
|
|
25
|
+
* @param sources
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare const getSourcesFromAnswer: (answer: string, sources: StreamSource[]) => StreamSource[];
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAG9C;AAED,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,WAGxC,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,WAStC,CAAC;AAEF,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,UAEvC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,UAU3C;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAoBrE;AAED,KAAK,qBAAqB,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAG5D,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,qBAAqB,EAAE,GAC/B,YAAY,EAAE,CAShB;AAED,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,GAAG,CAAC,MAAM,CAOpD,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,kBAcvD;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,MAAM,EACd,SAAS,YAAY,EAAE,mBAOxB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { KapaApiService } from "./lib/api";
|
|
3
|
+
import { Conversation } from "./lib/conversation";
|
|
4
|
+
import { Callbacks, FeedbackComment, Reaction, UserTrackingMode } from "./types";
|
|
5
|
+
export declare const SDKContext: React.Context<{
|
|
6
|
+
integrationId: string;
|
|
7
|
+
error?: string | null;
|
|
8
|
+
isPreparingAnswer: boolean;
|
|
9
|
+
isGeneratingAnswer: boolean;
|
|
10
|
+
conversation: Conversation;
|
|
11
|
+
callbacks: Callbacks;
|
|
12
|
+
threadId: string | null;
|
|
13
|
+
submitQuery: (query: string) => void;
|
|
14
|
+
resetConversation: () => void;
|
|
15
|
+
stopGeneration: () => void;
|
|
16
|
+
addFeedback: (questionAnswerId: string, reaction: Reaction, comment?: FeedbackComment) => void;
|
|
17
|
+
} | undefined>;
|
|
18
|
+
export interface InternalKapaSDKProviderProps {
|
|
19
|
+
children: React.ReactNode;
|
|
20
|
+
integrationId: string;
|
|
21
|
+
sourceGroupIDsInclude?: string[];
|
|
22
|
+
uncertainAnswerCallout?: string;
|
|
23
|
+
userTrackingMode: UserTrackingMode;
|
|
24
|
+
callbacks?: Callbacks;
|
|
25
|
+
/**
|
|
26
|
+
* Swappable API layer. Defaults to {@link DefaultKapaApiService} but you can stub it
|
|
27
|
+
* in unit tests or storybooks.
|
|
28
|
+
*/
|
|
29
|
+
apiService?: KapaApiService;
|
|
30
|
+
}
|
|
31
|
+
export declare const InternalKapaSDKProvider: React.FC<InternalKapaSDKProviderProps>;
|
|
32
|
+
/**
|
|
33
|
+
* Context provider for the kapa.ai SDK
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```jsx
|
|
37
|
+
* <KapaSDKProvider integrationId="your_id" callbacks={{}}>
|
|
38
|
+
* <YourComponent />
|
|
39
|
+
* </KapaSDKProvider>
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare const KapaSDKProvider: React.FC<{
|
|
45
|
+
children: React.ReactNode;
|
|
46
|
+
/**
|
|
47
|
+
* Your Kapa integration identifier
|
|
48
|
+
* @example "6d04c434-4090-4ebf-aeb3-8e90645a504d"
|
|
49
|
+
* @required
|
|
50
|
+
*/
|
|
51
|
+
integrationId: string;
|
|
52
|
+
/**
|
|
53
|
+
* Source group IDs to include in the answer
|
|
54
|
+
* @example ["source-group-1", "source-group-2"]
|
|
55
|
+
*/
|
|
56
|
+
sourceGroupIDsInclude?: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Text to append to the answer when it is uncertain
|
|
59
|
+
* @example "Please reach out to our [support team](https://kapa.ai/support) for further assistance."
|
|
60
|
+
*/
|
|
61
|
+
uncertainAnswerCallout?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Callback functions for tracking user interactions with the SDK
|
|
64
|
+
* @example { onAskQuestion: (q) => console.log('question_asked', { question: q }) }
|
|
65
|
+
* @required
|
|
66
|
+
*/
|
|
67
|
+
callbacks?: Callbacks;
|
|
68
|
+
/**
|
|
69
|
+
* Enable browser fingerprinting or cookie keeping track of a unique
|
|
70
|
+
* identifier (kapa_web_id).
|
|
71
|
+
* When enabled, the SDK generates anonymized IDs for end users
|
|
72
|
+
* @default "cookie"
|
|
73
|
+
*/
|
|
74
|
+
userTrackingMode?: UserTrackingMode;
|
|
75
|
+
/**
|
|
76
|
+
* Choose which captcha provider to use for bot protection
|
|
77
|
+
* @default "recaptcha"
|
|
78
|
+
*/
|
|
79
|
+
botProtectionMechanism?: "recaptcha" | "hcaptcha";
|
|
80
|
+
/**
|
|
81
|
+
* Whether the user has provided consent for captcha
|
|
82
|
+
* Set to false if you need to obtain consent before enabling captcha
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
hasConsentForCaptcha?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Optional API service implementation for testing or custom networking
|
|
88
|
+
* You can provide a custom implementation that follows the KapaApiService interface
|
|
89
|
+
*/
|
|
90
|
+
apiService?: KapaApiService;
|
|
91
|
+
}>;
|
|
92
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../../react-sdk/src/provider.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAyB,cAAc,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,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AGG;IACH,sBAAsB,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;IAElD;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;;OAGG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B,CAmDA,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { StreamSource } from "@kapaai/utils";
|
|
2
|
+
import { Conversation } from "./lib/conversation";
|
|
3
|
+
import { Reaction, QAPendingCompletion } from "./types";
|
|
4
|
+
export interface ChatState {
|
|
5
|
+
isPreparing: boolean;
|
|
6
|
+
isGenerating: boolean;
|
|
7
|
+
threadId: string | null;
|
|
8
|
+
conversation: Conversation;
|
|
9
|
+
error: string | null;
|
|
10
|
+
}
|
|
11
|
+
type ChatAction = {
|
|
12
|
+
type: "ADD_NEW_QA";
|
|
13
|
+
query: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: "SET_IDENTIFIERS";
|
|
16
|
+
threadId: string;
|
|
17
|
+
questionAnswerId: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "SET_RELEVANT_SOURCES";
|
|
20
|
+
sources: StreamSource[];
|
|
21
|
+
} | {
|
|
22
|
+
type: "SET_PARTIAL_ANSWER";
|
|
23
|
+
answer: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: "SET_METADATA";
|
|
26
|
+
metadata: QAPendingCompletion["metadata"];
|
|
27
|
+
} | {
|
|
28
|
+
type: "SET_ERROR";
|
|
29
|
+
message: string;
|
|
30
|
+
} | {
|
|
31
|
+
type: "SET_IS_GENERATING";
|
|
32
|
+
isGenerating: boolean;
|
|
33
|
+
} | {
|
|
34
|
+
type: "RESET_CONVERSATION";
|
|
35
|
+
} | {
|
|
36
|
+
type: "STOP_GENERATION";
|
|
37
|
+
} | {
|
|
38
|
+
type: "SET_FEEDBACK";
|
|
39
|
+
questionAnswerId: string;
|
|
40
|
+
reaction: Reaction | null;
|
|
41
|
+
} | {
|
|
42
|
+
type: "MARK_COMPLETED";
|
|
43
|
+
questionAnswerId: string;
|
|
44
|
+
};
|
|
45
|
+
export declare function chatReducer(state: ChatState, action: ChatAction): ChatState;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../../../../react-sdk/src/reducer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,QAAQ,EAAe,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAErE,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,KAAK,UAAU,GACX;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrC;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GACD;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,OAAO,EAAE,YAAY,EAAE,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,iBAAiB,CAAA;CAAE,GAC3B;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC3B,GACD;IACE,IAAI,EAAE,gBAAgB,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEN,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAG,SAAS,CAkI3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/types/auth.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/types/chat.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Reaction = "upvote" | "downvote";
|
|
2
|
+
/**
|
|
3
|
+
* Feedback comment with specific categories and free-text feedback
|
|
4
|
+
*/
|
|
5
|
+
export interface FeedbackComment {
|
|
6
|
+
incorrect?: boolean;
|
|
7
|
+
irrelevant?: boolean;
|
|
8
|
+
unaddressed?: boolean;
|
|
9
|
+
issue?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface FeedbackResponse {
|
|
12
|
+
total_upvotes: number;
|
|
13
|
+
total_downvotes: number;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=feedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/types/feedback.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./qa";
|
|
2
|
+
export type { StreamSource, StreamSource as Source, ResponseChunk, StreamChunk, RelevantSourcesChunk, PartialAnswerChunk, MetadataChunk, IdentifiersChunk, ErrorChunk, } from "@kapaai/utils";
|
|
3
|
+
export * from "./feedback";
|
|
4
|
+
export * from "./user";
|
|
5
|
+
export * from "./sdk-context";
|
|
6
|
+
export * from "./auth";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,YAAY,EACV,YAAY,EACZ,YAAY,IAAI,MAAM,EACtB,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,UAAU,GACX,MAAM,eAAe,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { StreamSource } from "@kapaai/utils";
|
|
2
|
+
import { Reaction } from "../types";
|
|
3
|
+
interface QABase {
|
|
4
|
+
/** The user's question */
|
|
5
|
+
question: string;
|
|
6
|
+
/** The AI-generated answer */
|
|
7
|
+
answer: string;
|
|
8
|
+
/** Reference sources that support the answer */
|
|
9
|
+
sources: StreamSource[];
|
|
10
|
+
/** Whether the answer generation was manually stopped */
|
|
11
|
+
isGenerationAborted: boolean;
|
|
12
|
+
/** User feedback reaction (thumbs up/down) or null if not provided */
|
|
13
|
+
reaction: Reaction | null;
|
|
14
|
+
}
|
|
15
|
+
/** Feedback not yet enabled (optimistic state while streaming) */
|
|
16
|
+
export type QAStreaming = QABase & {
|
|
17
|
+
/** ID is null during streaming */
|
|
18
|
+
id: null;
|
|
19
|
+
/** Feedback submission is disabled during streaming */
|
|
20
|
+
isFeedbackSubmissionEnabled?: false;
|
|
21
|
+
status: "streaming";
|
|
22
|
+
};
|
|
23
|
+
/** Final server record with feedback flag on */
|
|
24
|
+
export type QAPendingCompletion = QABase & {
|
|
25
|
+
/** Unique ID for this question-answer pair */
|
|
26
|
+
id: string;
|
|
27
|
+
status: "pending_completion";
|
|
28
|
+
isFeedbackSubmissionEnabled: true;
|
|
29
|
+
metadata: {
|
|
30
|
+
is_uncertain: boolean;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type QACompleted = Omit<QAPendingCompletion, "status"> & {
|
|
34
|
+
status: "completed";
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Represents a question-answer pair.
|
|
38
|
+
*/
|
|
39
|
+
export type QA = QAStreaming | QAPendingCompletion | QACompleted;
|
|
40
|
+
export interface QuestionAnswer {
|
|
41
|
+
id: string;
|
|
42
|
+
question: string;
|
|
43
|
+
answer: string;
|
|
44
|
+
relevant_sources: StreamSource[];
|
|
45
|
+
total_upvotes: number;
|
|
46
|
+
total_downvotes: number;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=qa.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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AAE,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Conversation } from "../lib/conversation";
|
|
2
|
+
import type { Reaction, FeedbackComment } from "./feedback";
|
|
3
|
+
/**
|
|
4
|
+
* Interface for the useChat hook
|
|
5
|
+
*/
|
|
6
|
+
export interface UseChat {
|
|
7
|
+
/**
|
|
8
|
+
* True when the SDK is connecting to the backend.
|
|
9
|
+
* Use this to show a loading indicator before streaming begins.
|
|
10
|
+
*/
|
|
11
|
+
isPreparingAnswer: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* True when an answer is being streamed from the AI.
|
|
14
|
+
* Use this to show a streaming indicator during generation.
|
|
15
|
+
*/
|
|
16
|
+
isGeneratingAnswer: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Error message or null if no error has occurred.
|
|
19
|
+
* Check this to display error states to the user.
|
|
20
|
+
*/
|
|
21
|
+
error: string | null;
|
|
22
|
+
/** Conversation history containing all Q&A pairs. */
|
|
23
|
+
conversation: Conversation;
|
|
24
|
+
/**
|
|
25
|
+
* Current conversation thread ID from the backend.
|
|
26
|
+
* Null for new conversations that haven't received a response yet.
|
|
27
|
+
*/
|
|
28
|
+
threadId: string | null;
|
|
29
|
+
/** Submit a new question to the AI */
|
|
30
|
+
submitQuery: (q: string) => void;
|
|
31
|
+
/** Clear the conversation history */
|
|
32
|
+
resetConversation: () => void;
|
|
33
|
+
/** Abort the current generation */
|
|
34
|
+
stopGeneration: () => void;
|
|
35
|
+
/** Send feedback for a specific Q&A pair
|
|
36
|
+
*
|
|
37
|
+
* @param questionAnswerId - The ID of the Q&A pair to provide feedback on
|
|
38
|
+
* @param reaction - The user's reaction (upvote/downvote)
|
|
39
|
+
* @param comment - Optional feedback comment
|
|
40
|
+
*/
|
|
41
|
+
addFeedback: (questionAnswerId: string, reaction: Reaction, comment?: FeedbackComment) => void;
|
|
42
|
+
}
|
|
43
|
+
export type ThreadId = string | null;
|
|
44
|
+
export type EventCallbackQA = {
|
|
45
|
+
questionAnswerId: string;
|
|
46
|
+
question: string;
|
|
47
|
+
answer: string;
|
|
48
|
+
};
|
|
49
|
+
export interface ConversationCtx {
|
|
50
|
+
/** Full conversation history, after the event occurred */
|
|
51
|
+
conversation: EventCallbackQA[];
|
|
52
|
+
/** Conversation thread ID (null for initial queries) */
|
|
53
|
+
threadId: ThreadId;
|
|
54
|
+
}
|
|
55
|
+
/** ------------- Payload shapes ------------- */
|
|
56
|
+
export interface QuerySubmitPayload extends ConversationCtx {
|
|
57
|
+
question: string;
|
|
58
|
+
}
|
|
59
|
+
export interface AnswerGenerationStopPayload extends ConversationCtx {
|
|
60
|
+
question: string;
|
|
61
|
+
}
|
|
62
|
+
export type ConversationResetPayload = ConversationCtx;
|
|
63
|
+
export interface AnswerGenerationCompletedPayload extends ConversationCtx {
|
|
64
|
+
questionAnswerId: string;
|
|
65
|
+
question: string;
|
|
66
|
+
answer: string;
|
|
67
|
+
}
|
|
68
|
+
export interface FeedbackSubmitPayload extends ConversationCtx {
|
|
69
|
+
feedbackId: string;
|
|
70
|
+
reaction: Reaction;
|
|
71
|
+
comment?: FeedbackComment;
|
|
72
|
+
questionAnswerId: string;
|
|
73
|
+
question: string;
|
|
74
|
+
answer: string;
|
|
75
|
+
}
|
|
76
|
+
export interface AskAICallbacks {
|
|
77
|
+
/**
|
|
78
|
+
* Called when a user submits a question to the AI
|
|
79
|
+
* @param p Information about the submitted query
|
|
80
|
+
*/
|
|
81
|
+
onQuerySubmit?: (p: QuerySubmitPayload) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Called when an answer has finished generating completely
|
|
84
|
+
* @param p Information about the completed answer
|
|
85
|
+
*/
|
|
86
|
+
onAnswerGenerationCompleted?: (p: AnswerGenerationCompletedPayload) => void;
|
|
87
|
+
/**
|
|
88
|
+
* Called when answer generation is manually stopped by the user
|
|
89
|
+
* @param p Information about the stopped generation
|
|
90
|
+
*/
|
|
91
|
+
onAnswerGenerationStop?: (p: AnswerGenerationStopPayload) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Called when the conversation history is reset
|
|
94
|
+
* @param p Information about the reset conversation
|
|
95
|
+
*/
|
|
96
|
+
onConversationReset?: (p: ConversationResetPayload) => void;
|
|
97
|
+
/**
|
|
98
|
+
* Called when a user submits feedback on an answer
|
|
99
|
+
* @param p Information about the submitted feedback
|
|
100
|
+
*/
|
|
101
|
+
onFeedbackSubmit?: (p: FeedbackSubmitPayload) => void;
|
|
102
|
+
}
|
|
103
|
+
export interface Callbacks {
|
|
104
|
+
/**
|
|
105
|
+
* Callbacks for Ask AI mode
|
|
106
|
+
*/
|
|
107
|
+
askAI?: AskAICallbacks;
|
|
108
|
+
}
|
|
109
|
+
export type UserTrackingMode = "fingerprint" | "cookie" | "none";
|
|
110
|
+
//# sourceMappingURL=sdk-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-context.d.ts","sourceRoot":"","sources":["../../../../../../react-sdk/src/types/sdk-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,OAAO;IAGtB;;;OAGG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,kBAAkB,EAAE,OAAO,CAAC;IAE5B;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB,qDAAqD;IACrD,YAAY,EAAE,YAAY,CAAC;IAE3B;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAIxB,sCAAsC;IACtC,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEjC,qCAAqC;IACrC,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAE9B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,CAAC,EAAE,CAAC,CAAC,EAAE,gCAAgC,KAAK,IAAI,CAAC;IAE5E;;;OAGG;IACH,sBAAsB,CAAC,EAAE,CAAC,CAAC,EAAE,2BAA2B,KAAK,IAAI,CAAC;IAElE;;;OAGG;IACH,mBAAmB,CAAC,EAAE,CAAC,CAAC,EAAE,wBAAwB,KAAK,IAAI,CAAC;IAE5D;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACvD;AAED,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,QAAQ,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User identification data that helps with personalization
|
|
3
|
+
* and tracking conversation history
|
|
4
|
+
*/
|
|
5
|
+
export interface UserIdentifiers {
|
|
6
|
+
email?: string;
|
|
7
|
+
unique_client_id?: string;
|
|
8
|
+
fingerprint_id?: string;
|
|
9
|
+
kapa_web_id?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Additional user metadata for analytics/tracking */
|
|
12
|
+
export interface UserMetadata {
|
|
13
|
+
company_name?: string;
|
|
14
|
+
first_name?: string;
|
|
15
|
+
last_name?: string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=user.d.ts.map
|