@hef2024/llmasaservice-ui 0.20.3 → 0.21.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/dist/index.js +41 -31
- package/dist/index.mjs +41 -31
- package/package.json +1 -1
- package/src/AIAgentPanel.tsx +60 -47
package/dist/index.js
CHANGED
|
@@ -5952,22 +5952,6 @@ var AIAgentPanel = import_react14.default.forwardRef(({
|
|
|
5952
5952
|
}
|
|
5953
5953
|
}
|
|
5954
5954
|
}), [apiKey, customerId, getAgent, fetchFirstPrompt]);
|
|
5955
|
-
const stripContextFromPrompt = (0, import_react14.useCallback)((prompt) => {
|
|
5956
|
-
let cleanPrompt = prompt;
|
|
5957
|
-
const contextIndex = cleanPrompt.indexOf("---context---");
|
|
5958
|
-
if (contextIndex !== -1) {
|
|
5959
|
-
cleanPrompt = cleanPrompt.substring(0, contextIndex).trim();
|
|
5960
|
-
}
|
|
5961
|
-
const isoTimestampRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z:/;
|
|
5962
|
-
if (isoTimestampRegex.test(cleanPrompt)) {
|
|
5963
|
-
const colonIndex = cleanPrompt.indexOf(":", 19);
|
|
5964
|
-
cleanPrompt = cleanPrompt.substring(colonIndex + 1);
|
|
5965
|
-
} else if (/^\d+:/.test(cleanPrompt)) {
|
|
5966
|
-
const colonIndex = cleanPrompt.indexOf(":");
|
|
5967
|
-
cleanPrompt = cleanPrompt.substring(colonIndex + 1);
|
|
5968
|
-
}
|
|
5969
|
-
return cleanPrompt.trim();
|
|
5970
|
-
}, []);
|
|
5971
5955
|
const loadConversationTranscript = (0, import_react14.useCallback)((conversationId, agentIdForConversation, title) => __async(void 0, null, function* () {
|
|
5972
5956
|
var _a2;
|
|
5973
5957
|
const existingActive = activeConversationsRef.current.get(conversationId);
|
|
@@ -6004,23 +5988,49 @@ var AIAgentPanel = import_react14.default.forwardRef(({
|
|
|
6004
5988
|
const history = {};
|
|
6005
5989
|
let firstPrompt = null;
|
|
6006
5990
|
if (Array.isArray(payload) && payload.length > 0) {
|
|
6007
|
-
payload.
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
5991
|
+
const lastCall = payload[payload.length - 1];
|
|
5992
|
+
const callId = lastCall.id || "";
|
|
5993
|
+
const timestamp = lastCall.createdAt || lastCall.created_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
5994
|
+
if (lastCall.messages) {
|
|
5995
|
+
try {
|
|
5996
|
+
const messages2 = JSON.parse(lastCall.messages);
|
|
5997
|
+
console.log("loadConversationTranscript - parsed messages:", messages2);
|
|
5998
|
+
const relevantMessages = messages2.filter(
|
|
5999
|
+
(msg) => msg.role !== "system" && !(msg.role === "user" && msg.content.startsWith("__system__:"))
|
|
6000
|
+
);
|
|
6001
|
+
console.log("loadConversationTranscript - filtered messages:", relevantMessages);
|
|
6002
|
+
for (let i = 0; i < relevantMessages.length; i++) {
|
|
6003
|
+
const msg = relevantMessages[i];
|
|
6004
|
+
if (!msg) continue;
|
|
6005
|
+
if (msg.role === "user") {
|
|
6006
|
+
if (!firstPrompt) {
|
|
6007
|
+
firstPrompt = msg.content.length > 60 ? msg.content.slice(0, 57) + "..." : msg.content;
|
|
6008
|
+
}
|
|
6009
|
+
const nextMsg = relevantMessages[i + 1];
|
|
6010
|
+
if (nextMsg && nextMsg.role === "assistant") {
|
|
6011
|
+
const historyKey = `${timestamp}:${msg.content}`;
|
|
6012
|
+
history[historyKey] = {
|
|
6013
|
+
content: nextMsg.content,
|
|
6014
|
+
callId
|
|
6015
|
+
};
|
|
6016
|
+
i++;
|
|
6017
|
+
} else {
|
|
6018
|
+
if (lastCall.response) {
|
|
6019
|
+
const historyKey = `${timestamp}:${msg.content}`;
|
|
6020
|
+
history[historyKey] = {
|
|
6021
|
+
content: lastCall.response,
|
|
6022
|
+
callId
|
|
6023
|
+
};
|
|
6024
|
+
}
|
|
6025
|
+
}
|
|
6026
|
+
}
|
|
6014
6027
|
}
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
history[historyKey] = {
|
|
6018
|
-
content: call.response,
|
|
6019
|
-
callId: call.id || ""
|
|
6020
|
-
};
|
|
6028
|
+
} catch (err) {
|
|
6029
|
+
console.error("loadConversationTranscript - failed to parse messages property:", err);
|
|
6021
6030
|
}
|
|
6022
|
-
}
|
|
6031
|
+
}
|
|
6023
6032
|
}
|
|
6033
|
+
console.log("loadConversationTranscript - created", Object.keys(history).length, "history entries");
|
|
6024
6034
|
console.log("loadConversationTranscript - parsed history:", history);
|
|
6025
6035
|
if (firstPrompt) {
|
|
6026
6036
|
setConversationFirstPrompts((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
@@ -6051,7 +6061,7 @@ var AIAgentPanel = import_react14.default.forwardRef(({
|
|
|
6051
6061
|
setConversationsError(error.message || "Failed to load conversation");
|
|
6052
6062
|
setLoadingConversationId(null);
|
|
6053
6063
|
}
|
|
6054
|
-
}), [apiKey, currentAgentId, getAgent, onConversationChange
|
|
6064
|
+
}), [apiKey, currentAgentId, getAgent, onConversationChange]);
|
|
6055
6065
|
const handleRefreshConversations = (0, import_react14.useCallback)(() => {
|
|
6056
6066
|
fetchConversations(currentAgentId);
|
|
6057
6067
|
}, [currentAgentId, fetchConversations]);
|
package/dist/index.mjs
CHANGED
|
@@ -5919,22 +5919,6 @@ var AIAgentPanel = React13.forwardRef(({
|
|
|
5919
5919
|
}
|
|
5920
5920
|
}
|
|
5921
5921
|
}), [apiKey, customerId, getAgent, fetchFirstPrompt]);
|
|
5922
|
-
const stripContextFromPrompt = useCallback4((prompt) => {
|
|
5923
|
-
let cleanPrompt = prompt;
|
|
5924
|
-
const contextIndex = cleanPrompt.indexOf("---context---");
|
|
5925
|
-
if (contextIndex !== -1) {
|
|
5926
|
-
cleanPrompt = cleanPrompt.substring(0, contextIndex).trim();
|
|
5927
|
-
}
|
|
5928
|
-
const isoTimestampRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z:/;
|
|
5929
|
-
if (isoTimestampRegex.test(cleanPrompt)) {
|
|
5930
|
-
const colonIndex = cleanPrompt.indexOf(":", 19);
|
|
5931
|
-
cleanPrompt = cleanPrompt.substring(colonIndex + 1);
|
|
5932
|
-
} else if (/^\d+:/.test(cleanPrompt)) {
|
|
5933
|
-
const colonIndex = cleanPrompt.indexOf(":");
|
|
5934
|
-
cleanPrompt = cleanPrompt.substring(colonIndex + 1);
|
|
5935
|
-
}
|
|
5936
|
-
return cleanPrompt.trim();
|
|
5937
|
-
}, []);
|
|
5938
5922
|
const loadConversationTranscript = useCallback4((conversationId, agentIdForConversation, title) => __async(void 0, null, function* () {
|
|
5939
5923
|
var _a2;
|
|
5940
5924
|
const existingActive = activeConversationsRef.current.get(conversationId);
|
|
@@ -5971,23 +5955,49 @@ var AIAgentPanel = React13.forwardRef(({
|
|
|
5971
5955
|
const history = {};
|
|
5972
5956
|
let firstPrompt = null;
|
|
5973
5957
|
if (Array.isArray(payload) && payload.length > 0) {
|
|
5974
|
-
payload.
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5958
|
+
const lastCall = payload[payload.length - 1];
|
|
5959
|
+
const callId = lastCall.id || "";
|
|
5960
|
+
const timestamp = lastCall.createdAt || lastCall.created_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
5961
|
+
if (lastCall.messages) {
|
|
5962
|
+
try {
|
|
5963
|
+
const messages2 = JSON.parse(lastCall.messages);
|
|
5964
|
+
console.log("loadConversationTranscript - parsed messages:", messages2);
|
|
5965
|
+
const relevantMessages = messages2.filter(
|
|
5966
|
+
(msg) => msg.role !== "system" && !(msg.role === "user" && msg.content.startsWith("__system__:"))
|
|
5967
|
+
);
|
|
5968
|
+
console.log("loadConversationTranscript - filtered messages:", relevantMessages);
|
|
5969
|
+
for (let i = 0; i < relevantMessages.length; i++) {
|
|
5970
|
+
const msg = relevantMessages[i];
|
|
5971
|
+
if (!msg) continue;
|
|
5972
|
+
if (msg.role === "user") {
|
|
5973
|
+
if (!firstPrompt) {
|
|
5974
|
+
firstPrompt = msg.content.length > 60 ? msg.content.slice(0, 57) + "..." : msg.content;
|
|
5975
|
+
}
|
|
5976
|
+
const nextMsg = relevantMessages[i + 1];
|
|
5977
|
+
if (nextMsg && nextMsg.role === "assistant") {
|
|
5978
|
+
const historyKey = `${timestamp}:${msg.content}`;
|
|
5979
|
+
history[historyKey] = {
|
|
5980
|
+
content: nextMsg.content,
|
|
5981
|
+
callId
|
|
5982
|
+
};
|
|
5983
|
+
i++;
|
|
5984
|
+
} else {
|
|
5985
|
+
if (lastCall.response) {
|
|
5986
|
+
const historyKey = `${timestamp}:${msg.content}`;
|
|
5987
|
+
history[historyKey] = {
|
|
5988
|
+
content: lastCall.response,
|
|
5989
|
+
callId
|
|
5990
|
+
};
|
|
5991
|
+
}
|
|
5992
|
+
}
|
|
5993
|
+
}
|
|
5981
5994
|
}
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
history[historyKey] = {
|
|
5985
|
-
content: call.response,
|
|
5986
|
-
callId: call.id || ""
|
|
5987
|
-
};
|
|
5995
|
+
} catch (err) {
|
|
5996
|
+
console.error("loadConversationTranscript - failed to parse messages property:", err);
|
|
5988
5997
|
}
|
|
5989
|
-
}
|
|
5998
|
+
}
|
|
5990
5999
|
}
|
|
6000
|
+
console.log("loadConversationTranscript - created", Object.keys(history).length, "history entries");
|
|
5991
6001
|
console.log("loadConversationTranscript - parsed history:", history);
|
|
5992
6002
|
if (firstPrompt) {
|
|
5993
6003
|
setConversationFirstPrompts((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
@@ -6018,7 +6028,7 @@ var AIAgentPanel = React13.forwardRef(({
|
|
|
6018
6028
|
setConversationsError(error.message || "Failed to load conversation");
|
|
6019
6029
|
setLoadingConversationId(null);
|
|
6020
6030
|
}
|
|
6021
|
-
}), [apiKey, currentAgentId, getAgent, onConversationChange
|
|
6031
|
+
}), [apiKey, currentAgentId, getAgent, onConversationChange]);
|
|
6022
6032
|
const handleRefreshConversations = useCallback4(() => {
|
|
6023
6033
|
fetchConversations(currentAgentId);
|
|
6024
6034
|
}, [currentAgentId, fetchConversations]);
|
package/package.json
CHANGED
package/src/AIAgentPanel.tsx
CHANGED
|
@@ -1092,28 +1092,6 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
|
|
|
1092
1092
|
}, [apiKey, customerId, getAgent, fetchFirstPrompt]);
|
|
1093
1093
|
|
|
1094
1094
|
// Helper to strip context/template data from a prompt - keeps only the user's actual message
|
|
1095
|
-
const stripContextFromPrompt = useCallback((prompt: string): string => {
|
|
1096
|
-
let cleanPrompt = prompt;
|
|
1097
|
-
|
|
1098
|
-
// Strip ---context--- block and everything after it
|
|
1099
|
-
const contextIndex = cleanPrompt.indexOf('---context---');
|
|
1100
|
-
if (contextIndex !== -1) {
|
|
1101
|
-
cleanPrompt = cleanPrompt.substring(0, contextIndex).trim();
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
// Strip timestamp prefix (ISO format: 2024-01-01T00:00:00.000Z:)
|
|
1105
|
-
const isoTimestampRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z:/;
|
|
1106
|
-
if (isoTimestampRegex.test(cleanPrompt)) {
|
|
1107
|
-
const colonIndex = cleanPrompt.indexOf(':', 19);
|
|
1108
|
-
cleanPrompt = cleanPrompt.substring(colonIndex + 1);
|
|
1109
|
-
} else if (/^\d+:/.test(cleanPrompt)) {
|
|
1110
|
-
const colonIndex = cleanPrompt.indexOf(':');
|
|
1111
|
-
cleanPrompt = cleanPrompt.substring(colonIndex + 1);
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
return cleanPrompt.trim();
|
|
1115
|
-
}, []);
|
|
1116
|
-
|
|
1117
1095
|
// Load a specific conversation's transcript (or switch to it if already active)
|
|
1118
1096
|
const loadConversationTranscript = useCallback(async (conversationId: string, agentIdForConversation?: string, title?: string) => {
|
|
1119
1097
|
// Check if conversation is already in activeConversations (use ref to avoid dependency)
|
|
@@ -1160,40 +1138,75 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
|
|
|
1160
1138
|
console.log('loadConversationTranscript - API response:', payload);
|
|
1161
1139
|
|
|
1162
1140
|
// The /calls endpoint returns an array of calls
|
|
1163
|
-
//
|
|
1164
|
-
// IMPORTANT: Strip context/template data from prompts to prevent token bloat
|
|
1141
|
+
// Use the messages property from the LAST call, which contains the full conversation history
|
|
1165
1142
|
const history: Record<string, { content: string; callId: string }> = {};
|
|
1166
1143
|
let firstPrompt: string | null = null;
|
|
1167
1144
|
|
|
1168
1145
|
if (Array.isArray(payload) && payload.length > 0) {
|
|
1169
|
-
//
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1146
|
+
// Get the last call - it contains the full conversation history in the messages property
|
|
1147
|
+
const lastCall = payload[payload.length - 1];
|
|
1148
|
+
const callId = lastCall.id || '';
|
|
1149
|
+
const timestamp = lastCall.createdAt || lastCall.created_at || new Date().toISOString();
|
|
1150
|
+
|
|
1151
|
+
if (lastCall.messages) {
|
|
1152
|
+
try {
|
|
1153
|
+
// Parse the messages JSON string
|
|
1154
|
+
const messages = JSON.parse(lastCall.messages) as { role: string; content: string }[];
|
|
1155
|
+
console.log('loadConversationTranscript - parsed messages:', messages);
|
|
1176
1156
|
|
|
1177
|
-
//
|
|
1178
|
-
const
|
|
1157
|
+
// Filter out system messages and special __system__: user messages
|
|
1158
|
+
const relevantMessages = messages.filter(msg =>
|
|
1159
|
+
msg.role !== 'system' &&
|
|
1160
|
+
!(msg.role === 'user' && msg.content.startsWith('__system__:'))
|
|
1161
|
+
);
|
|
1162
|
+
console.log('loadConversationTranscript - filtered messages:', relevantMessages);
|
|
1179
1163
|
|
|
1180
|
-
//
|
|
1181
|
-
|
|
1182
|
-
|
|
1164
|
+
// Pair user/assistant messages to build history
|
|
1165
|
+
// Note: The messages array contains the INPUT to the LLM (history + new prompt)
|
|
1166
|
+
// The LAST user message needs to be paired with the call's response field
|
|
1167
|
+
for (let i = 0; i < relevantMessages.length; i++) {
|
|
1168
|
+
const msg = relevantMessages[i];
|
|
1169
|
+
|
|
1170
|
+
if (!msg) continue;
|
|
1171
|
+
|
|
1172
|
+
if (msg.role === 'user') {
|
|
1173
|
+
// Extract first prompt for conversation title
|
|
1174
|
+
if (!firstPrompt) {
|
|
1175
|
+
firstPrompt = msg.content.length > 60 ? msg.content.slice(0, 57) + '...' : msg.content;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
// Look for the next assistant message in the array
|
|
1179
|
+
const nextMsg = relevantMessages[i + 1];
|
|
1180
|
+
|
|
1181
|
+
if (nextMsg && nextMsg.role === 'assistant') {
|
|
1182
|
+
// This is a historical turn - pair the user message with the assistant message from the array
|
|
1183
|
+
const historyKey = `${timestamp}:${msg.content}`;
|
|
1184
|
+
history[historyKey] = {
|
|
1185
|
+
content: nextMsg.content,
|
|
1186
|
+
callId: callId,
|
|
1187
|
+
};
|
|
1188
|
+
|
|
1189
|
+
// Skip the assistant message we just processed
|
|
1190
|
+
i++;
|
|
1191
|
+
} else {
|
|
1192
|
+
// This is the LAST user message - pair it with the response field
|
|
1193
|
+
if (lastCall.response) {
|
|
1194
|
+
const historyKey = `${timestamp}:${msg.content}`;
|
|
1195
|
+
history[historyKey] = {
|
|
1196
|
+
content: lastCall.response,
|
|
1197
|
+
callId: callId,
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1183
1202
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
const timestamp = call.createdAt || call.created_at || new Date().toISOString();
|
|
1187
|
-
const historyKey = `${timestamp}:${cleanedPrompt}`;
|
|
1188
|
-
|
|
1189
|
-
history[historyKey] = {
|
|
1190
|
-
content: call.response,
|
|
1191
|
-
callId: call.id || '',
|
|
1192
|
-
};
|
|
1203
|
+
} catch (err) {
|
|
1204
|
+
console.error('loadConversationTranscript - failed to parse messages property:', err);
|
|
1193
1205
|
}
|
|
1194
|
-
}
|
|
1206
|
+
}
|
|
1195
1207
|
}
|
|
1196
1208
|
|
|
1209
|
+
console.log('loadConversationTranscript - created', Object.keys(history).length, 'history entries');
|
|
1197
1210
|
console.log('loadConversationTranscript - parsed history:', history);
|
|
1198
1211
|
|
|
1199
1212
|
// Update first prompt in state if we found one
|
|
@@ -1234,7 +1247,7 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
|
|
|
1234
1247
|
// Clear loading state on error
|
|
1235
1248
|
setLoadingConversationId(null);
|
|
1236
1249
|
}
|
|
1237
|
-
}, [apiKey, currentAgentId, getAgent, onConversationChange
|
|
1250
|
+
}, [apiKey, currentAgentId, getAgent, onConversationChange]);
|
|
1238
1251
|
|
|
1239
1252
|
|
|
1240
1253
|
// Refresh conversations callback
|