obi-sdk 0.1.2 → 0.1.4
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 +99 -65
- package/dist/index-e52b38be.js +5223 -0
- package/dist/modular/chunks/assistant-5a47c1b4.js +234 -0
- package/dist/modular/chunks/assistant-5a47c1b4.js.map +1 -0
- package/dist/modular/chunks/mitt-3c1f932d.js +20 -0
- package/dist/modular/chunks/mitt-3c1f932d.js.map +1 -0
- package/dist/modular/chunks/{index-634e0df5.js → obi-widget-0d63936f.js} +2258 -253
- package/dist/modular/chunks/obi-widget-0d63936f.js.map +1 -0
- package/dist/modular/chunks/{session-e208b5bb.js → session-88fd0dca.js} +18 -39
- package/dist/modular/chunks/session-88fd0dca.js.map +1 -0
- package/dist/modular/core.js +11 -207
- package/dist/modular/core.js.map +1 -1
- package/dist/modular/index.js +78 -400
- package/dist/modular/index.js.map +1 -1
- package/dist/modular/ui.js +29 -1992
- package/dist/modular/ui.js.map +1 -1
- package/dist/obi-loader.iife.js +1 -1
- package/dist/obi-loader.iife.js.map +1 -1
- package/dist/obi-loader.js +36 -33
- package/dist/obi-loader.js.map +1 -1
- package/dist/obi-loader.umd.cjs +1 -1
- package/dist/obi-loader.umd.cjs.map +1 -1
- package/dist/obi-sdk.es.js +8 -22713
- package/dist/obi-sdk.standalone.iife.js +72 -175
- package/dist/obi-sdk.standalone.iife.js.map +1 -1
- package/dist/obi-sdk.umd.js +121 -262
- package/dist/session-33b71dff.js +15762 -0
- package/package.json +1 -1
- package/dist/modular/chunks/index-634e0df5.js.map +0 -1
- package/dist/modular/chunks/session-e208b5bb.js.map +0 -1
package/README.md
CHANGED
|
@@ -18,13 +18,12 @@ Currently, the recommended way to use Obi SDK is through the inline loader scrip
|
|
|
18
18
|
|
|
19
19
|
The loader accepts the following configuration options:
|
|
20
20
|
|
|
21
|
-
| Option
|
|
22
|
-
|
|
|
23
|
-
| `position`
|
|
24
|
-
| `apiKey`
|
|
25
|
-
| `
|
|
26
|
-
| `
|
|
27
|
-
| `apiBaseUrl` | string | `'https://www.iamobi.ai/api/'` | Base URL for API calls |
|
|
21
|
+
| Option | Type | Default | Description |
|
|
22
|
+
| ---------- | ------- | ---------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| `position` | string | `'bottom-right'` | Position of the widget on the page. Options: `'bottom-right'`, `'bottom-left'`, `'top-right'`, `'top-left'` |
|
|
24
|
+
| `apiKey` | string | - | Your Obi API key (required for production) |
|
|
25
|
+
| `autoInit` | boolean | `true` | Whether to initialize the widget automatically when loaded |
|
|
26
|
+
| `user` | object | - | User information with `id` (required), `email` (optional) and `metadata` (optional) |
|
|
28
27
|
|
|
29
28
|
## Quick Start
|
|
30
29
|
|
|
@@ -44,7 +43,10 @@ The simplest way to add Obi to your website is by using the inline loader script
|
|
|
44
43
|
window.obiWidgetConfig = {
|
|
45
44
|
position: "bottom-right",
|
|
46
45
|
apiKey: "YOUR_API_KEY",
|
|
47
|
-
|
|
46
|
+
user: {
|
|
47
|
+
id: "user-123",
|
|
48
|
+
email: "user@example.com",
|
|
49
|
+
},
|
|
48
50
|
}
|
|
49
51
|
</script>
|
|
50
52
|
</head>
|
|
@@ -57,9 +59,7 @@ The simplest way to add Obi to your website is by using the inline loader script
|
|
|
57
59
|
"use strict"
|
|
58
60
|
var c = {
|
|
59
61
|
position: "bottom-right",
|
|
60
|
-
|
|
61
|
-
sdkVersion: "latest",
|
|
62
|
-
noCacheSDK: !1,
|
|
62
|
+
autoInit: true,
|
|
63
63
|
}
|
|
64
64
|
w.__obiSDKLoading = w.__obiSDKLoading || !1
|
|
65
65
|
function i() {
|
|
@@ -73,20 +73,12 @@ The simplest way to add Obi to your website is by using the inline loader script
|
|
|
73
73
|
})
|
|
74
74
|
return
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
v && (f.sdkVersion = v)
|
|
79
|
-
j(f, function () {
|
|
80
|
-
w.__obiSDKLoading = !1
|
|
81
|
-
g(f)
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
} else {
|
|
85
|
-
j(f, function () {
|
|
76
|
+
m(function (v) {
|
|
77
|
+
j(v, function () {
|
|
86
78
|
w.__obiSDKLoading = !1
|
|
87
79
|
g(f)
|
|
88
80
|
})
|
|
89
|
-
}
|
|
81
|
+
})
|
|
90
82
|
}
|
|
91
83
|
}
|
|
92
84
|
function e(f) {
|
|
@@ -99,7 +91,7 @@ The simplest way to add Obi to your website is by using the inline loader script
|
|
|
99
91
|
}
|
|
100
92
|
function m(cb) {
|
|
101
93
|
try {
|
|
102
|
-
var x = new
|
|
94
|
+
var x = new XMLHttpRequest()
|
|
103
95
|
x.open("GET", "https://registry.npmjs.org/obi-sdk/latest")
|
|
104
96
|
x.onload = function () {
|
|
105
97
|
if (x.status === 200) {
|
|
@@ -121,23 +113,23 @@ The simplest way to add Obi to your website is by using the inline loader script
|
|
|
121
113
|
cb(null)
|
|
122
114
|
}
|
|
123
115
|
}
|
|
124
|
-
function j(
|
|
116
|
+
function j(v, cb) {
|
|
125
117
|
w.__obiSDKLoading = !0
|
|
126
118
|
var s = d.createElement("script")
|
|
127
119
|
s.type = "text/javascript"
|
|
128
120
|
s.async = !0
|
|
129
121
|
var b = "https://unpkg.com/obi-sdk"
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
: b + "@" + f.sdkVersion + "/dist/obi-sdk.standalone.iife.js"
|
|
122
|
+
var u = v || "latest"
|
|
123
|
+
s.src = b + "@" + u + "/dist/obi-sdk.standalone.iife.js"
|
|
133
124
|
s.onload = cb
|
|
134
125
|
s.onerror = function () {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
126
|
+
if (u !== "latest") {
|
|
127
|
+
console.warn("Failed to load specific version, falling back to latest")
|
|
128
|
+
s.src = b + "@latest/dist/obi-sdk.standalone.iife.js"
|
|
129
|
+
s.onload = cb
|
|
130
|
+
} else {
|
|
131
|
+
w.__obiSDKLoading = !1
|
|
132
|
+
console.error("Failed to load Obi SDK")
|
|
141
133
|
}
|
|
142
134
|
}
|
|
143
135
|
var fs = d.getElementsByTagName("script")[0]
|
|
@@ -159,36 +151,22 @@ The simplest way to add Obi to your website is by using the inline loader script
|
|
|
159
151
|
var t = d.createElement("obi-widget")
|
|
160
152
|
f.theme && t.setAttribute("theme", f.theme)
|
|
161
153
|
f.apiKey && t.setAttribute("api-key", f.apiKey)
|
|
162
|
-
|
|
163
|
-
f.
|
|
164
|
-
|
|
165
|
-
t.style.zIndex = "9999"
|
|
166
|
-
switch (f.position) {
|
|
167
|
-
case "bottom-right":
|
|
168
|
-
t.style.bottom = "20px"
|
|
169
|
-
t.style.right = "20px"
|
|
170
|
-
break
|
|
171
|
-
case "bottom-left":
|
|
172
|
-
t.style.bottom = "20px"
|
|
173
|
-
t.style.left = "20px"
|
|
174
|
-
break
|
|
175
|
-
case "top-right":
|
|
176
|
-
t.style.top = "20px"
|
|
177
|
-
t.style.right = "20px"
|
|
178
|
-
break
|
|
179
|
-
case "top-left":
|
|
180
|
-
t.style.top = "20px"
|
|
181
|
-
t.style.left = "20px"
|
|
182
|
-
break
|
|
183
|
-
}
|
|
154
|
+
t.setAttribute("api-base-url", "https://www.iamobi.ai/api/")
|
|
155
|
+
f.position && t.setAttribute("position", f.position)
|
|
156
|
+
f.user && t.setAttribute("user", JSON.stringify(f.user))
|
|
184
157
|
d.body.appendChild(t)
|
|
185
158
|
w.console && w.console.log && w.console.log("Obi Widget added to page")
|
|
186
159
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
160
|
+
if (w.obiWidgetConfig && w.obiWidgetConfig.autoInit === false) {
|
|
161
|
+
// Skip auto-initialization
|
|
162
|
+
console.log("Obi Widget auto-initialization disabled")
|
|
163
|
+
} else {
|
|
164
|
+
d.readyState === "complete"
|
|
165
|
+
? i()
|
|
166
|
+
: w.attachEvent
|
|
167
|
+
? w.attachEvent("onload", i)
|
|
168
|
+
: w.addEventListener("load", i, !1)
|
|
169
|
+
}
|
|
192
170
|
})(window, document)
|
|
193
171
|
</script>
|
|
194
172
|
</body>
|
|
@@ -202,10 +180,29 @@ The widget will automatically appear in the specified position on your page.
|
|
|
202
180
|
The loader script:
|
|
203
181
|
|
|
204
182
|
1. Dynamically checks for the latest version using the npm registry API
|
|
205
|
-
2. Loads the
|
|
183
|
+
2. Loads the specific versioned SDK from unpkg.com for better browser caching
|
|
206
184
|
3. Creates and positions the `<obi-widget>` custom element on your page
|
|
207
185
|
4. Initializes the widget with your API key and configuration
|
|
208
186
|
|
|
187
|
+
## Advanced Loader Usage
|
|
188
|
+
|
|
189
|
+
The inline loader script shown above is already minified for production use. If you need to customize it or understand how it works, you can find the full, commented version in the source code (`src/loader-inline.js`).
|
|
190
|
+
|
|
191
|
+
The loader script is also available as a separate file that can be loaded directly:
|
|
192
|
+
|
|
193
|
+
```html
|
|
194
|
+
<!-- Configure the widget (optional) -->
|
|
195
|
+
<script>
|
|
196
|
+
window.obiWidgetConfig = {
|
|
197
|
+
position: "bottom-right",
|
|
198
|
+
apiKey: "YOUR_API_KEY",
|
|
199
|
+
}
|
|
200
|
+
</script>
|
|
201
|
+
|
|
202
|
+
<!-- Load the widget using the separate loader script -->
|
|
203
|
+
<script src="https://unpkg.com/obi-sdk@latest/dist/obi-loader.iife.js"></script>
|
|
204
|
+
```
|
|
205
|
+
|
|
209
206
|
## Installation for npm Projects
|
|
210
207
|
|
|
211
208
|
You can also install the SDK via npm:
|
|
@@ -222,10 +219,50 @@ import ObiSDK from "obi-sdk"
|
|
|
222
219
|
// Initialize the SDK
|
|
223
220
|
const sdk = new ObiSDK({
|
|
224
221
|
apiKey: "YOUR_API_KEY",
|
|
225
|
-
apiBaseUrl: "https://www.iamobi.ai/api/",
|
|
226
222
|
})
|
|
227
223
|
```
|
|
228
224
|
|
|
225
|
+
## Always Load the Latest SDK Version
|
|
226
|
+
|
|
227
|
+
The SDK includes a simple function to always load the latest version from the CDN, which can be useful for applications that need to ensure users always have the newest features. The dynamic loader follows the same version detection mechanism as the inline script, querying the npm registry to get the latest version.
|
|
228
|
+
|
|
229
|
+
```tsx
|
|
230
|
+
import { initObi } from "obi-sdk"
|
|
231
|
+
|
|
232
|
+
// In a React component:
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const setupObi = async () => {
|
|
235
|
+
try {
|
|
236
|
+
// This will:
|
|
237
|
+
// 1. Check npm registry for the latest version
|
|
238
|
+
// 2. Load that specific version from unpkg.com
|
|
239
|
+
// 3. Initialize the widget with your config
|
|
240
|
+
await initObi({
|
|
241
|
+
apiKey: "YOUR_API_KEY",
|
|
242
|
+
position: "bottom-right",
|
|
243
|
+
user: {
|
|
244
|
+
id: "user-123",
|
|
245
|
+
email: "user@example.com",
|
|
246
|
+
},
|
|
247
|
+
})
|
|
248
|
+
console.log("Obi Assistant initialized with latest SDK")
|
|
249
|
+
} catch (error) {
|
|
250
|
+
console.error("Failed to initialize Obi Assistant:", error)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Initialize Obi
|
|
255
|
+
setupObi()
|
|
256
|
+
}, [])
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
This approach ensures your application always uses the newest SDK version without requiring updates to your codebase. The loader will:
|
|
260
|
+
|
|
261
|
+
1. Query the npm registry to find the latest published version
|
|
262
|
+
2. Load that specific version from unpkg.com
|
|
263
|
+
3. Fall back to the "latest" tag if the specific version fails to load
|
|
264
|
+
4. Initialize the Obi widget with your configuration
|
|
265
|
+
|
|
229
266
|
## Building the SDK
|
|
230
267
|
|
|
231
268
|
To build the SDK locally:
|
|
@@ -284,7 +321,6 @@ The widget can be positioned in one of four corners of the page:
|
|
|
284
321
|
window.obiWidgetConfig = {
|
|
285
322
|
position: "bottom-right", // Options: "bottom-right", "bottom-left", "top-right", "top-left"
|
|
286
323
|
apiKey: "YOUR_API_KEY",
|
|
287
|
-
apiBaseUrl: "https://www.iamobi.ai/api/",
|
|
288
324
|
}
|
|
289
325
|
```
|
|
290
326
|
|
|
@@ -296,7 +332,6 @@ The widget supports light and dark themes:
|
|
|
296
332
|
window.obiWidgetConfig = {
|
|
297
333
|
theme: "light", // Options: "light", "dark"
|
|
298
334
|
apiKey: "YOUR_API_KEY",
|
|
299
|
-
apiBaseUrl: "https://www.iamobi.ai/api/",
|
|
300
335
|
}
|
|
301
336
|
```
|
|
302
337
|
|
|
@@ -309,7 +344,6 @@ window.obiWidgetConfig = {
|
|
|
309
344
|
sdkVersion: "latest", // Use "latest" or a specific version number
|
|
310
345
|
noCacheSDK: false, // Set to true to bypass cache
|
|
311
346
|
apiKey: "YOUR_API_KEY",
|
|
312
|
-
apiBaseUrl: "https://www.iamobi.ai/api/",
|
|
313
347
|
}
|
|
314
348
|
```
|
|
315
349
|
|