@folio-agent/widget 0.2.1 → 0.3.1
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 +2 -0
- package/dist/styles.d.ts +1 -1
- package/dist/styles.js +4 -4
- package/dist/widget-element.js +35 -9
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/styles.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WIDGET_STYLES = "\n :host {\n all: initial;\n color: inherit;\n color-scheme: inherit;\n font-family: var(--folio-agent-font, inherit);\n }\n .toggle {\n position: fixed;\n right: 20px;\n bottom: 20px;\n width: 56px;\n height: 56px;\n border-radius: 50%;\n border: none;\n background: var(--folio-agent-accent, CanvasText);\n color: var(--folio-agent-accent-contrast, Canvas);\n font-size: 24px;\n cursor: pointer;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);\n z-index: 2147483000;\n }\n .panel {\n position: fixed;\n right: 20px;\n bottom: 88px;\n width: 320px;\n max-height: 420px;\n display: flex;\n flex-direction: column;\n background: var(--folio-agent-surface, Canvas);\n border-radius: 12px;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);\n overflow: hidden;\n z-index: 2147483000;\n }\n .panel[hidden] {\n display: none;\n }\n .messages {\n flex: 1;\n overflow-y: auto;\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 10px;\n font-size: 14px;\n line-height: 1.6;\n color: var(--folio-agent-text, CanvasText);\n }\n .message {\n white-space: pre-wrap;\n }\n .message.assistant {\n align-self: flex-start;\n background: color-mix(in srgb, CanvasText 8%, Canvas);\n border: 1px solid color-mix(in srgb, CanvasText 16%, Canvas);\n border-radius: 8px;\n padding: 10px 14px;\n }\n .message.user {\n align-self: flex-end;\n background: color-mix(in srgb, CanvasText 14%, Canvas);\n border: 1px solid color-mix(in srgb, CanvasText 24%, Canvas);\n border-radius: 8px;\n padding: 10px 14px;\n }\n .disclosure {\n font-size: 12px;\n color: var(--folio-agent-muted, color-mix(in srgb, CanvasText 55%, Canvas));\n padding: 0 0 4px;\n }\n .disclosure a {\n color: #2563eb;\n }\n form {\n display: flex;\n border-top: 1px solid color-mix(in srgb, CanvasText 16%, Canvas);\n }\n input {\n flex: 1;\n border: none;\n background: transparent;\n color: inherit;\n padding: 10px;\n font-size: 14px;\n }\n input:focus {\n outline: none;\n }\n button[type=\"submit\"] {\n border: none;\n background: none;\n padding: 0 14px;\n cursor: pointer;\n color: var(--folio-agent-accent, CanvasText);\n font-weight: 600;\n }\n";
|
|
1
|
+
export declare const WIDGET_STYLES = "\n :host {\n all: initial;\n color: inherit;\n color-scheme: inherit;\n font-family: var(--folio-agent-font, inherit);\n }\n .toggle {\n position: fixed;\n right: 20px;\n bottom: 20px;\n width: 56px;\n height: 56px;\n border-radius: 50%;\n border: none;\n background: var(--folio-agent-accent, CanvasText);\n color: var(--folio-agent-accent-contrast, Canvas);\n font-size: 24px;\n cursor: pointer;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);\n z-index: 2147483000;\n }\n .panel {\n position: fixed;\n right: 20px;\n bottom: 88px;\n width: 320px;\n max-height: 420px;\n display: flex;\n flex-direction: column;\n background: var(--folio-agent-surface, Canvas);\n border-radius: 12px;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);\n overflow: hidden;\n z-index: 2147483000;\n }\n .panel[hidden] {\n display: none;\n }\n .messages {\n flex: 1;\n overflow-y: auto;\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 10px;\n font-size: 14px;\n line-height: 1.6;\n color: var(--folio-agent-text, CanvasText);\n }\n .message {\n white-space: pre-wrap;\n }\n .message.assistant {\n align-self: flex-start;\n background: color-mix(in srgb, var(--folio-agent-text, CanvasText) 8%, var(--folio-agent-surface, Canvas));\n border: 1px solid color-mix(in srgb, var(--folio-agent-text, CanvasText) 16%, var(--folio-agent-surface, Canvas));\n border-radius: 8px;\n padding: 10px 14px;\n }\n .message.user {\n align-self: flex-end;\n background: color-mix(in srgb, var(--folio-agent-text, CanvasText) 14%, var(--folio-agent-surface, Canvas));\n border: 1px solid color-mix(in srgb, var(--folio-agent-text, CanvasText) 24%, var(--folio-agent-surface, Canvas));\n border-radius: 8px;\n padding: 10px 14px;\n }\n .disclosure {\n font-size: 12px;\n color: var(--folio-agent-muted, color-mix(in srgb, CanvasText 55%, Canvas));\n padding: 0 0 4px;\n }\n .disclosure a {\n color: #2563eb;\n }\n form {\n display: flex;\n border-top: 1px solid color-mix(in srgb, CanvasText 16%, Canvas);\n }\n input {\n flex: 1;\n border: none;\n background: transparent;\n color: inherit;\n padding: 10px;\n font-size: 14px;\n }\n input:focus {\n outline: none;\n }\n button[type=\"submit\"] {\n border: none;\n background: none;\n padding: 0 14px;\n cursor: pointer;\n color: var(--folio-agent-accent, CanvasText);\n font-weight: 600;\n }\n";
|
package/dist/styles.js
CHANGED
|
@@ -58,15 +58,15 @@ export const WIDGET_STYLES = `
|
|
|
58
58
|
}
|
|
59
59
|
.message.assistant {
|
|
60
60
|
align-self: flex-start;
|
|
61
|
-
background: color-mix(in srgb, CanvasText 8%, Canvas);
|
|
62
|
-
border: 1px solid color-mix(in srgb, CanvasText 16%, Canvas);
|
|
61
|
+
background: color-mix(in srgb, var(--folio-agent-text, CanvasText) 8%, var(--folio-agent-surface, Canvas));
|
|
62
|
+
border: 1px solid color-mix(in srgb, var(--folio-agent-text, CanvasText) 16%, var(--folio-agent-surface, Canvas));
|
|
63
63
|
border-radius: 8px;
|
|
64
64
|
padding: 10px 14px;
|
|
65
65
|
}
|
|
66
66
|
.message.user {
|
|
67
67
|
align-self: flex-end;
|
|
68
|
-
background: color-mix(in srgb, CanvasText 14%, Canvas);
|
|
69
|
-
border: 1px solid color-mix(in srgb, CanvasText 24%, Canvas);
|
|
68
|
+
background: color-mix(in srgb, var(--folio-agent-text, CanvasText) 14%, var(--folio-agent-surface, Canvas));
|
|
69
|
+
border: 1px solid color-mix(in srgb, var(--folio-agent-text, CanvasText) 24%, var(--folio-agent-surface, Canvas));
|
|
70
70
|
border-radius: 8px;
|
|
71
71
|
padding: 10px 14px;
|
|
72
72
|
}
|
package/dist/widget-element.js
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
import { WIDGET_STYLES } from "./styles.js";
|
|
2
|
-
const
|
|
2
|
+
const WIDGET_TEXT = {
|
|
3
|
+
ja: {
|
|
4
|
+
toggleAriaLabel: "チャットを開く",
|
|
5
|
+
inputPlaceholder: "メッセージを入力",
|
|
6
|
+
submitLabel: "送信",
|
|
7
|
+
disclosureText: "入力内容は品質改善のため記録されます。",
|
|
8
|
+
policyLinkText: "利用データの扱いについて",
|
|
9
|
+
configErrorText: "設定エラー: endpoint属性が指定されていません。",
|
|
10
|
+
answerFallbackText: "回答を取得できませんでした。しばらくしてから再度お試しください。",
|
|
11
|
+
networkErrorText: "通信エラーが発生しました。しばらくしてから再度お試しください。",
|
|
12
|
+
},
|
|
13
|
+
en: {
|
|
14
|
+
toggleAriaLabel: "Open chat",
|
|
15
|
+
inputPlaceholder: "Type a message",
|
|
16
|
+
submitLabel: "Send",
|
|
17
|
+
disclosureText: "Your input is logged for quality improvement.",
|
|
18
|
+
policyLinkText: "About data usage",
|
|
19
|
+
configErrorText: "Configuration error: the endpoint attribute is not set.",
|
|
20
|
+
answerFallbackText: "Couldn't get an answer. Please try again later.",
|
|
21
|
+
networkErrorText: "A network error occurred. Please try again later.",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
function resolveLanguage(value) {
|
|
25
|
+
return value === "en" ? "en" : "ja";
|
|
26
|
+
}
|
|
3
27
|
export class FolioAgentWidgetElement extends HTMLElement {
|
|
4
28
|
static tagName = "folio-agent-widget";
|
|
5
29
|
#open = false;
|
|
@@ -8,7 +32,9 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
8
32
|
#panelEl;
|
|
9
33
|
#messagesEl;
|
|
10
34
|
#inputEl;
|
|
35
|
+
#text = WIDGET_TEXT.ja;
|
|
11
36
|
connectedCallback() {
|
|
37
|
+
this.#text = WIDGET_TEXT[resolveLanguage(this.getAttribute("lang"))];
|
|
12
38
|
const root = this.attachShadow({ mode: "open" });
|
|
13
39
|
const style = document.createElement("style");
|
|
14
40
|
style.textContent = WIDGET_STYLES;
|
|
@@ -16,7 +42,7 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
16
42
|
const toggle = document.createElement("button");
|
|
17
43
|
toggle.className = "toggle";
|
|
18
44
|
toggle.type = "button";
|
|
19
|
-
toggle.setAttribute("aria-label",
|
|
45
|
+
toggle.setAttribute("aria-label", this.#text.toggleAriaLabel);
|
|
20
46
|
toggle.textContent = "💬";
|
|
21
47
|
toggle.addEventListener("click", () => this.#togglePanel());
|
|
22
48
|
root.appendChild(toggle);
|
|
@@ -29,11 +55,11 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
29
55
|
const form = document.createElement("form");
|
|
30
56
|
const input = document.createElement("input");
|
|
31
57
|
input.type = "text";
|
|
32
|
-
input.placeholder =
|
|
58
|
+
input.placeholder = this.#text.inputPlaceholder;
|
|
33
59
|
input.autocomplete = "off";
|
|
34
60
|
const submit = document.createElement("button");
|
|
35
61
|
submit.type = "submit";
|
|
36
|
-
submit.textContent =
|
|
62
|
+
submit.textContent = this.#text.submitLabel;
|
|
37
63
|
form.appendChild(input);
|
|
38
64
|
form.appendChild(submit);
|
|
39
65
|
form.addEventListener("submit", (event) => {
|
|
@@ -66,14 +92,14 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
66
92
|
return;
|
|
67
93
|
const disclosure = document.createElement("div");
|
|
68
94
|
disclosure.className = "disclosure";
|
|
69
|
-
disclosure.append(`${
|
|
95
|
+
disclosure.append(`${this.#text.disclosureText} `);
|
|
70
96
|
const policyHref = this.getAttribute("policy-href");
|
|
71
97
|
if (policyHref) {
|
|
72
98
|
const link = document.createElement("a");
|
|
73
99
|
link.href = policyHref;
|
|
74
100
|
link.target = "_blank";
|
|
75
101
|
link.rel = "noopener noreferrer";
|
|
76
|
-
link.textContent =
|
|
102
|
+
link.textContent = this.#text.policyLinkText;
|
|
77
103
|
disclosure.appendChild(link);
|
|
78
104
|
}
|
|
79
105
|
this.#messagesEl.appendChild(disclosure);
|
|
@@ -85,7 +111,7 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
85
111
|
this.#appendMessage({ role: "user", text });
|
|
86
112
|
const endpoint = this.getAttribute("endpoint");
|
|
87
113
|
if (!endpoint) {
|
|
88
|
-
this.#appendMessage({ role: "assistant", text:
|
|
114
|
+
this.#appendMessage({ role: "assistant", text: this.#text.configErrorText });
|
|
89
115
|
return;
|
|
90
116
|
}
|
|
91
117
|
try {
|
|
@@ -97,13 +123,13 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
97
123
|
const body = (await response.json());
|
|
98
124
|
this.#appendMessage({
|
|
99
125
|
role: "assistant",
|
|
100
|
-
text: body.answer ??
|
|
126
|
+
text: body.answer ?? this.#text.answerFallbackText,
|
|
101
127
|
});
|
|
102
128
|
}
|
|
103
129
|
catch {
|
|
104
130
|
this.#appendMessage({
|
|
105
131
|
role: "assistant",
|
|
106
|
-
text:
|
|
132
|
+
text: this.#text.networkErrorText,
|
|
107
133
|
});
|
|
108
134
|
}
|
|
109
135
|
}
|