@vettvangur/ai-sdk 0.5.4 → 0.7.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/README.md +113 -6
- package/dist/binmx.d.ts +17 -0
- package/dist/binmx.js +40 -0
- package/dist/contracts.d.ts +336 -0
- package/dist/dom.js +15 -1
- package/dist/index.d.ts +55 -273
- package/dist/index.js +244 -71
- package/dist/live-chat/aichat.d.ts +10 -1
- package/dist/live-chat/aichat.js +23 -1
- package/dist/styles.css +163 -0
- package/dist/surfaces.js +37 -0
- package/package.json +15 -3
package/dist/surfaces.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { i as isPlainObject } from "./dom.js";
|
|
2
|
+
//#region src/surfaces.ts
|
|
3
|
+
/**
|
|
4
|
+
* A surface that shows one item out of an authored list template. The template is cloned, every
|
|
5
|
+
* element carrying `attribute` whose value is not the payload's `key` field is removed, and the
|
|
6
|
+
* rest of the template stays as authored, so one item is the same markup the whole list shows.
|
|
7
|
+
* Null when the template is missing or no item matches.
|
|
8
|
+
*/
|
|
9
|
+
function createTemplateItemSurface(options) {
|
|
10
|
+
return ({ root, data }) => {
|
|
11
|
+
const value = isPlainObject(data) ? data[options.key] : null;
|
|
12
|
+
const template = root.querySelector(`template[data-template="${CSS.escape(options.template)}"]`);
|
|
13
|
+
if (typeof value !== "string" || !template) return null;
|
|
14
|
+
const content = template.content.cloneNode(true);
|
|
15
|
+
let found = false;
|
|
16
|
+
for (const item of content.querySelectorAll(`[${CSS.escape(options.attribute)}]`)) if (item.getAttribute(options.attribute) === value) found = true;
|
|
17
|
+
else item.remove();
|
|
18
|
+
return found ? content : null;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A surface of which only the latest copy stays in the thread, for an embedded component whose
|
|
23
|
+
* script binds to the first match in the document or whose fields share ids. What it draws is
|
|
24
|
+
* marked with `data-ai-chat-single` under `key`, and drawing it again removes the earlier copies.
|
|
25
|
+
*/
|
|
26
|
+
function createSingleSurface(key, surface) {
|
|
27
|
+
return (context) => {
|
|
28
|
+
const content = surface(context);
|
|
29
|
+
if (!content) return null;
|
|
30
|
+
for (const earlier of context.root.querySelectorAll(`[data-ai-chat-thread] [data-ai-chat-single="${CSS.escape(key)}"]`)) earlier.remove();
|
|
31
|
+
const elements = content instanceof Element ? [content] : content instanceof DocumentFragment ? Array.from(content.children) : [];
|
|
32
|
+
for (const element of elements) element.setAttribute("data-ai-chat-single", key);
|
|
33
|
+
return content;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { createTemplateItemSurface as n, createSingleSurface as t };
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vettvangur/ai-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Framework-agnostic AI chat client for server-rendered shells",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"access": "public",
|
|
7
7
|
"author": "Vettvangur",
|
|
8
8
|
"license": "Proprietary",
|
|
9
|
-
"sideEffects":
|
|
9
|
+
"sideEffects": [
|
|
10
|
+
"*.css"
|
|
11
|
+
],
|
|
10
12
|
"files": [
|
|
11
13
|
"dist/**/*",
|
|
12
14
|
"LICENSE"
|
|
@@ -27,18 +29,28 @@
|
|
|
27
29
|
"./live-chat/aichat": {
|
|
28
30
|
"types": "./dist/live-chat/aichat.d.ts",
|
|
29
31
|
"import": "./dist/live-chat/aichat.js"
|
|
30
|
-
}
|
|
32
|
+
},
|
|
33
|
+
"./binmx": {
|
|
34
|
+
"types": "./dist/binmx.d.ts",
|
|
35
|
+
"import": "./dist/binmx.js"
|
|
36
|
+
},
|
|
37
|
+
"./styles.css": "./dist/styles.css"
|
|
31
38
|
},
|
|
32
39
|
"types": "./dist/index.d.ts",
|
|
33
40
|
"peerDependencies": {
|
|
41
|
+
"@bgunnarsson/binmx": "^0.1.0",
|
|
34
42
|
"@microsoft/omnichannel-chat-sdk": "^2.0.2"
|
|
35
43
|
},
|
|
36
44
|
"peerDependenciesMeta": {
|
|
45
|
+
"@bgunnarsson/binmx": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
37
48
|
"@microsoft/omnichannel-chat-sdk": {
|
|
38
49
|
"optional": true
|
|
39
50
|
}
|
|
40
51
|
},
|
|
41
52
|
"devDependencies": {
|
|
53
|
+
"@bgunnarsson/binmx": "0.1.0",
|
|
42
54
|
"@microsoft/omnichannel-chat-sdk": "2.0.2",
|
|
43
55
|
"rimraf": "6.1.3",
|
|
44
56
|
"tsdown": "0.22.14",
|