@syntrologie/adapt-chatbot 2.8.0-canary.31 → 2.8.0-canary.310
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/AdaptiveChatBar.d.ts +85 -0
- package/dist/AdaptiveChatBar.d.ts.map +1 -0
- package/dist/AdaptiveChatBar.js +10 -0
- package/dist/AdaptiveChatBar.js.map +7 -0
- package/dist/AdaptiveChatBarMountable.d.ts +35 -0
- package/dist/AdaptiveChatBarMountable.d.ts.map +1 -0
- package/dist/AdaptiveChatTrail.d.ts +85 -0
- package/dist/AdaptiveChatTrail.d.ts.map +1 -0
- package/dist/AdaptiveChatTrail.js +9 -0
- package/dist/AdaptiveChatTrail.js.map +7 -0
- package/dist/AdaptiveChipsStrip.d.ts +1150 -0
- package/dist/AdaptiveChipsStrip.d.ts.map +1 -0
- package/dist/AdaptiveChipsStrip.js +11 -0
- package/dist/AdaptiveChipsStrip.js.map +7 -0
- package/dist/AdaptiveChipsStripMountable.d.ts +24 -0
- package/dist/AdaptiveChipsStripMountable.d.ts.map +1 -0
- package/dist/ChatAssistantLit.d.ts +60 -0
- package/dist/ChatAssistantLit.d.ts.map +1 -0
- package/dist/ChatAssistantLit.js +12 -0
- package/dist/ChatAssistantLit.js.map +7 -0
- package/dist/ChatSession.d.ts +178 -0
- package/dist/ChatSession.d.ts.map +1 -0
- package/dist/ChatTransport.d.ts +283 -0
- package/dist/ChatTransport.d.ts.map +1 -0
- package/dist/NavLinkMountable.d.ts +25 -0
- package/dist/NavLinkMountable.d.ts.map +1 -0
- package/dist/NavLinkMountable.test.d.ts +2 -0
- package/dist/NavLinkMountable.test.d.ts.map +1 -0
- package/dist/TextAnswerMountable.d.ts +17 -0
- package/dist/TextAnswerMountable.d.ts.map +1 -0
- package/dist/Turnstile.d.ts +83 -0
- package/dist/Turnstile.d.ts.map +1 -0
- package/dist/cdn.d.ts +2 -6
- package/dist/cdn.d.ts.map +1 -1
- package/dist/chunk-2ZUJ7DZI.js +8770 -0
- package/dist/chunk-2ZUJ7DZI.js.map +7 -0
- package/dist/chunk-BNN5YLN3.js +417 -0
- package/dist/chunk-BNN5YLN3.js.map +7 -0
- package/dist/chunk-FVNSOP7B.js +634 -0
- package/dist/chunk-FVNSOP7B.js.map +7 -0
- package/dist/chunk-ONGGPQER.js +3722 -0
- package/dist/chunk-ONGGPQER.js.map +7 -0
- package/dist/chunk-SCVTTLFJ.js +334 -0
- package/dist/chunk-SCVTTLFJ.js.map +7 -0
- package/dist/chunk-UVKRO5ER.js +13 -0
- package/dist/chunk-UVKRO5ER.js.map +7 -0
- package/dist/chunk-VLJ3WOEX.js +231 -0
- package/dist/chunk-VLJ3WOEX.js.map +7 -0
- package/dist/editor-lit.d.ts +37 -0
- package/dist/editor-lit.d.ts.map +1 -0
- package/dist/editor-lit.js +134 -0
- package/dist/editor-lit.js.map +7 -0
- package/dist/elements/ActionHandler.d.ts +34 -0
- package/dist/elements/ActionHandler.d.ts.map +1 -0
- package/dist/elements/ElementInstanceStore.d.ts +155 -0
- package/dist/elements/ElementInstanceStore.d.ts.map +1 -0
- package/dist/elements/ElementInstanceStore.test.d.ts +2 -0
- package/dist/elements/ElementInstanceStore.test.d.ts.map +1 -0
- package/dist/elements/ElementTypeHandler.d.ts +77 -0
- package/dist/elements/ElementTypeHandler.d.ts.map +1 -0
- package/dist/elements/ItemHandler.d.ts +60 -0
- package/dist/elements/ItemHandler.d.ts.map +1 -0
- package/dist/elements/ItemHandler.test.d.ts +2 -0
- package/dist/elements/ItemHandler.test.d.ts.map +1 -0
- package/dist/elements/TileHandler.d.ts +52 -0
- package/dist/elements/TileHandler.d.ts.map +1 -0
- package/dist/elements/blockRenderer.d.ts +46 -0
- package/dist/elements/blockRenderer.d.ts.map +1 -0
- package/dist/elements/blockRenderer.test.d.ts +13 -0
- package/dist/elements/blockRenderer.test.d.ts.map +1 -0
- package/dist/elements/blocks.d.ts +58 -0
- package/dist/elements/blocks.d.ts.map +1 -0
- package/dist/elements/envelope.d.ts +24 -0
- package/dist/elements/envelope.d.ts.map +1 -0
- package/dist/elements/fetcher.d.ts +40 -0
- package/dist/elements/fetcher.d.ts.map +1 -0
- package/dist/elements/index.d.ts +32 -0
- package/dist/elements/index.d.ts.map +1 -0
- package/dist/elements/types.d.ts +106 -0
- package/dist/elements/types.d.ts.map +1 -0
- package/dist/observer/__tests__/allowlist.test.d.ts +9 -0
- package/dist/observer/__tests__/allowlist.test.d.ts.map +1 -0
- package/dist/observer/__tests__/observer-isolation.test.d.ts +13 -0
- package/dist/observer/__tests__/observer-isolation.test.d.ts.map +1 -0
- package/dist/observer/__tests__/queue.test.d.ts +2 -0
- package/dist/observer/__tests__/queue.test.d.ts.map +1 -0
- package/dist/observer/__tests__/transport.test.d.ts +2 -0
- package/dist/observer/__tests__/transport.test.d.ts.map +1 -0
- package/dist/observer/allowlist.d.ts +32 -0
- package/dist/observer/allowlist.d.ts.map +1 -0
- package/dist/observer/index.d.ts +35 -0
- package/dist/observer/index.d.ts.map +1 -0
- package/dist/observer/queue.d.ts +57 -0
- package/dist/observer/queue.d.ts.map +1 -0
- package/dist/observer/transport.d.ts +26 -0
- package/dist/observer/transport.d.ts.map +1 -0
- package/dist/runtime-lit.d.ts +8 -0
- package/dist/runtime-lit.d.ts.map +1 -0
- package/dist/runtime.d.ts +8 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1649 -29
- package/dist/runtime.js.map +7 -0
- package/dist/schema.d.ts +3298 -11
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +126 -31
- package/dist/schema.js.map +7 -0
- package/dist/types.d.ts +47 -31
- package/dist/types.d.ts.map +1 -1
- package/package.json +50 -19
- package/dist/ChatAssistant.d.ts +0 -18
- package/dist/ChatAssistant.d.ts.map +0 -1
- package/dist/ChatAssistant.js +0 -178
- package/dist/actionParser.d.ts +0 -15
- package/dist/actionParser.d.ts.map +0 -1
- package/dist/actionParser.js +0 -52
- package/dist/apiClient.d.ts +0 -23
- package/dist/apiClient.d.ts.map +0 -1
- package/dist/apiClient.js +0 -51
- package/dist/cdn.js +0 -37
- package/dist/editor.d.ts +0 -17
- package/dist/editor.d.ts.map +0 -1
- package/dist/editor.js +0 -36
- package/dist/types.js +0 -6
- package/dist/useChat.d.ts +0 -25
- package/dist/useChat.d.ts.map +0 -1
- package/dist/useChat.js +0 -106
package/dist/actionParser.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adaptive Chatbot - Action Parser
|
|
3
|
-
*
|
|
4
|
-
* Extracts JSON action blocks from LLM markdown responses.
|
|
5
|
-
* Actions are identified by having a `kind` field in a ```json code fence.
|
|
6
|
-
*/
|
|
7
|
-
import type { ParsedResponse } from './types';
|
|
8
|
-
/**
|
|
9
|
-
* Parse an LLM response, extracting action blocks from JSON code fences.
|
|
10
|
-
*
|
|
11
|
-
* - Blocks with a `kind` field are treated as actions and removed from display text.
|
|
12
|
-
* - Blocks without `kind` or with invalid JSON are left in the display text.
|
|
13
|
-
*/
|
|
14
|
-
export declare function parseActions(input: string): ParsedResponse;
|
|
15
|
-
//# sourceMappingURL=actionParser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actionParser.d.ts","sourceRoot":"","sources":["../src/actionParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAe,cAAc,EAAE,MAAM,SAAS,CAAC;AAI3D;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CA8C1D"}
|
package/dist/actionParser.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adaptive Chatbot - Action Parser
|
|
3
|
-
*
|
|
4
|
-
* Extracts JSON action blocks from LLM markdown responses.
|
|
5
|
-
* Actions are identified by having a `kind` field in a ```json code fence.
|
|
6
|
-
*/
|
|
7
|
-
const JSON_FENCE_RE = /```json\s*\n([\s\S]*?)```/g;
|
|
8
|
-
/**
|
|
9
|
-
* Parse an LLM response, extracting action blocks from JSON code fences.
|
|
10
|
-
*
|
|
11
|
-
* - Blocks with a `kind` field are treated as actions and removed from display text.
|
|
12
|
-
* - Blocks without `kind` or with invalid JSON are left in the display text.
|
|
13
|
-
*/
|
|
14
|
-
export function parseActions(input) {
|
|
15
|
-
const actions = [];
|
|
16
|
-
let displayText = input;
|
|
17
|
-
// Collect matches in reverse order so we can splice display text without index shifting
|
|
18
|
-
const matches = [];
|
|
19
|
-
let match;
|
|
20
|
-
// Reset regex state
|
|
21
|
-
JSON_FENCE_RE.lastIndex = 0;
|
|
22
|
-
while ((match = JSON_FENCE_RE.exec(input)) !== null) {
|
|
23
|
-
matches.push({
|
|
24
|
-
fullMatch: match[0],
|
|
25
|
-
json: match[1],
|
|
26
|
-
index: match.index,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
// Process in reverse to preserve indices when removing from displayText
|
|
30
|
-
for (let i = matches.length - 1; i >= 0; i--) {
|
|
31
|
-
const { fullMatch, json } = matches[i];
|
|
32
|
-
let parsed;
|
|
33
|
-
try {
|
|
34
|
-
parsed = JSON.parse(json);
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
// Malformed JSON — leave in display text
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (typeof parsed === 'object' &&
|
|
41
|
-
parsed !== null &&
|
|
42
|
-
'kind' in parsed &&
|
|
43
|
-
typeof parsed.kind === 'string') {
|
|
44
|
-
actions.unshift(parsed);
|
|
45
|
-
// Remove the action block from display text
|
|
46
|
-
displayText = displayText.replace(fullMatch, '');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
// Clean up extra blank lines left from removed blocks
|
|
50
|
-
displayText = displayText.replace(/\n{3,}/g, '\n\n').trim();
|
|
51
|
-
return { displayText, actions };
|
|
52
|
-
}
|
package/dist/apiClient.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adaptive Chatbot - API Client
|
|
3
|
-
*
|
|
4
|
-
* Auth-aware fetch client that reads Stytch JWT from cookies
|
|
5
|
-
* and workspace ID from localStorage.
|
|
6
|
-
*/
|
|
7
|
-
import type { ChatApiRequest, ChatApiResponse } from './types';
|
|
8
|
-
export declare class AuthError extends Error {
|
|
9
|
-
constructor(message: string);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Read auth credentials from browser cookie and localStorage.
|
|
13
|
-
* Throws AuthError if credentials are missing.
|
|
14
|
-
*/
|
|
15
|
-
export declare function getAuthHeaders(): {
|
|
16
|
-
Authorization: string;
|
|
17
|
-
'X-Workspace-Id': string;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Send a chat message to the backend.
|
|
21
|
-
*/
|
|
22
|
-
export declare function sendMessage(url: string, request: ChatApiRequest): Promise<ChatApiResponse>;
|
|
23
|
-
//# sourceMappingURL=apiClient.d.ts.map
|
package/dist/apiClient.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../src/apiClient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/D,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAepF;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAoBhG"}
|
package/dist/apiClient.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adaptive Chatbot - API Client
|
|
3
|
-
*
|
|
4
|
-
* Auth-aware fetch client that reads Stytch JWT from cookies
|
|
5
|
-
* and workspace ID from localStorage.
|
|
6
|
-
*/
|
|
7
|
-
export class AuthError extends Error {
|
|
8
|
-
constructor(message) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = 'AuthError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Read auth credentials from browser cookie and localStorage.
|
|
15
|
-
* Throws AuthError if credentials are missing.
|
|
16
|
-
*/
|
|
17
|
-
export function getAuthHeaders() {
|
|
18
|
-
const cookieMatch = document.cookie.match(/stytch_session_jwt=([^;]*)/);
|
|
19
|
-
if (!cookieMatch || !cookieMatch[1]) {
|
|
20
|
-
throw new AuthError('No authentication token found');
|
|
21
|
-
}
|
|
22
|
-
const workspaceId = localStorage.getItem('syntrologie_workspace_id');
|
|
23
|
-
if (!workspaceId) {
|
|
24
|
-
throw new AuthError('No workspace ID found');
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
Authorization: `Bearer ${cookieMatch[1]}`,
|
|
28
|
-
'X-Workspace-Id': workspaceId,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Send a chat message to the backend.
|
|
33
|
-
*/
|
|
34
|
-
export async function sendMessage(url, request) {
|
|
35
|
-
const authHeaders = getAuthHeaders();
|
|
36
|
-
const response = await fetch(url, {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
headers: {
|
|
39
|
-
'Content-Type': 'application/json',
|
|
40
|
-
...authHeaders,
|
|
41
|
-
},
|
|
42
|
-
body: JSON.stringify(request),
|
|
43
|
-
});
|
|
44
|
-
if (!response.ok) {
|
|
45
|
-
if (response.status === 401) {
|
|
46
|
-
throw new AuthError('Session expired or unauthorized');
|
|
47
|
-
}
|
|
48
|
-
throw new Error(`Chat request failed: ${response.status} ${response.statusText}`);
|
|
49
|
-
}
|
|
50
|
-
return response.json();
|
|
51
|
-
}
|
package/dist/cdn.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CDN Entry Point for Adaptive Chatbot
|
|
3
|
-
*
|
|
4
|
-
* This module is bundled for CDN delivery and self-registers with the global
|
|
5
|
-
* SynOS app registry when loaded dynamically via the AppLoader.
|
|
6
|
-
*/
|
|
7
|
-
import ChatbotEditor, { editorPanel } from './editor';
|
|
8
|
-
import { runtime } from './runtime';
|
|
9
|
-
/**
|
|
10
|
-
* App manifest for registry registration.
|
|
11
|
-
* Follows the AppManifest interface expected by AppLoader/AppRegistry.
|
|
12
|
-
*/
|
|
13
|
-
export const manifest = {
|
|
14
|
-
id: 'adaptive-chatbot',
|
|
15
|
-
version: runtime.version,
|
|
16
|
-
name: runtime.name,
|
|
17
|
-
description: runtime.description,
|
|
18
|
-
runtime: {
|
|
19
|
-
actions: [],
|
|
20
|
-
widgets: runtime.widgets,
|
|
21
|
-
},
|
|
22
|
-
editor: { component: ChatbotEditor, panel: editorPanel },
|
|
23
|
-
metadata: {
|
|
24
|
-
isBuiltIn: false,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Self-register with global registry if available.
|
|
29
|
-
* This happens when loaded via script tag (UMD).
|
|
30
|
-
*/
|
|
31
|
-
if (typeof window !== 'undefined') {
|
|
32
|
-
const registry = window.SynOS?.appRegistry;
|
|
33
|
-
if (registry && typeof registry.register === 'function') {
|
|
34
|
-
registry.register(manifest);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export default manifest;
|
package/dist/editor.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adaptive Chatbot - Editor Component
|
|
3
|
-
*
|
|
4
|
-
* Visual editor panel for configuring chatbot tile props.
|
|
5
|
-
*/
|
|
6
|
-
import type { EditorPanelProps } from './types';
|
|
7
|
-
export declare function ChatbotEditor({ config, onChange, editor }: EditorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
-
/**
|
|
9
|
-
* Editor panel configuration for the app registry.
|
|
10
|
-
*/
|
|
11
|
-
export declare const editorPanel: {
|
|
12
|
-
title: string;
|
|
13
|
-
icon: string;
|
|
14
|
-
description: string;
|
|
15
|
-
};
|
|
16
|
-
export default ChatbotEditor;
|
|
17
|
-
//# sourceMappingURL=editor.d.ts.map
|
package/dist/editor.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAM/D,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,gBAAgB,2CAoF3E;AAED;;GAEG;AACH,eAAO,MAAM,WAAW;;;;CAIvB,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
package/dist/editor.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* Adaptive Chatbot - Editor Component
|
|
4
|
-
*
|
|
5
|
-
* Visual editor panel for configuring chatbot tile props.
|
|
6
|
-
*/
|
|
7
|
-
import { EditorBody, EditorFooter, EditorHeader, EditorInput, EditorLayout, EditorTextarea, } from '@syntrologie/shared-editor-ui';
|
|
8
|
-
import { useEffect, useRef } from 'react';
|
|
9
|
-
// ============================================================================
|
|
10
|
-
// ChatbotEditor Component
|
|
11
|
-
// ============================================================================
|
|
12
|
-
export function ChatbotEditor({ config, onChange, editor }) {
|
|
13
|
-
const typedConfig = config;
|
|
14
|
-
// Consume initial navigation payload on mount (chatbot is form-based, no sub-items)
|
|
15
|
-
const initialConsumed = useRef(false);
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (!initialConsumed.current && (editor.initialEditKey != null || editor.initialCreate)) {
|
|
18
|
-
initialConsumed.current = true;
|
|
19
|
-
editor.clearInitialState?.();
|
|
20
|
-
}
|
|
21
|
-
}, [editor]);
|
|
22
|
-
const handleChange = (field, value) => {
|
|
23
|
-
onChange({ ...config, [field]: value });
|
|
24
|
-
editor.setDirty(true);
|
|
25
|
-
};
|
|
26
|
-
return (_jsxs(EditorLayout, { children: [_jsx(EditorHeader, { title: "Chat Assistant", subtitle: "Configure AI chat assistant", onBack: () => editor.navigateHome() }), _jsxs(EditorBody, { children: [_jsxs("div", { className: "se-mb-6", children: [_jsx("div", { className: "se-text-xs se-font-semibold se-text-slate-grey-8 se-uppercase se-tracking-wide se-mb-3", children: "API Configuration" }), _jsx(EditorInput, { label: "Backend URL", type: "text", value: typedConfig.backendUrl || '', onChange: (e) => handleChange('backendUrl', e.target.value), placeholder: "/api/chat/message" }), _jsx(EditorInput, { label: "MLflow Run ID (optional)", type: "text", value: typedConfig.mlflowRunId || '', onChange: (e) => handleChange('mlflowRunId', e.target.value), placeholder: "e.g., abc123" })] }), _jsxs("div", { className: "se-mb-6", children: [_jsx("div", { className: "se-text-xs se-font-semibold se-text-slate-grey-8 se-uppercase se-tracking-wide se-mb-3", children: "Chat Settings" }), _jsx(EditorTextarea, { label: "Greeting Message", value: typedConfig.greeting || '', onChange: (e) => handleChange('greeting', e.target.value), placeholder: "Hi! How can I help?" }), _jsx(EditorInput, { label: "Max History (messages sent to backend)", type: "number", value: typedConfig.maxHistory || 20, onChange: (e) => handleChange('maxHistory', parseInt(e.target.value, 10)), min: 1, max: 100 })] })] }), _jsx(EditorFooter, { onSave: () => editor.save(), onPublish: () => editor.publish() })] }));
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Editor panel configuration for the app registry.
|
|
30
|
-
*/
|
|
31
|
-
export const editorPanel = {
|
|
32
|
-
title: 'Chat Assistant',
|
|
33
|
-
icon: '\u{1F4AC}',
|
|
34
|
-
description: 'AI chat assistant with action execution',
|
|
35
|
-
};
|
|
36
|
-
export default ChatbotEditor;
|
package/dist/types.js
DELETED
package/dist/useChat.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adaptive Chatbot - useChat Hook
|
|
3
|
-
*
|
|
4
|
-
* React hook managing chat message state, API communication,
|
|
5
|
-
* history management, and action execution via the runtime ActionEngine.
|
|
6
|
-
*/
|
|
7
|
-
import type { ChatbotWidgetRuntime, ChatMessage } from './types';
|
|
8
|
-
export interface UseChatOptions {
|
|
9
|
-
backendUrl: string;
|
|
10
|
-
tileId: string;
|
|
11
|
-
runtime: ChatbotWidgetRuntime;
|
|
12
|
-
greeting?: string;
|
|
13
|
-
maxHistory?: number;
|
|
14
|
-
mlflowRunId?: string;
|
|
15
|
-
config?: Record<string, unknown>;
|
|
16
|
-
}
|
|
17
|
-
export interface UseChatReturn {
|
|
18
|
-
messages: ChatMessage[];
|
|
19
|
-
isLoading: boolean;
|
|
20
|
-
error: string | null;
|
|
21
|
-
sendMessage: (text: string) => Promise<void>;
|
|
22
|
-
clearMessages: () => void;
|
|
23
|
-
}
|
|
24
|
-
export declare function useChat(options: UseChatOptions): UseChatReturn;
|
|
25
|
-
//# sourceMappingURL=useChat.d.ts.map
|
package/dist/useChat.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../src/useChat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAqB,oBAAoB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpF,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,oBAAoB,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAOD,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CA4G9D"}
|
package/dist/useChat.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adaptive Chatbot - useChat Hook
|
|
3
|
-
*
|
|
4
|
-
* React hook managing chat message state, API communication,
|
|
5
|
-
* history management, and action execution via the runtime ActionEngine.
|
|
6
|
-
*/
|
|
7
|
-
import { useCallback, useRef, useState } from 'react';
|
|
8
|
-
import { parseActions } from './actionParser';
|
|
9
|
-
import { sendMessage } from './apiClient';
|
|
10
|
-
let nextId = 0;
|
|
11
|
-
function generateId() {
|
|
12
|
-
return `msg-${Date.now()}-${++nextId}`;
|
|
13
|
-
}
|
|
14
|
-
export function useChat(options) {
|
|
15
|
-
const { backendUrl, tileId, runtime, greeting, maxHistory = 20, mlflowRunId, config } = options;
|
|
16
|
-
const [messages, setMessages] = useState(() => {
|
|
17
|
-
if (greeting) {
|
|
18
|
-
return [
|
|
19
|
-
{
|
|
20
|
-
id: generateId(),
|
|
21
|
-
role: 'assistant',
|
|
22
|
-
text: greeting,
|
|
23
|
-
timestamp: Date.now(),
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
return [];
|
|
28
|
-
});
|
|
29
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
30
|
-
const [error, setError] = useState(null);
|
|
31
|
-
const batchHandleRef = useRef(null);
|
|
32
|
-
const send = useCallback(async (text) => {
|
|
33
|
-
const trimmed = text.trim();
|
|
34
|
-
if (!trimmed)
|
|
35
|
-
return;
|
|
36
|
-
setError(null);
|
|
37
|
-
const userMessage = {
|
|
38
|
-
id: generateId(),
|
|
39
|
-
role: 'user',
|
|
40
|
-
text: trimmed,
|
|
41
|
-
timestamp: Date.now(),
|
|
42
|
-
};
|
|
43
|
-
setMessages((prev) => [...prev, userMessage]);
|
|
44
|
-
setIsLoading(true);
|
|
45
|
-
try {
|
|
46
|
-
// Build history from current messages + new user message
|
|
47
|
-
const currentMessages = [...messages, userMessage];
|
|
48
|
-
const historySlice = currentMessages.slice(-maxHistory).map((m) => ({
|
|
49
|
-
role: m.role,
|
|
50
|
-
content: m.text,
|
|
51
|
-
}));
|
|
52
|
-
const response = await sendMessage(backendUrl, {
|
|
53
|
-
message: trimmed,
|
|
54
|
-
history: historySlice,
|
|
55
|
-
mlflow_run_id: mlflowRunId,
|
|
56
|
-
current_config: config,
|
|
57
|
-
});
|
|
58
|
-
// Parse actions from the LLM response
|
|
59
|
-
const { displayText, actions } = parseActions(response.response);
|
|
60
|
-
const assistantMessage = {
|
|
61
|
-
id: generateId(),
|
|
62
|
-
role: 'assistant',
|
|
63
|
-
text: displayText,
|
|
64
|
-
timestamp: Date.now(),
|
|
65
|
-
};
|
|
66
|
-
setMessages((prev) => [...prev, assistantMessage]);
|
|
67
|
-
// Execute actions if present
|
|
68
|
-
if (actions.length > 0) {
|
|
69
|
-
// Revert previous batch
|
|
70
|
-
if (batchHandleRef.current?.isApplied()) {
|
|
71
|
-
await batchHandleRef.current.revertAll();
|
|
72
|
-
}
|
|
73
|
-
batchHandleRef.current = await runtime.actions.applyBatch(actions);
|
|
74
|
-
runtime.events.publish('chatbot.actions_applied', {
|
|
75
|
-
count: actions.length,
|
|
76
|
-
kinds: actions.map((a) => a.kind),
|
|
77
|
-
tileId,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
const message = err instanceof Error ? err.message : 'An unexpected error occurred';
|
|
83
|
-
setError(message);
|
|
84
|
-
}
|
|
85
|
-
finally {
|
|
86
|
-
setIsLoading(false);
|
|
87
|
-
}
|
|
88
|
-
}, [backendUrl, messages, maxHistory, mlflowRunId, config, runtime, tileId]);
|
|
89
|
-
const clearMessages = useCallback(() => {
|
|
90
|
-
setMessages([]);
|
|
91
|
-
setError(null);
|
|
92
|
-
// Revert any active actions
|
|
93
|
-
if (batchHandleRef.current?.isApplied()) {
|
|
94
|
-
batchHandleRef.current.revertAll();
|
|
95
|
-
batchHandleRef.current = null;
|
|
96
|
-
}
|
|
97
|
-
sessionStorage.removeItem(`syntro:chatbot:history:${tileId}`);
|
|
98
|
-
}, [tileId]);
|
|
99
|
-
return {
|
|
100
|
-
messages,
|
|
101
|
-
isLoading,
|
|
102
|
-
error,
|
|
103
|
-
sendMessage: send,
|
|
104
|
-
clearMessages,
|
|
105
|
-
};
|
|
106
|
-
}
|