@syntrologie/adapt-chatbot 2.15.0 → 2.25.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/dist/ChatAssistantLit.d.ts +8 -56
- package/dist/ChatAssistantLit.d.ts.map +1 -1
- package/dist/ChatAssistantLit.js +8 -389
- package/dist/ChatAssistantLit.js.map +7 -0
- package/dist/cdn.d.ts +2 -6
- package/dist/cdn.d.ts.map +1 -1
- package/dist/chunk-FI7F22ED.js +3331 -0
- package/dist/chunk-FI7F22ED.js.map +7 -0
- package/dist/chunk-V6TY7KAL.js +8 -0
- package/dist/chunk-V6TY7KAL.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/runtime-lit.d.ts +3 -24
- package/dist/runtime-lit.d.ts.map +1 -1
- package/dist/runtime.d.ts +1 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +29 -40
- package/dist/runtime.js.map +7 -0
- package/dist/schema.d.ts +13 -3
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +29 -31
- package/dist/schema.js.map +7 -0
- package/dist/types.d.ts +1 -39
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -23
- package/dist/ChatAssistant.d.ts +0 -18
- package/dist/ChatAssistant.d.ts.map +0 -1
- package/dist/ChatAssistant.js +0 -178
- package/dist/SyntroChatbot.d.ts +0 -14
- package/dist/SyntroChatbot.d.ts.map +0 -1
- package/dist/SyntroChatbot.js +0 -56
- 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/runtime-lit.js +0 -32
- package/dist/tools/bridge.d.ts +0 -26
- package/dist/tools/bridge.d.ts.map +0 -1
- package/dist/tools/bridge.js +0 -25
- package/dist/tools/expanders.d.ts +0 -17
- package/dist/tools/expanders.d.ts.map +0 -1
- package/dist/tools/expanders.js +0 -41
- package/dist/tools/index.d.ts +0 -14
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -11
- package/dist/tools/registrations/GetContextTool.d.ts +0 -7
- package/dist/tools/registrations/GetContextTool.d.ts.map +0 -1
- package/dist/tools/registrations/GetContextTool.js +0 -18
- package/dist/tools/registrations/ScrollToTool.d.ts +0 -7
- package/dist/tools/registrations/ScrollToTool.d.ts.map +0 -1
- package/dist/tools/registrations/ScrollToTool.js +0 -38
- package/dist/tools/registrations/ShowOverlayTool.d.ts +0 -7
- package/dist/tools/registrations/ShowOverlayTool.d.ts.map +0 -1
- package/dist/tools/registrations/ShowOverlayTool.js +0 -47
- package/dist/tools/registrations/index.d.ts +0 -19
- package/dist/tools/registrations/index.d.ts.map +0 -1
- package/dist/tools/registrations/index.js +0 -7
- 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/tools/bridge.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Bridge — Dispatch
|
|
3
|
-
*
|
|
4
|
-
* executeTool: translates an AI tool call to an ActionStep and fires applyBatch().
|
|
5
|
-
* getContext: reads session state from the runtime (no page effect).
|
|
6
|
-
*/
|
|
7
|
-
import type { ChatbotWidgetRuntime } from '../types';
|
|
8
|
-
export interface ToolCall {
|
|
9
|
-
name: string;
|
|
10
|
-
args: Record<string, unknown>;
|
|
11
|
-
}
|
|
12
|
-
export interface ContextResult {
|
|
13
|
-
page: string;
|
|
14
|
-
signals: ReturnType<ChatbotWidgetRuntime['getActiveSignals']>;
|
|
15
|
-
config: ReturnType<ChatbotWidgetRuntime['getContextConfig']>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Execute a tool call. For action tools (show_overlay, scroll_to):
|
|
19
|
-
* expands args to ActionStep and calls applyBatch(). Throws for unknown tools.
|
|
20
|
-
*/
|
|
21
|
-
export declare function executeTool(call: ToolCall, runtime: ChatbotWidgetRuntime): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Read current session context. Never calls applyBatch.
|
|
24
|
-
*/
|
|
25
|
-
export declare function getContext(runtime: ChatbotWidgetRuntime): ContextResult;
|
|
26
|
-
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/tools/bridge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGrD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,UAAU,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC9D,MAAM,EAAE,UAAU,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,CAAC,CAAC;CAC9D;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAMvE"}
|
package/dist/tools/bridge.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Bridge — Dispatch
|
|
3
|
-
*
|
|
4
|
-
* executeTool: translates an AI tool call to an ActionStep and fires applyBatch().
|
|
5
|
-
* getContext: reads session state from the runtime (no page effect).
|
|
6
|
-
*/
|
|
7
|
-
import { expand } from './expanders';
|
|
8
|
-
/**
|
|
9
|
-
* Execute a tool call. For action tools (show_overlay, scroll_to):
|
|
10
|
-
* expands args to ActionStep and calls applyBatch(). Throws for unknown tools.
|
|
11
|
-
*/
|
|
12
|
-
export async function executeTool(call, runtime) {
|
|
13
|
-
const step = expand(call.name, call.args);
|
|
14
|
-
await runtime.actions.applyBatch([step]);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Read current session context. Never calls applyBatch.
|
|
18
|
-
*/
|
|
19
|
-
export function getContext(runtime) {
|
|
20
|
-
return {
|
|
21
|
-
page: window.location.pathname,
|
|
22
|
-
signals: runtime.getActiveSignals(),
|
|
23
|
-
config: runtime.getContextConfig(),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Bridge — Expanders
|
|
3
|
-
*
|
|
4
|
-
* Translates simplified AI tool arguments into full ActionStep objects.
|
|
5
|
-
* The AI sees small, constrained arg schemas. Expanders fill in all
|
|
6
|
-
* schema defaults the AI doesn't need to reason about.
|
|
7
|
-
*/
|
|
8
|
-
export interface ActionStep {
|
|
9
|
-
kind: string;
|
|
10
|
-
config: Record<string, unknown>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Expand a tool call into a full ActionStep.
|
|
14
|
-
* Throws for unknown tool names — do not silently ignore.
|
|
15
|
-
*/
|
|
16
|
-
export declare function expand(toolName: string, args: Record<string, unknown>): ActionStep;
|
|
17
|
-
//# sourceMappingURL=expanders.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expanders.d.ts","sourceRoot":"","sources":["../../src/tools/expanders.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AA6BD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAMlF"}
|
package/dist/tools/expanders.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Bridge — Expanders
|
|
3
|
-
*
|
|
4
|
-
* Translates simplified AI tool arguments into full ActionStep objects.
|
|
5
|
-
* The AI sees small, constrained arg schemas. Expanders fill in all
|
|
6
|
-
* schema defaults the AI doesn't need to reason about.
|
|
7
|
-
*/
|
|
8
|
-
const expanders = {
|
|
9
|
-
show_overlay: (args) => ({
|
|
10
|
-
kind: 'show_overlay',
|
|
11
|
-
config: {
|
|
12
|
-
headline: args['headline'],
|
|
13
|
-
body: args['body'],
|
|
14
|
-
cta_label: args['cta'] ?? null,
|
|
15
|
-
// Schema defaults — AI does not control these
|
|
16
|
-
position: 'center',
|
|
17
|
-
dismissible: true,
|
|
18
|
-
},
|
|
19
|
-
}),
|
|
20
|
-
scroll_to: (args) => ({
|
|
21
|
-
kind: 'scroll_to',
|
|
22
|
-
config: {
|
|
23
|
-
// Passed through as-is. The runtime SDK's scroll_to executor resolves
|
|
24
|
-
// the target string: first as a CSS selector / anchor ID, then by
|
|
25
|
-
// case-insensitive heading text match. The expander does no DOM lookup.
|
|
26
|
-
target: args['section'],
|
|
27
|
-
behavior: 'smooth',
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Expand a tool call into a full ActionStep.
|
|
33
|
-
* Throws for unknown tool names — do not silently ignore.
|
|
34
|
-
*/
|
|
35
|
-
export function expand(toolName, args) {
|
|
36
|
-
const expander = expanders[toolName];
|
|
37
|
-
if (!expander) {
|
|
38
|
-
throw new Error(`Unknown tool: ${toolName}`);
|
|
39
|
-
}
|
|
40
|
-
return expander(args);
|
|
41
|
-
}
|
package/dist/tools/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Bridge — public API
|
|
3
|
-
*
|
|
4
|
-
* Integration mode (client owns the chat shell):
|
|
5
|
-
* import { SyntroTools } from '@syntrologie/adapt-chatbot/tools'
|
|
6
|
-
* // Render <SyntroTools runtime={syntroRuntime} /> inside AssistantRuntimeProvider
|
|
7
|
-
*
|
|
8
|
-
* Supply mode: use <SyntroChatbot /> from '@syntrologie/adapt-chatbot' instead.
|
|
9
|
-
*/
|
|
10
|
-
export type { ContextResult, ToolCall } from './bridge';
|
|
11
|
-
export { executeTool, getContext } from './bridge';
|
|
12
|
-
export type { ActionStep } from './expanders';
|
|
13
|
-
export { SyntroTools } from './registrations';
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/tools/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Bridge — public API
|
|
3
|
-
*
|
|
4
|
-
* Integration mode (client owns the chat shell):
|
|
5
|
-
* import { SyntroTools } from '@syntrologie/adapt-chatbot/tools'
|
|
6
|
-
* // Render <SyntroTools runtime={syntroRuntime} /> inside AssistantRuntimeProvider
|
|
7
|
-
*
|
|
8
|
-
* Supply mode: use <SyntroChatbot /> from '@syntrologie/adapt-chatbot' instead.
|
|
9
|
-
*/
|
|
10
|
-
export { executeTool, getContext } from './bridge';
|
|
11
|
-
export { SyntroTools } from './registrations';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GetContextTool.d.ts","sourceRoot":"","sources":["../../../src/tools/registrations/GetContextTool.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGxD,UAAU,KAAK;IACb,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AAED,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,QAUhD"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GetContextTool — registers the get_context tool with assistant-ui.
|
|
3
|
-
*
|
|
4
|
-
* This is a silent tool: it has no render output. When the AI calls it,
|
|
5
|
-
* execute() reads session state and returns the context. No applyBatch call.
|
|
6
|
-
*/
|
|
7
|
-
import { useAssistantTool } from '@assistant-ui/react';
|
|
8
|
-
import { getContext } from '../bridge';
|
|
9
|
-
export function GetContextTool({ runtime }) {
|
|
10
|
-
useAssistantTool({
|
|
11
|
-
toolName: 'get_context',
|
|
12
|
-
type: 'frontend',
|
|
13
|
-
description: "Get current context about the user: what page they're on and what behavioral signals have fired in this session.",
|
|
14
|
-
parameters: { type: 'object', properties: {}, required: [] },
|
|
15
|
-
execute: async () => getContext(runtime),
|
|
16
|
-
});
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollToTool.d.ts","sourceRoot":"","sources":["../../../src/tools/registrations/ScrollToTool.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAOxD,UAAU,KAAK;IACb,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AAED,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,QAuC9C"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* ScrollToTool — registers the scroll_to tool with assistant-ui.
|
|
4
|
-
*/
|
|
5
|
-
import { useAssistantTool } from '@assistant-ui/react';
|
|
6
|
-
import { executeTool } from '../bridge';
|
|
7
|
-
export function ScrollToTool({ runtime }) {
|
|
8
|
-
useAssistantTool({
|
|
9
|
-
toolName: 'scroll_to',
|
|
10
|
-
type: 'frontend',
|
|
11
|
-
description: "Scroll the page to a named section. Use the section's visible heading text or a known anchor ID.",
|
|
12
|
-
parameters: {
|
|
13
|
-
type: 'object',
|
|
14
|
-
properties: {
|
|
15
|
-
section: {
|
|
16
|
-
type: 'string',
|
|
17
|
-
description: "The section to scroll to. Use the section's visible heading text or a known anchor ID.",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
required: ['section'],
|
|
21
|
-
},
|
|
22
|
-
execute: async (args) => {
|
|
23
|
-
await executeTool({ name: 'scroll_to', args }, runtime);
|
|
24
|
-
},
|
|
25
|
-
render: ({ args, status }) => {
|
|
26
|
-
if (status.type !== 'complete')
|
|
27
|
-
return null;
|
|
28
|
-
return (_jsxs("div", { style: {
|
|
29
|
-
padding: '8px 12px',
|
|
30
|
-
borderRadius: '6px',
|
|
31
|
-
background: 'rgba(99, 179, 237, 0.08)',
|
|
32
|
-
border: '1px solid rgba(99, 179, 237, 0.2)',
|
|
33
|
-
fontSize: '12px',
|
|
34
|
-
}, children: [_jsx("span", { style: { color: '#63b3ed', fontWeight: 600 }, children: "Scrolled to \u2014 " }), _jsx("span", { style: { color: '#90cdf4' }, children: args.section })] }));
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ShowOverlayTool.d.ts","sourceRoot":"","sources":["../../../src/tools/registrations/ShowOverlayTool.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AASxD,UAAU,KAAK;IACb,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AAED,wBAAgB,eAAe,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,QAwCjD"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* ShowOverlayTool — registers the show_overlay tool with assistant-ui.
|
|
4
|
-
*
|
|
5
|
-
* execute() fires immediately (type: 'frontend'), dispatching the overlay
|
|
6
|
-
* action via applyBatch(). The render prop shows a compact confirmation card
|
|
7
|
-
* inline in the chat thread after the tool completes.
|
|
8
|
-
*
|
|
9
|
-
* React 18+ strict mode double-fires useEffect in dev. applyBatch is
|
|
10
|
-
* idempotent for the same action within a session, so this is benign.
|
|
11
|
-
*/
|
|
12
|
-
import { useAssistantTool } from '@assistant-ui/react';
|
|
13
|
-
import { executeTool } from '../bridge';
|
|
14
|
-
export function ShowOverlayTool({ runtime }) {
|
|
15
|
-
useAssistantTool({
|
|
16
|
-
toolName: 'show_overlay',
|
|
17
|
-
type: 'frontend',
|
|
18
|
-
description: 'Show a modal overlay on the page with a headline, body message, and optional call-to-action button.',
|
|
19
|
-
parameters: {
|
|
20
|
-
type: 'object',
|
|
21
|
-
properties: {
|
|
22
|
-
headline: { type: 'string', description: 'Short headline for the overlay.' },
|
|
23
|
-
body: { type: 'string', description: 'Main message body.' },
|
|
24
|
-
cta: {
|
|
25
|
-
type: 'string',
|
|
26
|
-
description: 'Button label. Omit if no action needed.',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
required: ['headline', 'body'],
|
|
30
|
-
},
|
|
31
|
-
execute: async (args) => {
|
|
32
|
-
await executeTool({ name: 'show_overlay', args }, runtime);
|
|
33
|
-
},
|
|
34
|
-
render: ({ args, status }) => {
|
|
35
|
-
if (status.type !== 'complete')
|
|
36
|
-
return null;
|
|
37
|
-
return (_jsxs("div", { style: {
|
|
38
|
-
padding: '8px 12px',
|
|
39
|
-
borderRadius: '6px',
|
|
40
|
-
background: 'rgba(104, 211, 145, 0.08)',
|
|
41
|
-
border: '1px solid rgba(104, 211, 145, 0.2)',
|
|
42
|
-
fontSize: '12px',
|
|
43
|
-
}, children: [_jsx("span", { style: { color: '#68d391', fontWeight: 600 }, children: "Overlay shown \u2014 " }), _jsx("span", { style: { color: '#9ae6b4' }, children: args.headline })] }));
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SyntroTools — renders all tool registration components.
|
|
3
|
-
*
|
|
4
|
-
* Render this inside an AssistantRuntimeProvider. Each child registers
|
|
5
|
-
* one tool with assistant-ui via useAssistantTool.
|
|
6
|
-
*
|
|
7
|
-
* Integration mode:
|
|
8
|
-
* <AssistantRuntimeProvider runtime={myRuntime}>
|
|
9
|
-
* <SyntroTools runtime={syntroRuntime} />
|
|
10
|
-
* <Thread />
|
|
11
|
-
* </AssistantRuntimeProvider>
|
|
12
|
-
*/
|
|
13
|
-
import type { ChatbotWidgetRuntime } from '../../types';
|
|
14
|
-
interface Props {
|
|
15
|
-
runtime: ChatbotWidgetRuntime;
|
|
16
|
-
}
|
|
17
|
-
export declare function SyntroTools({ runtime }: Props): import("react/jsx-runtime").JSX.Element;
|
|
18
|
-
export {};
|
|
19
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/registrations/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAKxD,UAAU,KAAK;IACb,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AAED,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,2CAQ7C"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { GetContextTool } from './GetContextTool';
|
|
3
|
-
import { ScrollToTool } from './ScrollToTool';
|
|
4
|
-
import { ShowOverlayTool } from './ShowOverlayTool';
|
|
5
|
-
export function SyntroTools({ runtime }) {
|
|
6
|
-
return (_jsxs(_Fragment, { children: [_jsx(GetContextTool, { runtime: runtime }), _jsx(ShowOverlayTool, { runtime: runtime }), _jsx(ScrollToTool, { runtime: runtime })] }));
|
|
7
|
-
}
|
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
|
-
}
|