@squadico/chatbot 1.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/README.md +502 -0
- package/dist/chatbot.global.js +8 -0
- package/dist/chatbot.global.js.map +1 -0
- package/dist/components/Approval.d.ts +37 -0
- package/dist/components/Approval.d.ts.map +1 -0
- package/dist/components/ChatbotWidget.d.ts +19 -0
- package/dist/components/ChatbotWidget.d.ts.map +1 -0
- package/dist/components/Choices.d.ts +27 -0
- package/dist/components/Choices.d.ts.map +1 -0
- package/dist/components/Composer.d.ts +35 -0
- package/dist/components/Composer.d.ts.map +1 -0
- package/dist/components/Confirm.d.ts +16 -0
- package/dist/components/Confirm.d.ts.map +1 -0
- package/dist/components/MessageList.d.ts +32 -0
- package/dist/components/MessageList.d.ts.map +1 -0
- package/dist/components/RichText.d.ts +19 -0
- package/dist/components/RichText.d.ts.map +1 -0
- package/dist/element.d.ts +9 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/jsx.d.ts +57 -0
- package/dist/jsx.d.ts.map +1 -0
- package/dist/lib/client.d.ts +217 -0
- package/dist/lib/client.d.ts.map +1 -0
- package/dist/lib/confirm.d.ts +17 -0
- package/dist/lib/confirm.d.ts.map +1 -0
- package/dist/lib/context.d.ts +40 -0
- package/dist/lib/context.d.ts.map +1 -0
- package/dist/lib/conversation.d.ts +49 -0
- package/dist/lib/conversation.d.ts.map +1 -0
- package/dist/lib/i18n.d.ts +152 -0
- package/dist/lib/i18n.d.ts.map +1 -0
- package/dist/lib/openState.d.ts +26 -0
- package/dist/lib/openState.d.ts.map +1 -0
- package/dist/lib/uid.d.ts +8 -0
- package/dist/lib/uid.d.ts.map +1 -0
- package/dist/lib/useChat.d.ts +71 -0
- package/dist/lib/useChat.d.ts.map +1 -0
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +30 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +70 -0
- package/dist/react.js.map +1 -0
- package/dist/src-CN1vDssu.js +2492 -0
- package/dist/src-CN1vDssu.js.map +1 -0
- package/dist/src-DvRdkFTu.cjs +8 -0
- package/dist/src-DvRdkFTu.cjs.map +1 -0
- package/dist/types.d.ts +301 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decision on a tool call the agent stopped before making: yes, or no.
|
|
3
|
+
*
|
|
4
|
+
* The agent paused before calling the tool and wrote what it would do (that is the
|
|
5
|
+
* message body); these buttons are what releases the call, not a bare "yes"
|
|
6
|
+
* interpreted by the model. Nothing has been written while they are here.
|
|
7
|
+
*
|
|
8
|
+
* **When it wrote nothing, the call speaks for itself.** Several models ask for a
|
|
9
|
+
* tool with no sentence at all, and a visitor then faces an empty bubble with two
|
|
10
|
+
* buttons under it — a decision nobody can take. So `call`, passed only in that
|
|
11
|
+
* case, names what would be used and with what: approving "read a pull request"
|
|
12
|
+
* is not approving *which* one. The values come from a model and are printed as
|
|
13
|
+
* text, never as markup.
|
|
14
|
+
*
|
|
15
|
+
* Two answers and no third. There used to be a "correct it" button that opened an
|
|
16
|
+
* input, and the API has never had anything to send it to — a control that cannot be
|
|
17
|
+
* honoured is worse than one that is missing. Saying something else is a new
|
|
18
|
+
* message, and the backend closes the pending call as it goes out: asking instead of
|
|
19
|
+
* deciding is a decision too.
|
|
20
|
+
*
|
|
21
|
+
* Once the decision is made the group is frozen — the history has to stay readable,
|
|
22
|
+
* and a call is not approved twice.
|
|
23
|
+
*/
|
|
24
|
+
import type { JSX } from 'preact';
|
|
25
|
+
import type { Locale } from '../lib/i18n';
|
|
26
|
+
import type { PendingApproval } from '../types';
|
|
27
|
+
export interface ApprovalProps {
|
|
28
|
+
locale: Locale;
|
|
29
|
+
/** The paused call, when the agent asked for it without a word of its own.
|
|
30
|
+
* Absent when it explained itself: its sentence is the message body, and
|
|
31
|
+
* saying the same thing twice reads as two requests. */
|
|
32
|
+
call?: PendingApproval;
|
|
33
|
+
/** Absent when the group is frozen: decision already made, or turn in flight. */
|
|
34
|
+
onDecide?: (approved: boolean, label: string) => void;
|
|
35
|
+
}
|
|
36
|
+
export declare function Approval({ locale, call, onDecide }: ApprovalProps): JSX.Element;
|
|
37
|
+
//# sourceMappingURL=Approval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Approval.d.ts","sourceRoot":"","sources":["../../src/components/Approval.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAGjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd;;6DAEyD;IACzD,IAAI,CAAC,EAAE,eAAe,CAAA;IACtB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACtD;AA6BD,wBAAgB,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CAmD/E"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { JSX } from 'preact';
|
|
2
|
+
import type { ChatbotEvent, ChatbotOptions } from '../types';
|
|
3
|
+
/** Imperative surface exposed to the wrapper (custom element / React). */
|
|
4
|
+
export interface ChatbotControls {
|
|
5
|
+
open(): void;
|
|
6
|
+
close(): void;
|
|
7
|
+
toggle(): void;
|
|
8
|
+
reset(): void;
|
|
9
|
+
send(text: string): void;
|
|
10
|
+
isOpen(): boolean;
|
|
11
|
+
sessionId(): string;
|
|
12
|
+
}
|
|
13
|
+
export interface ChatbotWidgetProps extends ChatbotOptions {
|
|
14
|
+
onEvent?: (event: ChatbotEvent) => void;
|
|
15
|
+
/** Receives the imperative API on mount, `null` on unmount. */
|
|
16
|
+
bind?: (controls: ChatbotControls | null) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare function ChatbotWidget(props: ChatbotWidgetProps): JSX.Element;
|
|
19
|
+
//# sourceMappingURL=ChatbotWidget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatbotWidget.d.ts","sourceRoot":"","sources":["../../src/components/ChatbotWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAMjC,OAAO,KAAK,EAAkB,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAW5E,0EAA0E;AAC1E,MAAM,WAAW,eAAe;IAC9B,IAAI,IAAI,IAAI,CAAA;IACZ,KAAK,IAAI,IAAI,CAAA;IACb,MAAM,IAAI,IAAI,CAAA;IACd,KAAK,IAAI,IAAI,CAAA;IACb,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,MAAM,IAAI,OAAO,CAAA;IACjB,SAAS,IAAI,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACvC,+DAA+D;IAC/D,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAA;CAClD;AAkED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAgSpE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clickable options built from the Markdown checkboxes (`- [ ] Name`) the
|
|
3
|
+
* assistant writes when it offers candidates.
|
|
4
|
+
*
|
|
5
|
+
* The agent resolves the answer by name, so clicking an option amounts to
|
|
6
|
+
* sending its exact label as a message. The choice is single — the agent expects
|
|
7
|
+
* one candidate per turn — and the group locks as soon as an option is taken, so
|
|
8
|
+
* the history stays readable.
|
|
9
|
+
*/
|
|
10
|
+
import type { ComponentChildren, JSX } from 'preact';
|
|
11
|
+
import type { Locale } from '../lib/i18n';
|
|
12
|
+
export interface ChoiceItem {
|
|
13
|
+
/** Plain text sent to the agent. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** Checkbox already ticked in the Markdown (`- [x] …`). */
|
|
16
|
+
checked: boolean;
|
|
17
|
+
/** Rendered label (inline Markdown is already applied to it). */
|
|
18
|
+
content: ComponentChildren;
|
|
19
|
+
}
|
|
20
|
+
export interface ChoicesProps {
|
|
21
|
+
items: ChoiceItem[];
|
|
22
|
+
locale: Locale;
|
|
23
|
+
/** Absent when the group is frozen: older message, or turn in flight. */
|
|
24
|
+
onPick?: (label: string) => void;
|
|
25
|
+
}
|
|
26
|
+
export declare function Choices({ items, locale, onPick }: ChoicesProps): JSX.Element;
|
|
27
|
+
//# sourceMappingURL=Choices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Choices.d.ts","sourceRoot":"","sources":["../../src/components/Choices.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAEpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,WAAW,UAAU;IACzB,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAA;IACb,2DAA2D;IAC3D,OAAO,EAAE,OAAO,CAAA;IAChB,iEAAiE;IACjE,OAAO,EAAE,iBAAiB,CAAA;CAC3B;AAUD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,yEAAyE;IACzE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACjC;AAED,wBAAgB,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,YAAY,GAAG,GAAG,CAAC,OAAO,CA+B5E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { JSX } from 'preact';
|
|
2
|
+
import type { Locale } from '../lib/i18n';
|
|
3
|
+
import type { AgentHandle, ChatAttachment } from '../types';
|
|
4
|
+
export interface ComposerProps {
|
|
5
|
+
placeholder: string;
|
|
6
|
+
locale: Locale;
|
|
7
|
+
busy: boolean;
|
|
8
|
+
/** Focuses the field when the sidebar opens. */
|
|
9
|
+
autoFocus: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The handles this application offers, as the open response returned them.
|
|
12
|
+
*
|
|
13
|
+
* Empty is the ordinary case — a deployment is unlisted until somebody ticks it —
|
|
14
|
+
* and it ships no affordance at all: an empty popup is worse than no popup, and
|
|
15
|
+
* the default agent answers plain text anyway.
|
|
16
|
+
*/
|
|
17
|
+
handles?: AgentHandle[];
|
|
18
|
+
/** The handle the conversation opened on, written into the field once so the
|
|
19
|
+
* visitor can see who is being addressed — and delete it. */
|
|
20
|
+
addressee?: string;
|
|
21
|
+
/** The files already accepted for this question. */
|
|
22
|
+
attachments?: ChatAttachment[];
|
|
23
|
+
/** The names of the ones still on their way up, so a slow upload is visible. */
|
|
24
|
+
uploading?: string[];
|
|
25
|
+
/** Why the last upload was refused, in the visitor's own language. */
|
|
26
|
+
attachmentError?: string;
|
|
27
|
+
/** Absent where a conversation cannot take files — which is also what hides
|
|
28
|
+
* the paperclip rather than showing one that refuses. */
|
|
29
|
+
onAttach?: (file: File) => void;
|
|
30
|
+
onDetach?: (attachmentId: string) => void;
|
|
31
|
+
onSend: (text: string) => void;
|
|
32
|
+
onStop: () => void;
|
|
33
|
+
}
|
|
34
|
+
export declare function Composer({ placeholder, locale, busy, autoFocus, handles, addressee, attachments, uploading, attachmentError, onAttach, onDetach, onSend, onStop, }: ComposerProps): JSX.Element;
|
|
35
|
+
//# sourceMappingURL=Composer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Composer.d.ts","sourceRoot":"","sources":["../../src/components/Composer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAGjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAuC3D,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,OAAO,CAAA;IACb,gDAAgD;IAChD,SAAS,EAAE,OAAO,CAAA;IAClB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;IACvB;kEAC8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oDAAoD;IACpD,WAAW,CAAC,EAAE,cAAc,EAAE,CAAA;IAC9B,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,sEAAsE;IACtE,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;8DAC0D;IAC1D,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IAC/B,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED,wBAAgB,QAAQ,CAAC,EACvB,WAAW,EACX,MAAM,EACN,IAAI,EACJ,SAAS,EACT,OAAO,EACP,SAAS,EACT,WAAgB,EAChB,SAAc,EACd,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,GACP,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CA+T7B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Yes" / "No" buttons under a closed question from the assistant.
|
|
3
|
+
*
|
|
4
|
+
* A bare "yes" or "no" is recognised agent-side without going through the LLM,
|
|
5
|
+
* so clicking is exactly the same as typing the answer. As with the tickable
|
|
6
|
+
* options, the group locks on the choice made, so the history stays readable.
|
|
7
|
+
*/
|
|
8
|
+
import type { JSX } from 'preact';
|
|
9
|
+
import type { Locale } from '../lib/i18n';
|
|
10
|
+
export interface ConfirmProps {
|
|
11
|
+
locale: Locale;
|
|
12
|
+
/** Absent when the group is frozen: older message, or turn in flight. */
|
|
13
|
+
onPick?: (answer: string) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare function Confirm({ locale, onPick }: ConfirmProps): JSX.Element;
|
|
16
|
+
//# sourceMappingURL=Confirm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Confirm.d.ts","sourceRoot":"","sources":["../../src/components/Confirm.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAEjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,yEAAyE;IACzE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;CAClC;AAED,wBAAgB,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,YAAY,GAAG,GAAG,CAAC,OAAO,CA8BrE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { JSX } from 'preact';
|
|
2
|
+
import type { Locale } from '../lib/i18n';
|
|
3
|
+
import type { ChatMessage } from '../types';
|
|
4
|
+
/** Reads one file's bytes, as a URL this component owns and revokes. */
|
|
5
|
+
export type AttachmentLoader = (attachmentId: string) => Promise<Blob>;
|
|
6
|
+
/** Lucide `message-circle`: the launcher, the panel title and every answer
|
|
7
|
+
* coming from the assistant. */
|
|
8
|
+
export declare function ChatIcon(): JSX.Element;
|
|
9
|
+
export interface MessageListProps {
|
|
10
|
+
messages: ChatMessage[];
|
|
11
|
+
locale: Locale;
|
|
12
|
+
/** Name displayed above each answer. */
|
|
13
|
+
assistantName: string;
|
|
14
|
+
suggestions?: string[];
|
|
15
|
+
/** Suggestions are only shown on the first turn, as long as the user has
|
|
16
|
+
* written nothing. */
|
|
17
|
+
showSuggestions: boolean;
|
|
18
|
+
/** A turn is in flight: the last message's options are disabled. */
|
|
19
|
+
busy?: boolean;
|
|
20
|
+
/** A human of the organization handles the conversation: said under the
|
|
21
|
+
* transcript, since no agent will answer what comes next. */
|
|
22
|
+
withHuman?: boolean;
|
|
23
|
+
onSuggestion: (text: string) => void;
|
|
24
|
+
/** Sends the label of a ticked option as the turn's answer. */
|
|
25
|
+
onChoice: (label: string) => void;
|
|
26
|
+
/** Decides the tool call the last message put on hold. */
|
|
27
|
+
onDecide: (approved: boolean, label: string) => void;
|
|
28
|
+
/** Reads the bytes of a file a turn carried. Absent where nothing can. */
|
|
29
|
+
onLoadAttachment?: AttachmentLoader;
|
|
30
|
+
}
|
|
31
|
+
export declare function MessageList({ messages, locale, assistantName, suggestions, showSuggestions, busy, withHuman, onSuggestion, onChoice, onDecide, onLoadAttachment, }: MessageListProps): JSX.Element;
|
|
32
|
+
//# sourceMappingURL=MessageList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../src/components/MessageList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAGjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,UAAU,CAAA;AAmB3D,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,GAAG,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAkLtE;iCACiC;AACjC,wBAAgB,QAAQ,IAAI,GAAG,CAAC,OAAO,CActC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB;2BACuB;IACvB,eAAe,EAAE,OAAO,CAAA;IACxB,oEAAoE;IACpE,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;kEAC8D;IAC9D,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,+DAA+D;IAC/D,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,0DAA0D;IAC1D,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACpD,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AAED,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,MAAM,EACN,aAAa,EACb,WAAW,EACX,eAAe,EACf,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,gBAAgB,GACjB,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAoEhC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Markdown rendering of the agent's answers.
|
|
3
|
+
*
|
|
4
|
+
* The agent answers with a stable subset of Markdown: headings, lists
|
|
5
|
+
* (sometimes nested), tables (record listings), identifiers in backticks, links.
|
|
6
|
+
* That subset is covered and nothing more: no Markdown library (weight), and
|
|
7
|
+
* above all **never** any injected HTML — everything is produced as Preact
|
|
8
|
+
* nodes, hence escaped by construction.
|
|
9
|
+
*/
|
|
10
|
+
import type { JSX } from 'preact';
|
|
11
|
+
import type { Locale } from '../lib/i18n';
|
|
12
|
+
export interface RichTextProps {
|
|
13
|
+
text: string;
|
|
14
|
+
locale: Locale;
|
|
15
|
+
/** Makes the checkboxes clickable; absent, they stay displayed but frozen. */
|
|
16
|
+
onChoice?: (label: string) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare function RichText({ text, locale, onChoice }: RichTextProps): JSX.Element;
|
|
19
|
+
//# sourceMappingURL=RichText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichText.d.ts","sourceRoot":"","sources":["../../src/components/RichText.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AA+IzC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACnC;AAED,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CAyL/E"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const TAG_NAME = "squadico-chatbot";
|
|
2
|
+
/**
|
|
3
|
+
* Registers `<squadico-chatbot>`. Idempotent, and a no-op server-side.
|
|
4
|
+
*
|
|
5
|
+
* @param tag alternative tag name, when `squadico-chatbot` is already taken by
|
|
6
|
+
* another version of the widget on the page.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defineChatbot(tag?: string): void;
|
|
9
|
+
//# sourceMappingURL=element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.tsx"],"names":[],"mappings":"AAYA,eAAO,MAAM,QAAQ,qBAAqB,CAAA;AAsU1C;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,GAAE,MAAiB,GAAG,IAAI,CAM1D"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./src-DvRdkFTu.cjs");exports.API_URL=e.r,exports.ChatHttpError=e.i,exports.DEFAULT_LANGUAGE=e.s,exports.MAX_MESSAGE_LENGTH=e.a,exports.SUPPORTED_LANGUAGES=e.c,exports.TAG_NAME=e.t,exports.defineChatbot=e.n;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default entry point of `@squadico/chatbot`.
|
|
3
|
+
*
|
|
4
|
+
* Importing it registers `<squadico-chatbot>` in the browser (a deliberate side
|
|
5
|
+
* effect, declared through `sideEffects` in `package.json`) and does nothing
|
|
6
|
+
* server-side, which makes it safe to import from a Next.js or Nuxt component.
|
|
7
|
+
*
|
|
8
|
+
* import '@squadico/chatbot'
|
|
9
|
+
* <squadico-chatbot embed-key="sq_pub_…" />
|
|
10
|
+
*/
|
|
11
|
+
export { defineChatbot, TAG_NAME } from './element';
|
|
12
|
+
export { DEFAULT_LANGUAGE, SUPPORTED_LANGUAGES, type LanguageCode } from './lib/i18n';
|
|
13
|
+
export { API_URL, ChatHttpError, MAX_MESSAGE_LENGTH } from './lib/client';
|
|
14
|
+
export type { AgentHandle, ApprovalDecision, ChatbotContext, ChatbotEvent, ChatbotEventMap, ChatbotEventName, ChatbotOptions, ChatbotTheme, ChatMessage, ChatRole, ContextObject, ContextValue, HostUser, LauncherPosition, PendingApproval, SquadicoChatbotElement, } from './types';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACzE,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,sBAAsB,GACvB,MAAM,SAAS,CAAA"}
|
package/dist/index.js
ADDED
package/dist/jsx.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional JSX declarations for React hosts writing the tag directly, without
|
|
3
|
+
* going through the `@squadico/chatbot/react` wrapper:
|
|
4
|
+
*
|
|
5
|
+
* /// <reference types="@squadico/chatbot/jsx" />
|
|
6
|
+
* <squadico-chatbot context='{"orderId":"ORD-1"}' />
|
|
7
|
+
*
|
|
8
|
+
* Deliberately isolated: it is not imported by the main entry point, so the
|
|
9
|
+
* `react` module augmentation does not leak into Vue or HTML hosts.
|
|
10
|
+
*/
|
|
11
|
+
import type { ReactNode } from 'react';
|
|
12
|
+
/** Attributes recognised by `<squadico-chatbot>`. All of them are strings —
|
|
13
|
+
* that is what an HTML attribute is. Object values (`context`, `user`) can be
|
|
14
|
+
* written as JSON here, or set as properties through a `ref`. */
|
|
15
|
+
export interface SquadicoChatbotAttributes {
|
|
16
|
+
/** Public key of the Squadico application this page embeds. Required: it is
|
|
17
|
+
* what says which application to open a conversation on. */
|
|
18
|
+
'embed-key'?: string;
|
|
19
|
+
/** Serialised JSON object — e.g. `'{"order":{"id":"ORD-1","name":"Order #1042"}}'`. */
|
|
20
|
+
context?: string;
|
|
21
|
+
/** Who the page has signed in, as JSON: `'{"id":"42","name":"Ada"}'`. A label
|
|
22
|
+
* for the transcript, never an authorization. */
|
|
23
|
+
user?: string;
|
|
24
|
+
heading?: string;
|
|
25
|
+
subheading?: string;
|
|
26
|
+
/** Name the assistant signs its answers with. */
|
|
27
|
+
'assistant-name'?: string;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
greeting?: string;
|
|
30
|
+
/** JSON array (`'["a","b"]'`) or a `|`-separated list. */
|
|
31
|
+
suggestions?: string;
|
|
32
|
+
width?: string;
|
|
33
|
+
accent?: string;
|
|
34
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
35
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
36
|
+
/** Presence = open. `open="false"` closes it. */
|
|
37
|
+
open?: string | boolean;
|
|
38
|
+
/** `persist-open="false"`: the panel starts from `open` on every mount. */
|
|
39
|
+
'persist-open'?: string | boolean;
|
|
40
|
+
locale?: string;
|
|
41
|
+
class?: string;
|
|
42
|
+
id?: string;
|
|
43
|
+
style?: Record<string, string | number>;
|
|
44
|
+
ref?: unknown;
|
|
45
|
+
/** Icon of the floating button: `<svg slot="launcher-icon" />`. The only
|
|
46
|
+
* child the widget renders — a child without a `slot` is not projected, and
|
|
47
|
+
* therefore not displayed. */
|
|
48
|
+
children?: ReactNode;
|
|
49
|
+
}
|
|
50
|
+
declare module 'react' {
|
|
51
|
+
namespace JSX {
|
|
52
|
+
interface IntrinsicElements {
|
|
53
|
+
'squadico-chatbot': SquadicoChatbotAttributes;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=jsx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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iB;YACzB,kBAAkB,EAAE,yBAAyB,CAAA;SAC9C;KACF;CACF"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client of the Squadico public API.
|
|
3
|
+
*
|
|
4
|
+
* Four calls, and they are the routes the backend actually serves:
|
|
5
|
+
* - `openConversation` → `POST /public/applications/{embedKey}/conversations`
|
|
6
|
+
* - `replayConversation` → `GET /public/conversations/{id}`
|
|
7
|
+
* - `sendMessage` → `POST /public/conversations/{id}/messages` (SSE)
|
|
8
|
+
* - `resolveApproval` → `POST /public/conversations/{id}/approvals` (SSE)
|
|
9
|
+
*
|
|
10
|
+
* **The widget authenticates nobody.** It is the public surface: the embed key says
|
|
11
|
+
* which application, and the visitor token handed back at open is the whole of the
|
|
12
|
+
* authorization afterwards. The token travels in a header and never in a cookie —
|
|
13
|
+
* third-party cookies are blocked or on their way out, and a header cannot be sent
|
|
14
|
+
* ambiently, which removes CSRF as a class.
|
|
15
|
+
*
|
|
16
|
+
* **The server names the conversation.** Its id comes back from the open call: a
|
|
17
|
+
* visitor allowed to name their own conversation is a visitor choosing which one to
|
|
18
|
+
* read.
|
|
19
|
+
*
|
|
20
|
+
* **The author claim travels once, at open.** A panel has one person in front of it,
|
|
21
|
+
* so one claim per conversation is auditable while one per message would be an
|
|
22
|
+
* annotation anybody could change halfway through. It is attribution and never
|
|
23
|
+
* authorization: what a visitor may read is decided by their token.
|
|
24
|
+
*
|
|
25
|
+
* **Everything is streamed the same way.** Four frame types — `token`, `done`,
|
|
26
|
+
* `error`, `approval_required` — for a fresh question and for a resumed approval
|
|
27
|
+
* alike, plus three a team adds: `handoff` (another agent of the team answers
|
|
28
|
+
* from here, and signs the `done` that follows), `escalated` (the agent handed the
|
|
29
|
+
* conversation to a human) and `held` (a human handles it: the message was kept
|
|
30
|
+
* for them and nothing answers). `done` carries the stored turn (the one a reload would show), on a surface
|
|
31
|
+
* that can hold several agents which one answered, and — when the message addressed
|
|
32
|
+
* a name nobody answers to — that name with the ones that do. That last one is a
|
|
33
|
+
* hint beside an answer and never a refusal: the default agent replied, because a
|
|
34
|
+
* visitor typing `@sale` should get help rather than a 404.
|
|
35
|
+
*
|
|
36
|
+
* **A handle is never routed from here.** The message text is what the server
|
|
37
|
+
* parses, so the picker and the `agent` option both work by putting a handle in
|
|
38
|
+
* front of what somebody types. A client naming its own agent would be a client
|
|
39
|
+
* choosing its own router.
|
|
40
|
+
*
|
|
41
|
+
* No dependency: `fetch` + `ReadableStream`, available everywhere the widget runs.
|
|
42
|
+
*/
|
|
43
|
+
import type { AgentHandle, ChatAttachment, ChatMessage, PendingApproval } from '../types';
|
|
44
|
+
/** The Squadico API, written in at build time (`config/api-url.ts`). Not an
|
|
45
|
+
* option: a page embedding the widget does not choose the server it talks to. */
|
|
46
|
+
export declare const API_URL: string;
|
|
47
|
+
/** Aligned on `MESSAGE_MAX_LENGTH` in the API's own schema: a message longer than
|
|
48
|
+
* this is a 422 from the form rather than a 400 from a vendor at the first token. */
|
|
49
|
+
export declare const MAX_MESSAGE_LENGTH = 20000;
|
|
50
|
+
export declare class ChatHttpError extends Error {
|
|
51
|
+
readonly status?: number;
|
|
52
|
+
/** The API's machine-readable name for the refusal, when it sent one.
|
|
53
|
+
*
|
|
54
|
+
* What a panel branches on: `origin_not_allowed` means stop embedding,
|
|
55
|
+
* `application_has_no_agent` means nothing answers there yet, and
|
|
56
|
+
* `conversation_retired` means open a new conversation. Three reactions a bare
|
|
57
|
+
* status cannot tell apart. */
|
|
58
|
+
readonly code?: string;
|
|
59
|
+
constructor(message: string, status?: number, code?: string);
|
|
60
|
+
}
|
|
61
|
+
export interface HostUser {
|
|
62
|
+
id: string;
|
|
63
|
+
name?: string;
|
|
64
|
+
/** The HMAC the host's *server* computed over `id`, where the application asks
|
|
65
|
+
* for one. Never computed in the page: a digest a browser can produce is a
|
|
66
|
+
* digest anybody can produce, and the secret would be in the page's source. */
|
|
67
|
+
digest?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface OpenConversationInit {
|
|
70
|
+
apiUrl: string;
|
|
71
|
+
embedKey: string;
|
|
72
|
+
/** Who the embedding application has signed in, when it has anybody. */
|
|
73
|
+
user?: HostUser;
|
|
74
|
+
/** The handle the page wants to open on. Unknown here opens on the default rather
|
|
75
|
+
* than refusing: a page carrying a renamed handle must keep working. */
|
|
76
|
+
agent?: string;
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
}
|
|
79
|
+
/** What opening a panel answers with. */
|
|
80
|
+
export interface OpenedConversation {
|
|
81
|
+
conversationId: string;
|
|
82
|
+
visitorToken: string;
|
|
83
|
+
/** The agent that answers a message addressing nobody. */
|
|
84
|
+
agentName: string;
|
|
85
|
+
agentSlug: string;
|
|
86
|
+
welcomeMessage?: string;
|
|
87
|
+
/** The transcript as it stands — the welcome message, on a fresh conversation. */
|
|
88
|
+
messages: ChatMessage[];
|
|
89
|
+
/** The handles this application offers, which is empty until somebody ticks one. */
|
|
90
|
+
handles: AgentHandle[];
|
|
91
|
+
/** The handle the conversation really opened on — which may not be the one that
|
|
92
|
+
* was asked for, if the server fell back to the default. */
|
|
93
|
+
agentHandle?: string;
|
|
94
|
+
/** A human of the organization handles it: no agent answers, and the panel
|
|
95
|
+
* reads the conversation again to show their replies. */
|
|
96
|
+
withHuman?: boolean;
|
|
97
|
+
}
|
|
98
|
+
export interface ReplayConversationInit {
|
|
99
|
+
apiUrl: string;
|
|
100
|
+
conversationId: string;
|
|
101
|
+
visitorToken: string;
|
|
102
|
+
signal?: AbortSignal;
|
|
103
|
+
}
|
|
104
|
+
export interface SendMessageInit {
|
|
105
|
+
apiUrl: string;
|
|
106
|
+
conversationId: string;
|
|
107
|
+
visitorToken: string;
|
|
108
|
+
message: string;
|
|
109
|
+
/** The files this question carries, named rather than implied: anything else
|
|
110
|
+
* the conversation is still holding stays where it is. */
|
|
111
|
+
attachmentIds?: string[];
|
|
112
|
+
/** What the page knows about where the visitor is. Sent as data, never as
|
|
113
|
+
* instructions — see `ChatbotContext`. */
|
|
114
|
+
context?: Record<string, unknown>;
|
|
115
|
+
onToken: (token: string) => void;
|
|
116
|
+
signal?: AbortSignal;
|
|
117
|
+
}
|
|
118
|
+
export interface ResolveApprovalInit {
|
|
119
|
+
apiUrl: string;
|
|
120
|
+
conversationId: string;
|
|
121
|
+
visitorToken: string;
|
|
122
|
+
/** The call the panel is answering for. Checked against what the conversation is
|
|
123
|
+
* actually waiting on, so a stale decision is refused rather than resuming the
|
|
124
|
+
* wrong thing. */
|
|
125
|
+
toolCallId: string;
|
|
126
|
+
approved: boolean;
|
|
127
|
+
onToken: (token: string) => void;
|
|
128
|
+
signal?: AbortSignal;
|
|
129
|
+
}
|
|
130
|
+
/** What a turn produced: the stored answer, who wrote it, and what it stopped on. */
|
|
131
|
+
export interface ChatTurn {
|
|
132
|
+
answer: string;
|
|
133
|
+
/** Which agent answered, on a surface that can hold several. */
|
|
134
|
+
agent?: AgentHandle;
|
|
135
|
+
/** Set when the turn paused: one tool call is waiting on a decision, and nothing
|
|
136
|
+
* has been written until one is sent. */
|
|
137
|
+
approval?: PendingApproval;
|
|
138
|
+
/** The name the message addressed and nobody on this application answers to. The
|
|
139
|
+
* answer came from the default agent all the same. */
|
|
140
|
+
unknownHandle?: string;
|
|
141
|
+
/** The handles that *do* answer, to say instead of the mistyped one. Empty when
|
|
142
|
+
* the organization has ticked none — the panel then says only that nobody
|
|
143
|
+
* answers to that name. */
|
|
144
|
+
offered?: AgentHandle[];
|
|
145
|
+
/** The agent the conversation was passed to during this turn, when it has no
|
|
146
|
+
* handle on the application to be announced by — what signs its answer. */
|
|
147
|
+
authorName?: string;
|
|
148
|
+
/** The agent handed the conversation to a human of the organization, or one
|
|
149
|
+
* already handles it: no agent answers what comes next. */
|
|
150
|
+
withHuman?: boolean;
|
|
151
|
+
/** The message was kept for the human handling the conversation; no agent ran,
|
|
152
|
+
* so there is no answer to draw. */
|
|
153
|
+
held?: boolean;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Opens a conversation for a page carrying this application's embed key.
|
|
157
|
+
*
|
|
158
|
+
* The body carries the host's author claim and nothing else. No bearer token: the
|
|
159
|
+
* widget is the public surface, and the key plus the visitor token it gets back are
|
|
160
|
+
* the whole credential story.
|
|
161
|
+
*/
|
|
162
|
+
export declare function openConversation(init: OpenConversationInit): Promise<OpenedConversation>;
|
|
163
|
+
/**
|
|
164
|
+
* Reads a conversation back, on the token it was opened with.
|
|
165
|
+
*
|
|
166
|
+
* What makes a reloaded page keep its conversation instead of opening a second one.
|
|
167
|
+
* The answer is the open response minus the credential — the transcript, the handles
|
|
168
|
+
* the composer offers, and the handle the conversation is on — because the token is
|
|
169
|
+
* handed over once and the caller already holds it.
|
|
170
|
+
*/
|
|
171
|
+
export declare function replayConversation(init: ReplayConversationInit): Promise<OpenedConversation>;
|
|
172
|
+
export interface AttachmentInit {
|
|
173
|
+
apiUrl: string;
|
|
174
|
+
conversationId: string;
|
|
175
|
+
visitorToken: string;
|
|
176
|
+
signal?: AbortSignal;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Puts one file on the conversation, before the question that will carry it.
|
|
180
|
+
*
|
|
181
|
+
* Uploaded as it is picked rather than held until the message is sent: a format
|
|
182
|
+
* the product does not take is refused here, in front of somebody who has not
|
|
183
|
+
* written their question yet.
|
|
184
|
+
*
|
|
185
|
+
* What comes back is what was *accepted* — the kind and the type read off the
|
|
186
|
+
* bytes on the server. The panel never decides what a file is.
|
|
187
|
+
*/
|
|
188
|
+
export declare function uploadAttachment(init: AttachmentInit & {
|
|
189
|
+
file: File;
|
|
190
|
+
}): Promise<ChatAttachment>;
|
|
191
|
+
/** Takes a file back out of the conversation, bytes and all. */
|
|
192
|
+
export declare function deleteAttachment(init: AttachmentInit & {
|
|
193
|
+
attachmentId: string;
|
|
194
|
+
}): Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* The bytes of one file, as something a browser can draw.
|
|
197
|
+
*
|
|
198
|
+
* Fetched rather than linked, and this is the whole reason attachments carry no
|
|
199
|
+
* URL: the route is opened by the visitor token, which travels in a header, and
|
|
200
|
+
* a header is exactly what an `<img src>` cannot send. So the panel reads the
|
|
201
|
+
* file itself and hands the caller an object URL — which the caller owns, and
|
|
202
|
+
* has to revoke.
|
|
203
|
+
*/
|
|
204
|
+
export declare function fetchAttachment(init: AttachmentInit & {
|
|
205
|
+
attachmentId: string;
|
|
206
|
+
}): Promise<Blob>;
|
|
207
|
+
/** Sends one message, and streams the answer as it is written. */
|
|
208
|
+
export declare function sendMessage(init: SendMessageInit): Promise<ChatTurn>;
|
|
209
|
+
/**
|
|
210
|
+
* Answers the tool call a turn paused on, and lets the turn carry on.
|
|
211
|
+
*
|
|
212
|
+
* Streamed like a message, because it *is* the same turn continuing: the tokens the
|
|
213
|
+
* agent writes after the call, then the stored answer — or another pause, if it asks
|
|
214
|
+
* for a second tool needing a decision.
|
|
215
|
+
*/
|
|
216
|
+
export declare function resolveApproval(init: ResolveApprovalInit): Promise<ChatTurn>;
|
|
217
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lib/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,WAAW,EAEX,eAAe,EAChB,MAAM,UAAU,CAAA;AAGjB;kFACkF;AAClF,eAAO,MAAM,OAAO,EAAE,MAA6B,CAAA;AAEnD;sFACsF;AACtF,eAAO,MAAM,kBAAkB,QAAS,CAAA;AAExC,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;oCAKgC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI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AED;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,cAAc,GAAG;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACpC,OAAO,CAAC,cAAc,CAAC,CAezB;AAED,gEAAgE;AAChE,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,cAAc,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GAC9C,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,cAAc,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GAC9C,OAAO,CAAC,IAAI,CAAC,CAOf;AASD,kEAAkE;AAClE,wBAAsB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAc1E;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAMlF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detection of the assistant's closed questions, so "Yes" / "No" can be offered
|
|
3
|
+
* instead of making the user retype the answer.
|
|
4
|
+
*
|
|
5
|
+
* The protocol exposes nothing explicit for this (the API only returns text), so
|
|
6
|
+
* this leans on the phrasings agents actually produce. The list is deliberately
|
|
7
|
+
* narrow: an open question ("Which records would you like to see?") must not
|
|
8
|
+
* bring up buttons.
|
|
9
|
+
*
|
|
10
|
+
* A question asked in the user's language is only recognisable with that
|
|
11
|
+
* language's phrasings: the patterns are therefore keyed by language, and the
|
|
12
|
+
* widget's locale picks the set — a single English set would leave a
|
|
13
|
+
* French-speaking host without buttons.
|
|
14
|
+
*/
|
|
15
|
+
import { type LanguageCode } from './i18n';
|
|
16
|
+
export declare function isConfirmationPrompt(text: string, language?: LanguageCode): boolean;
|
|
17
|
+
//# sourceMappingURL=confirm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm.d.ts","sourceRoot":"","sources":["../../src/lib/confirm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAA;AAuC5D,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,YAA+B,GACxC,OAAO,CAcT"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page context: reading an `{ id, name }` entry and shaping it for the wire.
|
|
3
|
+
*
|
|
4
|
+
* A host object can be named in two ways. Its id alone, under a flat key
|
|
5
|
+
* (`orderId: 'ORD-1'`), or the named object under the entity key
|
|
6
|
+
* (`order: { id: 'ORD-1', name: 'Order #1042' }`). The second form exists for
|
|
7
|
+
* display: the chip shows "Order #1042" instead of a UUID, and the host is the
|
|
8
|
+
* only one knowing that name without calling the API.
|
|
9
|
+
*
|
|
10
|
+
* On the wire the agent only reads strings, so `wireContext` splits every named
|
|
11
|
+
* object into `<key>Id` + `<key>Name` right before sending. Keeping a single
|
|
12
|
+
* shape on the network makes the request identical however the host filled its
|
|
13
|
+
* context in.
|
|
14
|
+
*
|
|
15
|
+
* Nothing here is domain-specific: the widget has no list of known entities, it
|
|
16
|
+
* only recognises the `{ id, name }` shape wherever the host used it.
|
|
17
|
+
*/
|
|
18
|
+
import type { ChatbotContext, ContextObject } from '../types';
|
|
19
|
+
/**
|
|
20
|
+
* Reads a context entry, named object or bare id.
|
|
21
|
+
*
|
|
22
|
+
* Returns `undefined` when it carries no usable id — empty string, object with
|
|
23
|
+
* no `id`: "nothing selected", not "something named nowhere".
|
|
24
|
+
*/
|
|
25
|
+
export declare function contextObject(value: unknown): ContextObject | undefined;
|
|
26
|
+
/** What a chip displays: the name when the host gave one, the id otherwise. */
|
|
27
|
+
export declare function contextLabel(value: unknown): string | undefined;
|
|
28
|
+
/** Whether an entry carries a named object (`{ id, name? }`) rather than a
|
|
29
|
+
* plain value — the shape the chips and the wire format are built on. */
|
|
30
|
+
export declare function isNamedObject(value: unknown): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Puts the context in the shape the agent reads: `order: { id, name }` becomes
|
|
33
|
+
* `orderId` + `orderName`.
|
|
34
|
+
*
|
|
35
|
+
* Everything else goes through untouched — `sessionId`, an already flat
|
|
36
|
+
* `orderId`, or any free key of the host: the widget does not filter the
|
|
37
|
+
* context, it only translates what it knows how to translate.
|
|
38
|
+
*/
|
|
39
|
+
export declare function wireContext(context: ChatbotContext): Record<string, unknown>;
|
|
40
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/lib/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAK7D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAQvE;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAI/D;AAED;0EAC0E;AAC1E,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAErD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAc5E"}
|