@lambforge/agent-chat 0.0.0-stage → 0.0.2
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 +81 -2
- package/dist/agent-chat.js +280 -0
- package/dist/agent-chat.js.map +7 -0
- package/dist/auto.d.ts +1 -0
- package/dist/element.d.ts +142 -0
- package/dist/index.cjs +4122 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +4136 -0
- package/dist/index.mjs.map +7 -0
- package/dist/markdown.d.ts +3 -0
- package/dist/store/chat-actions.d.ts +121 -0
- package/dist/store/chat-effects.d.ts +44 -0
- package/dist/store/chat-reducer.d.ts +2 -0
- package/dist/store/chat-state.d.ts +31 -0
- package/dist/store/chat-store.d.ts +18 -0
- package/dist/store/index.d.ts +5 -0
- package/dist/strings.d.ts +20 -0
- package/dist/styles.d.ts +2 -0
- package/dist/turnstile.d.ts +12 -0
- package/package.json +55 -4
package/dist/auto.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { AgentClient, SessionToken } from '@lambforge/agents';
|
|
2
|
+
import { LitElement } from '@rxdi/lit-html';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { ChatAction, ChatState, Notice } from './store';
|
|
5
|
+
import { ChatStrings } from './strings';
|
|
6
|
+
export declare const TAG = "lambforge-agent-chat";
|
|
7
|
+
/** An action that needs things from the render (`Reader` of @rhtml/di). */
|
|
8
|
+
export type Reader<T extends unknown[], R> = (deps: T) => R;
|
|
9
|
+
/**
|
|
10
|
+
* A visitor chat with a Lambforge agent (plan 51): a launcher + panel
|
|
11
|
+
* (drawer), a block in the page (inline) or the whole screen.
|
|
12
|
+
*
|
|
13
|
+
* Style A (`@rhtml/component`) over its own `@rxdi/redux-store` store
|
|
14
|
+
* (store/): `State` is the store's state, the view only renders it and
|
|
15
|
+
* dispatches; requests live in ChatEffects. The store is created when
|
|
16
|
+
* `State` starts and destroyed with the element.
|
|
17
|
+
*
|
|
18
|
+
* Give it ONE session source: `publishable-key` (anonymous visitors),
|
|
19
|
+
* `token-url`, `.getToken` or `.client`.
|
|
20
|
+
*
|
|
21
|
+
* @customElement lambforge-agent-chat
|
|
22
|
+
*
|
|
23
|
+
* @attr {string} publishable-key - `lfp_...` key: anonymous visitors (Turnstile bot check)
|
|
24
|
+
* @attr {string} token-url - your endpoint answering `{ token, expiresAt }` (signed-in visitors)
|
|
25
|
+
* @attr {string} agent - the agent to start with (id or name)
|
|
26
|
+
* @attr {string} agents - only these agents, comma list of ids or names (a picker when more than one)
|
|
27
|
+
* @attr {'drawer'|'inline'|'fullscreen'} mode - default `drawer`
|
|
28
|
+
* @attr {'bottom-right'|'bottom-left'} position - where the drawer's launcher sits
|
|
29
|
+
* @attr {boolean} open - the drawer is open
|
|
30
|
+
* @attr {'light'|'dark'} theme
|
|
31
|
+
* @attr {string} locale - `en`, `bg` (default: the page's `lang`)
|
|
32
|
+
* @attr {string} title - the header (default: the agent's name)
|
|
33
|
+
* @attr {string} url - the API (default `https://api.lambforge.com`)
|
|
34
|
+
* @attr {string} turnstile-sitekey - your own Turnstile widget instead of the hosted one
|
|
35
|
+
* @attr {string} turnstile-url - the hosted bot check page
|
|
36
|
+
*
|
|
37
|
+
* @prop {AgentClient} client - an AgentClient you built yourself (wins over the attributes)
|
|
38
|
+
* @prop {() => Promise<SessionToken | string>} getToken - your token source
|
|
39
|
+
* @prop {Partial<ChatStrings>} strings - override any text
|
|
40
|
+
*
|
|
41
|
+
* @fires open-change - `{ open }` the drawer opened or closed
|
|
42
|
+
* @fires answer - `{ text, agent, conversationId }` an answer arrived
|
|
43
|
+
* @fires error - `{ code }` something failed (`cap-reached`, `limit-reached`, ...)
|
|
44
|
+
*
|
|
45
|
+
* @slot launcher - the drawer button's content (default: a chat icon)
|
|
46
|
+
*
|
|
47
|
+
* @csspart launcher
|
|
48
|
+
* @csspart panel
|
|
49
|
+
* @csspart header
|
|
50
|
+
* @csspart picker
|
|
51
|
+
* @csspart new
|
|
52
|
+
* @csspart close
|
|
53
|
+
* @csspart messages
|
|
54
|
+
* @csspart message - every bubble (also `user` / `assistant`)
|
|
55
|
+
* @csspart suggestion
|
|
56
|
+
* @csspart status
|
|
57
|
+
* @csspart composer
|
|
58
|
+
* @csspart input
|
|
59
|
+
* @csspart send
|
|
60
|
+
*
|
|
61
|
+
* @cssprop --lf-chat-accent - buttons, the visitor's bubbles (#4f46e5)
|
|
62
|
+
* @cssprop --lf-chat-accent-fg
|
|
63
|
+
* @cssprop --lf-chat-bg
|
|
64
|
+
* @cssprop --lf-chat-fg
|
|
65
|
+
* @cssprop --lf-chat-muted
|
|
66
|
+
* @cssprop --lf-chat-border
|
|
67
|
+
* @cssprop --lf-chat-bot-bg
|
|
68
|
+
* @cssprop --lf-chat-bot-fg
|
|
69
|
+
* @cssprop --lf-chat-user-bg
|
|
70
|
+
* @cssprop --lf-chat-user-fg
|
|
71
|
+
* @cssprop --lf-chat-error
|
|
72
|
+
* @cssprop --lf-chat-radius
|
|
73
|
+
* @cssprop --lf-chat-font
|
|
74
|
+
* @cssprop --lf-chat-width - drawer width (380px)
|
|
75
|
+
* @cssprop --lf-chat-height
|
|
76
|
+
* @cssprop --lf-chat-offset - distance from the corner (20px)
|
|
77
|
+
* @cssprop --lf-chat-z-index
|
|
78
|
+
* @cssprop --lf-chat-launcher-size
|
|
79
|
+
* @cssprop --lf-chat-shadow
|
|
80
|
+
*/
|
|
81
|
+
export declare class LambforgeAgentChat extends LitElement {
|
|
82
|
+
/** drawer only: the panel is open */
|
|
83
|
+
open: boolean;
|
|
84
|
+
/** drawer (launcher + panel) | inline | fullscreen */
|
|
85
|
+
mode: 'drawer' | 'inline' | 'fullscreen';
|
|
86
|
+
position: 'bottom-right' | 'bottom-left';
|
|
87
|
+
theme: 'light' | 'dark';
|
|
88
|
+
/** preferred agent (id or name) */
|
|
89
|
+
agent: string;
|
|
90
|
+
/** only these agents (comma list of ids or names); a picker when > 1 */
|
|
91
|
+
agents: string;
|
|
92
|
+
locale: string;
|
|
93
|
+
/** the header text (default: the agent's name) */
|
|
94
|
+
heading: string;
|
|
95
|
+
url: string;
|
|
96
|
+
publishableKey: string;
|
|
97
|
+
tokenUrl: string;
|
|
98
|
+
turnstileSitekey: string;
|
|
99
|
+
turnstileUrl: string;
|
|
100
|
+
/** An AgentClient you built yourself (wins over the attributes). */
|
|
101
|
+
client?: AgentClient;
|
|
102
|
+
/** Your token source, when not using `token-url`. */
|
|
103
|
+
getToken?: () => Promise<SessionToken | string> | SessionToken | string;
|
|
104
|
+
/** Override any text (see ChatStrings). */
|
|
105
|
+
strings: Partial<ChatStrings>;
|
|
106
|
+
private store?;
|
|
107
|
+
private lastCount;
|
|
108
|
+
private get shown();
|
|
109
|
+
get t(): ChatStrings;
|
|
110
|
+
/** Cold: <r-renderer> subscribes once; the store lives as long as that. */
|
|
111
|
+
connect(): Observable<ChatState>;
|
|
112
|
+
dispatch(action: ChatAction): void;
|
|
113
|
+
OnUpdate(): void;
|
|
114
|
+
private resolveClient;
|
|
115
|
+
private verifyHuman;
|
|
116
|
+
/** The (rendered) box the challenge goes into. */
|
|
117
|
+
private turnstileBox;
|
|
118
|
+
/** Send a message to the selected agent. */
|
|
119
|
+
send(text: string): Reader<[ChatState], void>;
|
|
120
|
+
/** Stop the answer in progress. */
|
|
121
|
+
stopAnswer(): Reader<[ChatState], void>;
|
|
122
|
+
pick(agentId: string): void;
|
|
123
|
+
startOver(): void;
|
|
124
|
+
setOpen(open: boolean): void;
|
|
125
|
+
private focusInput;
|
|
126
|
+
private submit;
|
|
127
|
+
private onInputKey;
|
|
128
|
+
private autosize;
|
|
129
|
+
/** Escape closes the drawer; Tab stays inside the open dialog. */
|
|
130
|
+
private onPanelKey;
|
|
131
|
+
private emit;
|
|
132
|
+
noticeText(notice: Notice | null): string;
|
|
133
|
+
view(state: ChatState): import("lit-html").TemplateResult<1>;
|
|
134
|
+
private bubble;
|
|
135
|
+
private intro;
|
|
136
|
+
private scrollDown;
|
|
137
|
+
}
|
|
138
|
+
declare global {
|
|
139
|
+
interface HTMLElementTagNameMap {
|
|
140
|
+
'lambforge-agent-chat': LambforgeAgentChat;
|
|
141
|
+
}
|
|
142
|
+
}
|