llmasaservice-ui 0.3.9 → 0.3.11
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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -5
- package/dist/index.mjs +9 -5
- package/package.json +1 -1
- package/src/ChatPanel.tsx +9 -5
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -118,19 +118,21 @@ var ChatPanel = ({
|
|
|
118
118
|
actions.forEach((action, index) => {
|
|
119
119
|
const regex = new RegExp(action.pattern, "gmi");
|
|
120
120
|
newResponse = newResponse.replace(regex, (match, ...groups) => {
|
|
121
|
-
var _a;
|
|
121
|
+
var _a, _b;
|
|
122
122
|
console.log("match", match);
|
|
123
123
|
console.log("groups", groups);
|
|
124
124
|
const matchIndex = groups[groups.length - 2];
|
|
125
125
|
const buttonId = `button-${index}-${matchIndex}`;
|
|
126
|
+
console.log("buttonId", buttonId, action);
|
|
126
127
|
let html = match;
|
|
127
128
|
if (action.type === "button" || action.type === "callback") {
|
|
128
129
|
const button = document.getElementById(buttonId);
|
|
129
130
|
if (!button) {
|
|
130
|
-
|
|
131
|
+
console.log("Creating button", buttonId, action);
|
|
132
|
+
html = `<button id="${buttonId}">${(_a = action.markdown) != null ? _a : match}</button>`;
|
|
131
133
|
}
|
|
132
|
-
} else if (action.type === "markdown") {
|
|
133
|
-
html = (
|
|
134
|
+
} else if (action.type === "markdown" || action.type === "html") {
|
|
135
|
+
html = (_b = action.markdown) != null ? _b : "";
|
|
134
136
|
}
|
|
135
137
|
html = html.replace(new RegExp("\\$match", "g"), match);
|
|
136
138
|
groups.forEach((group, index2) => {
|
|
@@ -140,9 +142,10 @@ var ChatPanel = ({
|
|
|
140
142
|
const button = document.getElementById(buttonId);
|
|
141
143
|
if (button) {
|
|
142
144
|
if (!button.onclick) {
|
|
145
|
+
console.log("Setting button click event", buttonId, action);
|
|
143
146
|
button.onclick = () => {
|
|
144
147
|
if (action.callback) {
|
|
145
|
-
action.callback(match);
|
|
148
|
+
action.callback(match, groups);
|
|
146
149
|
}
|
|
147
150
|
if (action.clickCode) {
|
|
148
151
|
try {
|
|
@@ -156,6 +159,7 @@ var ChatPanel = ({
|
|
|
156
159
|
}
|
|
157
160
|
}
|
|
158
161
|
}, 0);
|
|
162
|
+
console.log("html", html);
|
|
159
163
|
return html;
|
|
160
164
|
});
|
|
161
165
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -85,19 +85,21 @@ var ChatPanel = ({
|
|
|
85
85
|
actions.forEach((action, index) => {
|
|
86
86
|
const regex = new RegExp(action.pattern, "gmi");
|
|
87
87
|
newResponse = newResponse.replace(regex, (match, ...groups) => {
|
|
88
|
-
var _a;
|
|
88
|
+
var _a, _b;
|
|
89
89
|
console.log("match", match);
|
|
90
90
|
console.log("groups", groups);
|
|
91
91
|
const matchIndex = groups[groups.length - 2];
|
|
92
92
|
const buttonId = `button-${index}-${matchIndex}`;
|
|
93
|
+
console.log("buttonId", buttonId, action);
|
|
93
94
|
let html = match;
|
|
94
95
|
if (action.type === "button" || action.type === "callback") {
|
|
95
96
|
const button = document.getElementById(buttonId);
|
|
96
97
|
if (!button) {
|
|
97
|
-
|
|
98
|
+
console.log("Creating button", buttonId, action);
|
|
99
|
+
html = `<button id="${buttonId}">${(_a = action.markdown) != null ? _a : match}</button>`;
|
|
98
100
|
}
|
|
99
|
-
} else if (action.type === "markdown") {
|
|
100
|
-
html = (
|
|
101
|
+
} else if (action.type === "markdown" || action.type === "html") {
|
|
102
|
+
html = (_b = action.markdown) != null ? _b : "";
|
|
101
103
|
}
|
|
102
104
|
html = html.replace(new RegExp("\\$match", "g"), match);
|
|
103
105
|
groups.forEach((group, index2) => {
|
|
@@ -107,9 +109,10 @@ var ChatPanel = ({
|
|
|
107
109
|
const button = document.getElementById(buttonId);
|
|
108
110
|
if (button) {
|
|
109
111
|
if (!button.onclick) {
|
|
112
|
+
console.log("Setting button click event", buttonId, action);
|
|
110
113
|
button.onclick = () => {
|
|
111
114
|
if (action.callback) {
|
|
112
|
-
action.callback(match);
|
|
115
|
+
action.callback(match, groups);
|
|
113
116
|
}
|
|
114
117
|
if (action.clickCode) {
|
|
115
118
|
try {
|
|
@@ -123,6 +126,7 @@ var ChatPanel = ({
|
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
}, 0);
|
|
129
|
+
console.log("html", html);
|
|
126
130
|
return html;
|
|
127
131
|
});
|
|
128
132
|
});
|
package/package.json
CHANGED
package/src/ChatPanel.tsx
CHANGED
|
@@ -38,7 +38,7 @@ export interface ChatPanelProps {
|
|
|
38
38
|
pattern: string;
|
|
39
39
|
type?: string;
|
|
40
40
|
markdown?: string;
|
|
41
|
-
callback?: (match: string) => void;
|
|
41
|
+
callback?: (match: string, groups: any[]) => void;
|
|
42
42
|
clickCode?: string;
|
|
43
43
|
}[];
|
|
44
44
|
}
|
|
@@ -125,16 +125,17 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
125
125
|
console.log("groups", groups);
|
|
126
126
|
|
|
127
127
|
const matchIndex = groups[groups.length - 2]; // The second-to-last argument is the match index
|
|
128
|
-
|
|
129
128
|
const buttonId = `button-${index}-${matchIndex}`;
|
|
129
|
+
console.log("buttonId", buttonId, action);
|
|
130
130
|
|
|
131
131
|
let html = match;
|
|
132
132
|
if (action.type === "button" || action.type === "callback") {
|
|
133
133
|
const button = document.getElementById(buttonId);
|
|
134
134
|
if (!button) {
|
|
135
|
-
|
|
135
|
+
console.log("Creating button", buttonId, action);
|
|
136
|
+
html = `<button id="${buttonId}">${action.markdown ?? match}</button>`;
|
|
136
137
|
}
|
|
137
|
-
} else if (action.type === "markdown") {
|
|
138
|
+
} else if (action.type === "markdown" || action.type === "html") {
|
|
138
139
|
html = action.markdown ?? "";
|
|
139
140
|
}
|
|
140
141
|
|
|
@@ -147,9 +148,10 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
147
148
|
const button = document.getElementById(buttonId);
|
|
148
149
|
if (button) {
|
|
149
150
|
if (!button.onclick) {
|
|
151
|
+
console.log("Setting button click event", buttonId, action);
|
|
150
152
|
button.onclick = () => {
|
|
151
153
|
if (action.callback) {
|
|
152
|
-
action.callback(match);
|
|
154
|
+
action.callback(match, groups);
|
|
153
155
|
}
|
|
154
156
|
if (action.clickCode) {
|
|
155
157
|
try {
|
|
@@ -163,6 +165,8 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
163
165
|
}
|
|
164
166
|
}
|
|
165
167
|
}, 0);
|
|
168
|
+
|
|
169
|
+
console.log("html", html);
|
|
166
170
|
return html;
|
|
167
171
|
});
|
|
168
172
|
});
|