@agentiffai/design 1.3.7 → 1.3.8

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.
@@ -4,6 +4,7 @@ var button = require('@react-aria/button');
4
4
  var react = require('react');
5
5
  var styled8 = require('styled-components');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
+ var reactCore = require('@copilotkit/react-core');
7
8
  var reactUi = require('@copilotkit/react-ui');
8
9
  var textfield = require('@react-aria/textfield');
9
10
 
@@ -1224,6 +1225,77 @@ var TOOL_CALL_MARKER_REGEX = /<!--TOOL_CALL:([^:]+):(.+?)-->/g;
1224
1225
  function stripToolCallMarkers(content) {
1225
1226
  return content.replace(TOOL_CALL_MARKER_REGEX, "").trim();
1226
1227
  }
1228
+ var ERROR_PATTERNS = [
1229
+ /\bfailed\b/i,
1230
+ /\berror\b/i,
1231
+ /\bunable to\b/i,
1232
+ /\bcouldn't\b/i,
1233
+ /\bcan't\b/i,
1234
+ /\bcannot\b/i,
1235
+ /\bsomething went wrong\b/i,
1236
+ /\btry again\b/i,
1237
+ /\bunexpected\b/i,
1238
+ /\btimed out\b/i,
1239
+ /\bconnection\b.*\b(lost|failed|refused)\b/i
1240
+ ];
1241
+ var CORRELATION_ID_PATTERNS = [
1242
+ /reference:\s*([a-f0-9-]+)/i,
1243
+ /correlation[_\s]?id:\s*([a-f0-9-]+)/i,
1244
+ /\[([a-f0-9]{8,})\]/i
1245
+ ];
1246
+ function inferErrorCategory(content) {
1247
+ const lowerContent = content.toLowerCase();
1248
+ if (lowerContent.includes("network") || lowerContent.includes("internet") || lowerContent.includes("connection") || lowerContent.includes("offline") || lowerContent.includes("timed out")) {
1249
+ return "Network";
1250
+ }
1251
+ if (lowerContent.includes("unauthorized") || lowerContent.includes("authentication") || lowerContent.includes("login") || lowerContent.includes("session expired") || lowerContent.includes("credentials")) {
1252
+ return "Auth";
1253
+ }
1254
+ if (lowerContent.includes("oauth") || lowerContent.includes("reconnect") || lowerContent.includes("authorization") || lowerContent.includes("token") && lowerContent.includes("expired")) {
1255
+ return "OAuth";
1256
+ }
1257
+ if (lowerContent.includes("workflow") || lowerContent.includes("execution") || lowerContent.includes("failed to start") || lowerContent.includes("automation")) {
1258
+ return "Workflow";
1259
+ }
1260
+ return "Unknown";
1261
+ }
1262
+ function extractCorrelationId(content) {
1263
+ for (const pattern of CORRELATION_ID_PATTERNS) {
1264
+ const match = content.match(pattern);
1265
+ if (match?.[1]) {
1266
+ return match[1];
1267
+ }
1268
+ }
1269
+ return void 0;
1270
+ }
1271
+ function detectErrorInMessage(content) {
1272
+ const hasError = ERROR_PATTERNS.some((pattern) => pattern.test(content));
1273
+ if (!hasError) {
1274
+ return { hasError: false };
1275
+ }
1276
+ return {
1277
+ hasError: true,
1278
+ category: inferErrorCategory(content),
1279
+ correlationId: extractCorrelationId(content),
1280
+ errorMessage: content
1281
+ };
1282
+ }
1283
+ function buildChatSnippet(messages, errorMessageContent, maxMessages = 5, maxLength = 1500) {
1284
+ const recentMessages = messages.filter((msg) => msg.content && msg.content !== errorMessageContent).slice(-maxMessages);
1285
+ const formattedMessages = recentMessages.map((msg) => {
1286
+ const role = msg.role === "user" ? "User" : "Assistant";
1287
+ const content = msg.content || "";
1288
+ const truncatedContent = content.length > 300 ? content.slice(0, 300) + "..." : content;
1289
+ return `[${role}]: ${truncatedContent}`;
1290
+ });
1291
+ const errorSnippet = errorMessageContent.length > 500 ? errorMessageContent.slice(0, 500) + "..." : errorMessageContent;
1292
+ formattedMessages.push(`[Assistant - Error]: ${errorSnippet}`);
1293
+ let result = formattedMessages.join("\n\n");
1294
+ if (result.length > maxLength) {
1295
+ result = result.slice(0, maxLength) + "\n...[truncated]";
1296
+ }
1297
+ return result;
1298
+ }
1227
1299
  var GenerativeUIContainer = styled8__default.default.div`
1228
1300
  margin-top: ${tokens.spacing.sm};
1229
1301
  margin-bottom: ${tokens.spacing.sm};
@@ -1319,6 +1391,95 @@ function createAssistantMessageAdapter(ThinkingIndicator, ToolCallsComponent) {
1319
1391
  CustomAssistantMessageAdapter.displayName = "CustomAssistantMessageAdapter";
1320
1392
  return react.memo(CustomAssistantMessageAdapter);
1321
1393
  }
1394
+ function createAssistantMessageAdapterWithErrorReporting(onReportIssue, ThinkingIndicator, ToolCallsComponent) {
1395
+ const ErrorReportingAssistantMessageAdapter = ({
1396
+ message,
1397
+ isLoading,
1398
+ isGenerating,
1399
+ isCurrentMessage
1400
+ }) => {
1401
+ const { visibleMessages } = reactCore.useCopilotChat();
1402
+ const showThinking = isLoading || isGenerating && !message?.content;
1403
+ const shouldShowToolCalls = isCurrentMessage && ToolCallsComponent;
1404
+ const rawContent = message?.content || "";
1405
+ const content = stripToolCallMarkers(rawContent);
1406
+ const errorContext = react.useMemo(() => detectErrorInMessage(content), [content]);
1407
+ const chatSnippet = react.useMemo(() => {
1408
+ if (!errorContext.hasError) return "";
1409
+ return buildChatSnippet(visibleMessages, content);
1410
+ }, [visibleMessages, content, errorContext.hasError]);
1411
+ const actions = react.useMemo(() => {
1412
+ if (!errorContext.hasError || !onReportIssue || isGenerating) {
1413
+ return [];
1414
+ }
1415
+ return [
1416
+ {
1417
+ label: "Report Issue",
1418
+ onClick: () => {
1419
+ onReportIssue({
1420
+ errorCategory: errorContext.category,
1421
+ correlationId: errorContext.correlationId,
1422
+ // Include conversation history leading to the error
1423
+ chatSnippet
1424
+ });
1425
+ },
1426
+ icon: /* @__PURE__ */ jsxRuntime.jsxs(
1427
+ "svg",
1428
+ {
1429
+ width: "14",
1430
+ height: "14",
1431
+ viewBox: "0 0 24 24",
1432
+ fill: "none",
1433
+ stroke: "currentColor",
1434
+ strokeWidth: "2",
1435
+ strokeLinecap: "round",
1436
+ strokeLinejoin: "round",
1437
+ children: [
1438
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
1439
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
1440
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
1441
+ ]
1442
+ }
1443
+ )
1444
+ }
1445
+ ];
1446
+ }, [errorContext, chatSnippet, isGenerating]);
1447
+ let generativeUIOutput = null;
1448
+ const msgWithUI = message;
1449
+ if (msgWithUI && typeof msgWithUI.generativeUI === "function") {
1450
+ try {
1451
+ generativeUIOutput = msgWithUI.generativeUI();
1452
+ } catch (e) {
1453
+ console.warn("[AssistantMessageAdapter] Error rendering generativeUI:", e);
1454
+ }
1455
+ }
1456
+ const attachments = [];
1457
+ if (showThinking) {
1458
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1459
+ ThinkingIndicator ? /* @__PURE__ */ jsxRuntime.jsx(ThinkingIndicator, { isLoading, isGenerating }) : /* @__PURE__ */ jsxRuntime.jsx(AssistantThinking, { message: "Thinking..." }),
1460
+ shouldShowToolCalls && /* @__PURE__ */ jsxRuntime.jsx(ToolCallsComponent, {})
1461
+ ] });
1462
+ }
1463
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1464
+ shouldShowToolCalls && /* @__PURE__ */ jsxRuntime.jsx(ToolCallsComponent, {}),
1465
+ generativeUIOutput && /* @__PURE__ */ jsxRuntime.jsx(GenerativeUIContainer, { children: generativeUIOutput }),
1466
+ content && /* @__PURE__ */ jsxRuntime.jsx(
1467
+ AssistantMessage,
1468
+ {
1469
+ content,
1470
+ avatarInitials: "AI",
1471
+ isLoading: false,
1472
+ isStreaming: isGenerating,
1473
+ attachments,
1474
+ enableMarkdown: true,
1475
+ actions
1476
+ }
1477
+ )
1478
+ ] });
1479
+ };
1480
+ ErrorReportingAssistantMessageAdapter.displayName = "ErrorReportingAssistantMessageAdapter";
1481
+ return react.memo(ErrorReportingAssistantMessageAdapter);
1482
+ }
1322
1483
  var ChatInputContainer = styled8__default.default.div`
1323
1484
  display: flex;
1324
1485
  flex-direction: column;
@@ -2917,7 +3078,8 @@ function CustomCopilotSidebar2({
2917
3078
  onError,
2918
3079
  renderError,
2919
3080
  ThinkingIndicator,
2920
- ToolCallsComponent
3081
+ ToolCallsComponent,
3082
+ onReportIssue
2921
3083
  }) {
2922
3084
  const HeaderAdapterWithClose = react.useMemo(
2923
3085
  () => createHeaderAdapter(onSetOpen),
@@ -2928,8 +3090,8 @@ function CustomCopilotSidebar2({
2928
3090
  [disabled, disabledReason, onSetOpen]
2929
3091
  );
2930
3092
  const AssistantMessageAdapterMemo = react.useMemo(
2931
- () => ThinkingIndicator || ToolCallsComponent ? createAssistantMessageAdapter(ThinkingIndicator, ToolCallsComponent) : AssistantMessageAdapter,
2932
- [ThinkingIndicator, ToolCallsComponent]
3093
+ () => onReportIssue ? createAssistantMessageAdapterWithErrorReporting(onReportIssue, ThinkingIndicator, ToolCallsComponent) : ThinkingIndicator || ToolCallsComponent ? createAssistantMessageAdapter(ThinkingIndicator, ToolCallsComponent) : AssistantMessageAdapter,
3094
+ [ThinkingIndicator, ToolCallsComponent, onReportIssue]
2933
3095
  );
2934
3096
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2935
3097
  /* @__PURE__ */ jsxRuntime.jsx(GlobalSidebarStyles2, {}),