bstp-agent-widget 0.2.77 → 0.2.79
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 +93 -24
- package/dist/agent-widget.js +1293 -1282
- package/dist/agent-widget.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,31 +30,88 @@ npm publish --access public
|
|
|
30
30
|
bun add bstp-agent-widget
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
### 1. Provide runtime configuration via `/environment.json`
|
|
34
|
+
|
|
35
|
+
Host applications must expose a GenAI configuration inside their own `public/environment.json`. The widget loads this file by default (or the URL you pass with `environmentUrl`).
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"url": {
|
|
40
|
+
"api": "https://your-api",
|
|
41
|
+
"apiPaths": {
|
|
42
|
+
"genai": "genai/api/v1"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"genai": {
|
|
46
|
+
"config": {
|
|
47
|
+
"assistantId": 220,
|
|
48
|
+
"agents": [
|
|
49
|
+
{
|
|
50
|
+
"assistantKey": "salesAgent",
|
|
51
|
+
"assistantId": 220,
|
|
52
|
+
"label": "Sales Assistant",
|
|
53
|
+
"initialMessage": "Hello, my customer id is "
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> GenAI login credentials are bundled inside the widget. Do **not** expose `genai.init` or any client secrets in your app's `environment.json`.
|
|
62
|
+
|
|
63
|
+
### 2. Mount the widget (React example)
|
|
64
|
+
|
|
65
|
+
Prefer mounting through `mountAgentChatWidgetFromEnvironment`. It automatically hydrates GenAI config from the environment file, while allowing optional overrides through the `config` option.
|
|
66
|
+
|
|
33
67
|
```tsx
|
|
34
|
-
import {
|
|
68
|
+
import { useEffect, useRef } from 'react';
|
|
69
|
+
import { mountAgentChatWidgetFromEnvironment } from 'bstp-agent-widget';
|
|
35
70
|
import 'bstp-agent-widget/style.css';
|
|
36
71
|
|
|
37
|
-
export function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
72
|
+
export function AgentWidgetHost() {
|
|
73
|
+
const hostRef = useRef<HTMLDivElement | null>(null);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!hostRef.current) return;
|
|
77
|
+
|
|
78
|
+
let cleanup: (() => void) | undefined;
|
|
79
|
+
|
|
80
|
+
(async () => {
|
|
81
|
+
cleanup = await mountAgentChatWidgetFromEnvironment(hostRef.current!, {
|
|
82
|
+
runtime: {
|
|
83
|
+
customerId: '590100010884',
|
|
84
|
+
customerToken: 'jwt-token',
|
|
85
|
+
language: 'tr-TR',
|
|
46
86
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
87
|
+
// Optional: override assistant selection coming from environment.json
|
|
88
|
+
config: {
|
|
89
|
+
assistantId: 220,
|
|
90
|
+
assistants: [
|
|
91
|
+
{
|
|
92
|
+
assistantKey: 'serviceAgent',
|
|
93
|
+
assistantId: 94,
|
|
94
|
+
label: 'Get help with your service issues',
|
|
95
|
+
initialMessage: 'Hello, my customer id is ',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
// Optional UI overrides
|
|
100
|
+
// theme: { withinPortal: true, fabPosition: { bottom: 16, right: 16 } },
|
|
101
|
+
// Optional: supply a different environment file
|
|
102
|
+
// environmentUrl: '/configs/widget-environment.json',
|
|
103
|
+
});
|
|
104
|
+
})();
|
|
105
|
+
|
|
106
|
+
return () => cleanup?.();
|
|
107
|
+
}, []);
|
|
108
|
+
|
|
109
|
+
return <div ref={hostRef} />;
|
|
55
110
|
}
|
|
56
111
|
```
|
|
57
112
|
|
|
113
|
+
> Precedence rules: runtime data is always provided by the host. If you pass a `config` option, the widget overrides the `genai.config` block from `environment.json` before booting (so every consumer, including initial automated messages, sees the admin UI values). When no override is provided, it falls back to the values coming from `environment.json`.
|
|
114
|
+
|
|
58
115
|
## Development Notes
|
|
59
116
|
|
|
60
117
|
- `react` and `react-dom` are defined as `peerDependencies`.
|
|
@@ -101,15 +158,19 @@ export class AgentChatWidgetComponent implements AfterViewInit, OnDestroy {
|
|
|
101
158
|
customerToken: 'jwt-token',
|
|
102
159
|
language: 'en-US',
|
|
103
160
|
},
|
|
104
|
-
//
|
|
105
|
-
// baseUrl and genai.init still come from environment.json.
|
|
161
|
+
// Optional: override what environment.json provides
|
|
106
162
|
config: {
|
|
107
163
|
assistantId: 220,
|
|
108
164
|
assistants: [
|
|
109
|
-
{
|
|
165
|
+
{
|
|
166
|
+
assistantKey: 'salesAgent',
|
|
167
|
+
assistantId: 220,
|
|
168
|
+
label: 'Sales Assistant',
|
|
169
|
+
initialMessage: 'Hello, my customer id is ',
|
|
170
|
+
},
|
|
110
171
|
],
|
|
111
172
|
},
|
|
112
|
-
|
|
173
|
+
theme: {
|
|
113
174
|
zIndex: 12000,
|
|
114
175
|
withinPortal: true,
|
|
115
176
|
fabPosition: { bottom: 16, right: 16 },
|
|
@@ -137,13 +198,21 @@ export class AgentChatWidgetComponent implements AfterViewInit, OnDestroy {
|
|
|
137
198
|
},
|
|
138
199
|
"genai": {
|
|
139
200
|
"config": {
|
|
140
|
-
"assistantId": 220
|
|
201
|
+
"assistantId": 220,
|
|
202
|
+
"agents": [
|
|
203
|
+
{
|
|
204
|
+
"assistantKey": "serviceAgent",
|
|
205
|
+
"assistantId": 94,
|
|
206
|
+
"label": "Get help with your service issues",
|
|
207
|
+
"initialMessage": "Hello, my customer id is "
|
|
208
|
+
}
|
|
209
|
+
]
|
|
141
210
|
}
|
|
142
211
|
}
|
|
143
212
|
}
|
|
144
213
|
```
|
|
145
214
|
|
|
146
|
-
Base URL is resolved from `url.api` + `url.apiPaths.genai`.
|
|
215
|
+
Base URL is resolved from `url.api` + `url.apiPaths.genai`. External `config` overrides supplied when mounting the widget take precedence over this environment file. GenAI login credentials are managed internally by the widget, so Angular hosts never provide `genai.init`.
|
|
147
216
|
|
|
148
217
|
# React Starter Kit
|
|
149
218
|
|