@lambforge/agent-chat 0.0.0-stage → 0.0.3

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.
@@ -0,0 +1,3 @@
1
+ import { TemplateResult } from '@rxdi/lit-html';
2
+ export declare function renderMarkdown(text: string): TemplateResult[];
3
+ export declare function inline(text: string): (TemplateResult | string)[];
@@ -0,0 +1,121 @@
1
+ import type { AgentEvent, ConversationDetail, EmbedAgent } from '@lambforge/agents';
2
+ /** The panel is on screen (nothing loads before the first time). */
3
+ export declare const shown: ((payload: boolean) => {
4
+ payload: boolean;
5
+ } & {
6
+ type: "[chat] shown";
7
+ }) & {
8
+ type: "[chat] shown";
9
+ };
10
+ export declare const connecting: (() => {
11
+ type: "[chat] connecting";
12
+ }) & {
13
+ type: "[chat] connecting";
14
+ };
15
+ export declare const failed: ((payload: string) => {
16
+ payload: string;
17
+ } & {
18
+ type: "[chat] failed";
19
+ }) & {
20
+ type: "[chat] failed";
21
+ };
22
+ export declare const verifying: ((payload: boolean) => {
23
+ payload: boolean;
24
+ } & {
25
+ type: "[chat] verifying";
26
+ }) & {
27
+ type: "[chat] verifying";
28
+ };
29
+ export declare const agentsLoaded: ((payload: {
30
+ agents: EmbedAgent[];
31
+ agentId: string | null;
32
+ }) => {
33
+ payload: {
34
+ agents: EmbedAgent[];
35
+ agentId: string | null;
36
+ };
37
+ } & {
38
+ type: "[chat] agents loaded";
39
+ }) & {
40
+ type: "[chat] agents loaded";
41
+ };
42
+ export declare const pickAgent: ((payload: string) => {
43
+ payload: string;
44
+ } & {
45
+ type: "[chat] pick agent";
46
+ }) & {
47
+ type: "[chat] pick agent";
48
+ };
49
+ export declare const historyLoaded: ((payload: {
50
+ agentId: string;
51
+ detail: ConversationDetail;
52
+ }) => {
53
+ payload: {
54
+ agentId: string;
55
+ detail: ConversationDetail;
56
+ };
57
+ } & {
58
+ type: "[chat] history loaded";
59
+ }) & {
60
+ type: "[chat] history loaded";
61
+ };
62
+ export declare const newConversation: (() => {
63
+ type: "[chat] new conversation";
64
+ }) & {
65
+ type: "[chat] new conversation";
66
+ };
67
+ /** Where a message goes / what to stop (from the state the view shows). */
68
+ export interface RunTarget {
69
+ agentId: string;
70
+ /** null = a new conversation */
71
+ conversationId: string | null;
72
+ }
73
+ /** The visitor sends a message (shown at once; the run effect sends it). */
74
+ export declare const sendMessage: ((payload: RunTarget & {
75
+ text: string;
76
+ }) => {
77
+ payload: RunTarget & {
78
+ text: string;
79
+ };
80
+ } & {
81
+ type: "[chat] send";
82
+ }) & {
83
+ type: "[chat] send";
84
+ };
85
+ /** Follow an answer that was already running (a page reload). */
86
+ export declare const resume: ((payload: {
87
+ agentId: string;
88
+ conversationId: string;
89
+ afterSeq: number;
90
+ }) => {
91
+ payload: {
92
+ agentId: string;
93
+ conversationId: string;
94
+ afterSeq: number;
95
+ };
96
+ } & {
97
+ type: "[chat] resume";
98
+ }) & {
99
+ type: "[chat] resume";
100
+ };
101
+ export declare const agentEvent: ((payload: AgentEvent) => {
102
+ payload: AgentEvent;
103
+ } & {
104
+ type: "[chat] event";
105
+ }) & {
106
+ type: "[chat] event";
107
+ };
108
+ export declare const runEnded: (() => {
109
+ type: "[chat] run ended";
110
+ }) & {
111
+ type: "[chat] run ended";
112
+ };
113
+ /** Stop the answer in progress (the abort effect tells the server). */
114
+ export declare const stop: ((payload: RunTarget) => {
115
+ payload: RunTarget;
116
+ } & {
117
+ type: "[chat] stop";
118
+ }) & {
119
+ type: "[chat] stop";
120
+ };
121
+ export type ChatAction = ReturnType<typeof shown | typeof connecting | typeof failed | typeof verifying | typeof agentsLoaded | typeof pickAgent | typeof historyLoaded | typeof newConversation | typeof sendMessage | typeof resume | typeof agentEvent | typeof runEnded | typeof stop>;
@@ -0,0 +1,44 @@
1
+ import type { AgentClient, EmbedAgent } from '@lambforge/agents';
2
+ import { ChatAction } from './chat-actions';
3
+ import type { ChatState } from './chat-state';
4
+ /** What the effects need from the element (no DI: one store per chat). */
5
+ export interface ChatContext {
6
+ /** null = no session source configured */
7
+ client: AgentClient | null;
8
+ /** preferred agent (id or name) */
9
+ agent: string;
10
+ /** only these agents (ids or names); empty = all the session allows */
11
+ agents: string[];
12
+ /** DOM events on the element */
13
+ emit(type: 'answer' | 'error', detail: Record<string, unknown>): void;
14
+ }
15
+ export declare const errorCode: (e: unknown) => string;
16
+ export declare function pickAgents(all: EmbedAgent[], ctx: Pick<ChatContext, 'agent' | 'agents'>): {
17
+ agents: EmbedAgent[];
18
+ agentId: string;
19
+ };
20
+ /**
21
+ * The chat's side effects: every request goes through here (the element
22
+ * only dispatches). Registered in ChatStore's `createEpicRegistry(...)` -
23
+ * an effect not listed there never runs.
24
+ */
25
+ export declare class ChatEffects {
26
+ private readonly ctx;
27
+ constructor(ctx: ChatContext);
28
+ /** The first time the panel is on screen: the agents this session may use. */
29
+ connect$: import("@rxdi/redux-store").EffectFactory<ChatAction, ChatState>;
30
+ /** The selected agent's latest conversation (resuming a running answer). */
31
+ select$: import("@rxdi/redux-store").EffectFactory<ChatAction, ChatState>;
32
+ /**
33
+ * One run at a time: a sent message or a resumed answer, its events as
34
+ * actions until done / error, cancelled by stop, another agent or a new
35
+ * conversation.
36
+ */
37
+ run$: import("@rxdi/redux-store").EffectFactory<ChatAction, ChatState>;
38
+ /** Tell the server to stop the answer. */
39
+ abort$: import("@rxdi/redux-store").EffectFactory<ChatAction, ChatState>;
40
+ /** Failures also reach the page as an `error` event. */
41
+ failures$: import("@rxdi/redux-store").EffectFactory<ChatAction, ChatState>;
42
+ private conversation;
43
+ private follow$;
44
+ }
@@ -0,0 +1,2 @@
1
+ import { ChatState } from './chat-state';
2
+ export declare const chatReducer: import("ts-action").Reducer<ChatState>;
@@ -0,0 +1,31 @@
1
+ import type { AgentErrorCode, AgentMessage, EmbedAgent } from '@lambforge/agents';
2
+ export interface ChatMessage {
3
+ id: string;
4
+ role: 'user' | 'assistant';
5
+ text: string;
6
+ /** distinct tool names the answer used */
7
+ tools: string[];
8
+ }
9
+ export type Notice = {
10
+ kind: 'busy';
11
+ what: 'connecting' | 'thinking' | 'verifying';
12
+ } | {
13
+ kind: 'error';
14
+ code: AgentErrorCode | string;
15
+ } | {
16
+ kind: 'info';
17
+ what: 'stopped';
18
+ };
19
+ export interface ChatState {
20
+ /** the panel has been / is on screen */
21
+ shown: boolean;
22
+ agents: EmbedAgent[];
23
+ agentId: string | null;
24
+ /** null = a new conversation (created by the first message) */
25
+ conversationId: string | null;
26
+ messages: ChatMessage[];
27
+ answering: boolean;
28
+ notice: Notice | null;
29
+ }
30
+ export declare const initialChatState: ChatState;
31
+ export declare function toMessage(m: AgentMessage): ChatMessage;
@@ -0,0 +1,18 @@
1
+ import { Observable } from 'rxjs';
2
+ import { ChatAction } from './chat-actions';
3
+ import { ChatContext } from './chat-effects';
4
+ import { ChatState } from './chat-state';
5
+ /**
6
+ * One chat's store (`@rxdi/redux-store`, like legends' AdminStore): one
7
+ * reducer, the effects in ChatEffects. One per element - a page may show
8
+ * several chats - created when the element's State stream starts and
9
+ * destroyed when it ends.
10
+ */
11
+ export declare class ChatStore {
12
+ private readonly destroy$;
13
+ private readonly store;
14
+ readonly state$: Observable<ChatState>;
15
+ constructor(ctx: ChatContext, initial?: Partial<ChatState>);
16
+ dispatch(action: ChatAction): void;
17
+ destroy(): void;
18
+ }
@@ -0,0 +1,5 @@
1
+ export * from './chat-actions';
2
+ export * from './chat-effects';
3
+ export * from './chat-reducer';
4
+ export * from './chat-state';
5
+ export * from './chat-store';
@@ -0,0 +1,20 @@
1
+ import type { AgentErrorCode } from '@lambforge/agents';
2
+ /** Every text the chat shows - override any with `.strings`. */
3
+ export interface ChatStrings {
4
+ title: string;
5
+ open: string;
6
+ close: string;
7
+ newChat: string;
8
+ placeholder: string;
9
+ send: string;
10
+ stop: string;
11
+ thinking: string;
12
+ connecting: string;
13
+ pickAgent: string;
14
+ usedTools: string;
15
+ verifying: string;
16
+ errors: Record<AgentErrorCode | 'default', string>;
17
+ }
18
+ export declare const LOCALES: Record<string, ChatStrings>;
19
+ /** The locale's strings (by language, `bg-BG` -> `bg`) with overrides. */
20
+ export declare function stringsFor(locale: string | null | undefined, overrides?: Partial<ChatStrings>): ChatStrings;
@@ -0,0 +1,2 @@
1
+ /** Shadow-DOM styles. Theme with `--lf-chat-*` variables or `::part()`. */
2
+ export declare const STYLES = "\n:host {\n --_accent: var(--lf-chat-accent, #4f46e5);\n --_accent-fg: var(--lf-chat-accent-fg, #ffffff);\n --_bg: var(--lf-chat-bg, #ffffff);\n --_fg: var(--lf-chat-fg, #111827);\n --_muted: var(--lf-chat-muted, #6b7280);\n --_border: var(--lf-chat-border, #e5e7eb);\n --_bot-bg: var(--lf-chat-bot-bg, #f3f4f6);\n --_bot-fg: var(--lf-chat-bot-fg, var(--_fg));\n --_user-bg: var(--lf-chat-user-bg, var(--_accent));\n --_user-fg: var(--lf-chat-user-fg, var(--_accent-fg));\n --_error: var(--lf-chat-error, #b91c1c);\n --_radius: var(--lf-chat-radius, 12px);\n --_font: var(--lf-chat-font, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);\n --_width: var(--lf-chat-width, 380px);\n --_height: var(--lf-chat-height, min(640px, calc(100vh - 120px)));\n --_offset: var(--lf-chat-offset, 20px);\n --_z: var(--lf-chat-z-index, 2147483000);\n --_launcher: var(--lf-chat-launcher-size, 56px);\n --_shadow: var(--lf-chat-shadow, 0 12px 40px rgba(0, 0, 0, 0.18));\n font-family: var(--_font);\n color: var(--_fg);\n font-size: 15px;\n line-height: 1.45;\n}\n:host([theme='dark']) {\n --_bg: var(--lf-chat-bg, #111827);\n --_fg: var(--lf-chat-fg, #f9fafb);\n --_muted: var(--lf-chat-muted, #9ca3af);\n --_border: var(--lf-chat-border, #374151);\n --_bot-bg: var(--lf-chat-bot-bg, #1f2937);\n --_error: var(--lf-chat-error, #f87171);\n}\n* { box-sizing: border-box; }\n[hidden] { display: none !important; }\nbutton { font: inherit; cursor: pointer; }\n\n.launcher {\n position: fixed;\n bottom: var(--_offset);\n right: var(--_offset);\n width: var(--_launcher);\n height: var(--_launcher);\n border-radius: 50%;\n border: 0;\n background: var(--_accent);\n color: var(--_accent-fg);\n box-shadow: var(--_shadow);\n z-index: var(--_z);\n display: grid;\n place-items: center;\n}\n:host([position='bottom-left']) .launcher { right: auto; left: var(--_offset); }\n.launcher svg { width: 26px; height: 26px; }\n\n.panel {\n display: flex;\n flex-direction: column;\n background: var(--_bg);\n color: var(--_fg);\n border: 1px solid var(--_border);\n border-radius: var(--_radius);\n overflow: hidden;\n}\n:host(:not([mode])) .panel,\n:host([mode='drawer']) .panel {\n position: fixed;\n bottom: calc(var(--_offset) + var(--_launcher) + 12px);\n right: var(--_offset);\n width: var(--_width);\n height: var(--_height);\n box-shadow: var(--_shadow);\n z-index: var(--_z);\n}\n:host([position='bottom-left']) .panel { right: auto; left: var(--_offset); }\n:host([mode='inline']) .panel { width: 100%; height: var(--lf-chat-height, 560px); }\n:host([mode='fullscreen']) .panel {\n position: fixed; inset: 0; border-radius: 0; border: 0; z-index: var(--_z);\n}\n@media (max-width: 640px) {\n :host(:not([mode])) .panel,\n :host([mode='drawer']) .panel {\n inset: 0; width: auto; height: auto; border-radius: 0; border: 0;\n height: 100dvh;\n }\n}\n\nheader {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 10px 12px;\n border-bottom: 1px solid var(--_border);\n}\nheader .title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\nheader select {\n font: inherit; color: inherit; background: transparent;\n border: 1px solid var(--_border); border-radius: 8px; padding: 4px 6px; max-width: 45%;\n}\n.icon {\n border: 0; background: transparent; color: var(--_muted);\n width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;\n}\n.icon:hover, .icon:focus-visible { background: var(--_bot-bg); color: var(--_fg); }\n.icon svg { width: 18px; height: 18px; }\n:host([mode='inline']) .close { display: none; }\n\n.messages {\n flex: 1;\n overflow-y: auto;\n padding: 14px 12px;\n display: flex;\n flex-direction: column;\n gap: 10px;\n scrollbar-width: thin;\n}\n.msg { max-width: 85%; padding: 8px 12px; border-radius: var(--_radius); overflow-wrap: anywhere; }\n.msg.user { align-self: flex-end; background: var(--_user-bg); color: var(--_user-fg); white-space: pre-wrap; }\n.msg.assistant { align-self: flex-start; background: var(--_bot-bg); color: var(--_bot-fg); }\n.msg p { margin: 0 0 6px; }\n.msg p:last-child { margin-bottom: 0; }\n.msg ul, .msg ol { margin: 4px 0 6px; padding-left: 20px; }\n.msg pre { margin: 6px 0; padding: 8px; overflow-x: auto; border-radius: 8px; background: rgba(0,0,0,0.06); font-size: 13px; }\n.msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }\n.msg a { color: inherit; }\n.tools { font-size: 12px; color: var(--_muted); margin-top: 4px; }\n\n.welcome { color: var(--_muted); }\n.suggestions { display: flex; flex-wrap: wrap; gap: 6px; }\n.suggestions button {\n border: 1px solid var(--_border); background: transparent; color: var(--_fg);\n border-radius: 999px; padding: 6px 10px; font-size: 13px; text-align: left;\n}\n.suggestions button:hover, .suggestions button:focus-visible { border-color: var(--_accent); }\n\n.status { font-size: 13px; color: var(--_muted); padding: 0 12px 6px; min-height: 0; }\n.status.error { color: var(--_error); }\n.dots::after { content: '...'; animation: dots 1.2s steps(4, end) infinite; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; }\n@keyframes dots { from { width: 0; } to { width: 1.2em; } }\n@media (prefers-reduced-motion: reduce) { .dots::after { animation: none; } }\n\n.turnstile { padding: 0 12px 6px; }\n.turnstile iframe { border: 0; width: 100%; height: 70px; }\n\nform {\n display: flex;\n gap: 8px;\n padding: 10px 12px;\n border-top: 1px solid var(--_border);\n align-items: flex-end;\n}\ntextarea {\n flex: 1;\n resize: none;\n font: inherit;\n color: inherit;\n background: transparent;\n border: 1px solid var(--_border);\n border-radius: 10px;\n padding: 8px 10px;\n max-height: 140px;\n min-height: 40px;\n}\ntextarea:focus-visible { outline: 2px solid var(--_accent); outline-offset: 0; border-color: transparent; }\n.send {\n border: 0; border-radius: 10px; background: var(--_accent); color: var(--_accent-fg);\n padding: 0 14px; height: 40px; font-weight: 600;\n}\n.send:disabled { opacity: 0.5; cursor: default; }\n.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A Cloudflare Turnstile token for an anonymous session. Either the site's
3
+ * own widget (`sitekey`; its hostname must be one of the publishable key's
4
+ * sites) or Lambforge's hosted challenge page in an iframe, which posts
5
+ * the token back to this page only (`postMessage` to our origin).
6
+ */
7
+ export declare const HOSTED_TURNSTILE_URL = "https://lambforge.com/agent-turnstile.html";
8
+ export declare function turnstileToken(opts: {
9
+ host: HTMLElement;
10
+ sitekey?: string | null;
11
+ hostedUrl?: string | null;
12
+ }): Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "@lambforge/agent-chat",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.3",
4
+ "description": "<lambforge-agent-chat>: a chat with your Lambforge agent on any site - one script tag or a web component (@rhtml/component + @rxdi/redux-store)",
5
+ "license": "MIT",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.ts",
9
+ "unpkg": "dist/agent-chat.js",
10
+ "jsdelivr": "dist/agent-chat.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.cjs"
16
+ },
17
+ "./agent-chat.js": "./dist/agent-chat.js"
18
+ },
19
+ "sideEffects": true,
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/lamb-forge/packages.git",
27
+ "directory": "packages/agent-chat"
28
+ },
29
+ "homepage": "https://lambforge.com/docs",
30
+ "keywords": [
31
+ "lambforge",
32
+ "ai-agent",
33
+ "chat",
34
+ "web-component",
35
+ "custom-element"
36
+ ],
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "build": "rm -rf dist && node scripts/build.mjs && tsc -p tsconfig.build.json",
42
+ "lint": "tsc --noEmit -p tsconfig.json",
43
+ "test": "node scripts/test.mjs"
44
+ },
45
+ "dependencies": {
46
+ "@lambforge/agents": "^0.0.2",
47
+ "rxjs": "^7.8.2"
48
+ },
49
+ "devDependencies": {
50
+ "@rhtml/component": "^0.0.149",
51
+ "@rxdi/lit-html": "^0.7.258",
52
+ "@rxdi/redux-store": "^7.0.1",
53
+ "happy-dom": "^21.0.4",
54
+ "ts-action": "^11.0.0"
55
+ },
56
+ "gitHead": "01763fd9c2e883e45e6026adb8ec22c447724cea"
57
+ }