@burtson-labs/bandit-engine 2.0.103 → 2.0.105

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 CHANGED
@@ -21532,7 +21532,7 @@ TOOL USAGE PROTOCOL (conservative approach)
21532
21532
  * web_search() - when asked about recent/current events, breaking news, live information (weather, prices, sports scores), or when you need to look up documentation, libraries, APIs, error messages, or verify a specific fact
21533
21533
  * web_fetch() - to read the FULL contents of a specific URL you already have. Reach for this when the user wants to "tell me more", "go deeper", "read/open that article", or asks for details about a specific source, link, or article from an EARLIER answer: take that item's URL from the previous Sources list in this conversation and fetch it, then answer from the page's actual content (not just the prior summary)
21534
21534
  * image_generation() - ONLY when explicitly asked to create or generate an image
21535
- * create_file({"content": "...", "filename": "report.docx", "format": "docx"}) - when the user asks for a downloadable FILE (a document, spreadsheet, slides, markdown, code, etc.) or to "export"/"download"/"save" something. Formats: md, txt, csv, json, html, xml, yaml, docx, pptx. For docx/pptx write well-structured Markdown (use "## " headings to start each slide for pptx). It returns a temporary download link \u2014 ALWAYS tell the user the file expires (~1 hour). If it is unclear whether they want it shown inline vs. as a downloadable file, use ask_user first.
21535
+ * create_file({"content": "...", "filename": "report.docx", "format": "docx"}) - when the user asks for a downloadable FILE (a document, spreadsheet, slides, markdown, code, etc.) or to "export"/"download"/"save" something. Formats: md, txt, csv, json, html, xml, yaml, docx, pptx. PDF is NOT a supported format \u2014 if the user asks for a PDF, create a docx instead. For docx/pptx write well-structured Markdown (use "## " headings to start each slide for pptx). It returns a temporary download link \u2014 ALWAYS tell the user the file expires (~1 hour). If it is unclear whether they want it shown inline vs. as a downloadable file, use ask_user first.
21536
21536
  * ask_user({"questions": [{"question": "...", "header": "Format", "options": [{"label": "Inline (Recommended)"}, {"label": "Download a file"}]}]}) - when you are genuinely BLOCKED on a decision that is the USER's to make and cannot resolve from the request, context, or sensible defaults (e.g. show content inline vs. let them download it, which format/option they want). Renders clickable options the user answers in one step \u2014 better than asking in prose and ending your turn. Give 1-4 questions, each with 2-4 options; if one is clearly best, list it first and append " (Recommended)". The user may also type their own answer; act on it directly.
21537
21537
  - For general questions about concepts, definitions, explanations, or how-to topics, use your built-in knowledge WITHOUT calling tools.
21538
21538
  - Examples of what NOT to use tools for: "who are you?", "what is React?", "explain machine learning", "how does X work?", general programming questions.
@@ -21718,16 +21718,50 @@ ${fn}(${argStr})
21718
21718
  \`\`\``;
21719
21719
  }
21720
21720
  }
21721
- if (!/```(?:tool_code|TOOL_CODE)/.test(fullMessage)) {
21722
- const plainToolFence = /```[a-zA-Z0-9_-]*[ \t]*\n([ \t]*(?:web_search|web_fetch|image_generation|create_file|ask_user)[\s\S]*?)\n```/;
21723
- const fm = fullMessage.match(plainToolFence);
21724
- if (fm) {
21725
- fullMessage = fullMessage.replace(plainToolFence, `\`\`\`tool_code
21726
- ${fm[1].trim()}
21727
- \`\`\``);
21721
+ const extractToolCalls = (message) => {
21722
+ const KNOWN = ["web_search", "web_fetch", "image_generation", "create_file", "ask_user", "ask-user"];
21723
+ const out = [];
21724
+ const nameRe = new RegExp(`\\b(${KNOWN.join("|")})\\s*\\(`, "g");
21725
+ let m;
21726
+ while ((m = nameRe.exec(message)) !== null) {
21727
+ const functionName = m[1];
21728
+ const openIdx = m.index + m[0].length - 1;
21729
+ let depth = 0;
21730
+ let i = openIdx;
21731
+ let inStr = false;
21732
+ let esc = false;
21733
+ for (; i < message.length; i++) {
21734
+ const ch = message[i];
21735
+ if (inStr) {
21736
+ if (esc) esc = false;
21737
+ else if (ch === "\\") esc = true;
21738
+ else if (ch === '"') inStr = false;
21739
+ } else if (ch === '"') inStr = true;
21740
+ else if (ch === "(") depth++;
21741
+ else if (ch === ")") {
21742
+ depth--;
21743
+ if (depth === 0) {
21744
+ i++;
21745
+ break;
21746
+ }
21747
+ }
21748
+ }
21749
+ if (depth !== 0) continue;
21750
+ const params = message.slice(openIdx + 1, i - 1).trim();
21751
+ let start = m.index;
21752
+ let end = i;
21753
+ const fenceOpen = message.slice(0, m.index).match(/```[a-zA-Z0-9_-]*[ \t]*\n[ \t]*$/);
21754
+ if (fenceOpen) {
21755
+ start = m.index - fenceOpen[0].length;
21756
+ const fenceClose = message.slice(i).match(/^[ \t]*\n```/);
21757
+ if (fenceClose) end = i + fenceClose[0].length;
21758
+ }
21759
+ out.push({ raw: message.slice(start, end), functionName, params });
21760
+ nameRe.lastIndex = i;
21728
21761
  }
21729
- }
21730
- const toolCallMatches = fullMessage.match(/```(?:tool_code|TOOL_CODE)\s*\n([^`]+)\n```/gi);
21762
+ return out;
21763
+ };
21764
+ const toolCallMatches = extractToolCalls(fullMessage);
21731
21765
  let enhancedMessage = fullMessage;
21732
21766
  const summarizableResults = [];
21733
21767
  const inlineImageBlocks = [];
@@ -21735,13 +21769,10 @@ ${fm[1].trim()}
21735
21769
  if (toolCallMatches && toolCallMatches.length > 0 && mcpToolsAvailable) {
21736
21770
  debugLogger.info("Detected tool calls in AI response", {
21737
21771
  toolCallCount: toolCallMatches.length,
21738
- toolCalls: toolCallMatches
21772
+ toolCalls: toolCallMatches.map((t) => t.functionName)
21739
21773
  });
21740
- for (const match of toolCallMatches) {
21741
- const toolCallCode = match.replace(/```(?:tool_code|TOOL_CODE)\s*\n|\n```/gi, "").trim();
21742
- const functionCallMatch = toolCallCode.match(/^(\w+)\(\s*(.*?)\s*\)$/);
21743
- if (!functionCallMatch) continue;
21744
- const [, functionName, params] = functionCallMatch;
21774
+ for (const call of toolCallMatches) {
21775
+ const { raw: match, functionName, params } = call;
21745
21776
  try {
21746
21777
  let parsedParams = {};
21747
21778
  const raw = params.trim();
@@ -35231,10 +35262,10 @@ var PersonalitiesTab = ({
35231
35262
  display: "flex",
35232
35263
  alignItems: "center",
35233
35264
  justifyContent: "center",
35234
- minWidth: { xs: "42px", sm: "48px" },
35235
- height: { xs: "42px", sm: "48px" },
35265
+ minWidth: { xs: "36px", sm: "38px" },
35266
+ height: { xs: "36px", sm: "38px" },
35236
35267
  boxShadow: "0 4px 12px rgba(25,118,210,0.25)"
35237
- }, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(RocketLaunchOutlinedIcon, { sx: { fontSize: { xs: "1.3rem", sm: "1.5rem" }, color: "common.white" } }) }),
35268
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(RocketLaunchOutlinedIcon, { sx: { fontSize: { xs: "1.15rem", sm: "1.25rem" }, color: "common.white" } }) }),
35238
35269
  /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_material40.Box, { sx: { textAlign: { xs: "left", md: "initial" }, flex: 1 }, children: [
35239
35270
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
35240
35271
  import_material40.Typography,
@@ -35247,7 +35278,7 @@ var PersonalitiesTab = ({
35247
35278
  WebkitBackgroundClip: "text",
35248
35279
  WebkitTextFillColor: "transparent",
35249
35280
  mb: { xs: 0.25, sm: 0.5 },
35250
- fontSize: { xs: "1.35rem", sm: "1.75rem" }
35281
+ fontSize: { xs: "1.2rem", sm: "1.35rem" }
35251
35282
  },
35252
35283
  children: "Quick Start Templates"
35253
35284
  }
@@ -35278,7 +35309,7 @@ var PersonalitiesTab = ({
35278
35309
  }
35279
35310
  )
35280
35311
  ] }),
35281
- isMobile ? /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
35312
+ isMobile && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
35282
35313
  import_material40.Box,
35283
35314
  {
35284
35315
  sx: {
@@ -35305,32 +35336,12 @@ var PersonalitiesTab = ({
35305
35336
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_material40.Collapse, { in: showTemplateHelp, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_material40.Typography, { variant: "body2", sx: { color: "text.secondary", fontSize: "0.8rem", lineHeight: 1.4, mt: 0.75 }, children: "Choose a setup you like, then tweak name, tone, and prompt details in the Create/Edit tab." }) })
35306
35337
  ]
35307
35338
  }
35308
- ) : /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
35309
- import_material40.Alert,
35310
- {
35311
- severity: "info",
35312
- sx: {
35313
- mb: { xs: 2.5, md: 4 },
35314
- borderRadius: 2,
35315
- border: "1px solid rgba(25, 118, 210, 0.2)",
35316
- background: "linear-gradient(135deg, rgba(25, 118, 210, 0.05) 0%, rgba(66, 165, 245, 0.05) 100%)",
35317
- px: { xs: 1.5, sm: 2 },
35318
- py: { xs: 1.25, sm: 1.5 },
35319
- "& .MuiAlert-icon": {
35320
- color: "primary.main"
35321
- }
35322
- },
35323
- children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_material40.Box, { sx: { display: "flex", flexDirection: "column", gap: 0.5 }, children: [
35324
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_material40.Typography, { variant: "body2", sx: { fontWeight: 600, color: "primary.main", fontSize: { xs: "0.85rem", sm: "0.9rem" } }, children: "Choose a template to get started instantly" }),
35325
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_material40.Typography, { variant: "body2", sx: { color: "text.secondary", fontSize: { xs: "0.85rem", sm: "0.9rem" }, lineHeight: 1.5 }, children: "Click any template to automatically fill the creation form with a proven personality setup. You can then customize it further to match your specific needs." })
35326
- ] })
35327
- }
35328
35339
  ),
35329
35340
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
35330
35341
  import_material40.Card,
35331
35342
  {
35332
35343
  sx: {
35333
- mb: { xs: 2, md: 2.5 },
35344
+ mb: { xs: 1.5, md: 2 },
35334
35345
  background: "linear-gradient(135deg, #1976d2 0%, #42a5f5 100%)",
35335
35346
  border: "2px solid transparent",
35336
35347
  borderRadius: { xs: 2.25, sm: 3 },
@@ -35367,7 +35378,7 @@ var PersonalitiesTab = ({
35367
35378
  setPersonalityTabIndex(1);
35368
35379
  },
35369
35380
  children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_material40.CardContent, { sx: {
35370
- p: { xs: 1.75, sm: 2.5 },
35381
+ p: { xs: 1.5, sm: 1.75 },
35371
35382
  color: "white",
35372
35383
  textAlign: "left",
35373
35384
  position: "relative",
@@ -35384,7 +35395,7 @@ var PersonalitiesTab = ({
35384
35395
  fontSize: 0,
35385
35396
  mb: 0,
35386
35397
  flexShrink: 0
35387
- }, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AutoAwesomeIcon, { sx: { fontSize: { xs: 28, sm: 34 }, color: "common.white", filter: "drop-shadow(0 4px 12px rgba(0,0,0,0.25))" } }) }),
35398
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AutoAwesomeIcon, { sx: { fontSize: { xs: 24, sm: 28 }, color: "common.white", filter: "drop-shadow(0 4px 12px rgba(0,0,0,0.25))" } }) }),
35388
35399
  /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_material40.Box, { sx: { flex: 1, minWidth: 0 }, children: [
35389
35400
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
35390
35401
  import_material40.Typography,
@@ -35394,7 +35405,7 @@ var PersonalitiesTab = ({
35394
35405
  fontWeight: 700,
35395
35406
  mb: 0.25,
35396
35407
  textShadow: "0 2px 4px rgba(0,0,0,0.2)",
35397
- fontSize: { xs: "1.1rem", sm: "1.25rem" }
35408
+ fontSize: { xs: "1rem", sm: "1.1rem" }
35398
35409
  },
35399
35410
  children: "Create from Scratch"
35400
35411
  }
@@ -35458,7 +35469,7 @@ var PersonalitiesTab = ({
35458
35469
  border: "1px solid",
35459
35470
  borderColor: "rgba(255,255,255,0.1)",
35460
35471
  borderRadius: 3,
35461
- minHeight: { xs: "auto", md: "188px" },
35472
+ minHeight: { xs: "auto", md: "150px" },
35462
35473
  display: "flex",
35463
35474
  flexDirection: "column",
35464
35475
  overflow: "hidden",
@@ -35499,7 +35510,7 @@ var PersonalitiesTab = ({
35499
35510
  },
35500
35511
  onClick: () => handleTemplateSelect(template),
35501
35512
  children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_material40.CardContent, { sx: {
35502
- p: { xs: 2, sm: 3 },
35513
+ p: { xs: 1.5, sm: 2 },
35503
35514
  display: "flex",
35504
35515
  flexDirection: "column",
35505
35516
  height: "100%",
@@ -35509,8 +35520,8 @@ var PersonalitiesTab = ({
35509
35520
  /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_material40.Box, { sx: {
35510
35521
  display: "flex",
35511
35522
  alignItems: "center",
35512
- mb: { xs: 1.25, md: 2.5 },
35513
- minHeight: { xs: "auto", md: "60px" }
35523
+ mb: { xs: 1, md: 1.5 },
35524
+ minHeight: { xs: "auto", md: "auto" }
35514
35525
  }, children: [
35515
35526
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
35516
35527
  import_material40.Avatar,
@@ -35518,8 +35529,8 @@ var PersonalitiesTab = ({
35518
35529
  src: template.avatar,
35519
35530
  alt: template.name,
35520
35531
  sx: {
35521
- width: { xs: 40, sm: 56, md: 60 },
35522
- height: { xs: 40, sm: 56, md: 60 },
35532
+ width: { xs: 40, sm: 48, md: 52 },
35533
+ height: { xs: 40, sm: 48, md: 52 },
35523
35534
  mr: { xs: 1.2, md: 2 },
35524
35535
  transition: "transform 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
35525
35536
  boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
@@ -35574,11 +35585,11 @@ var PersonalitiesTab = ({
35574
35585
  lineHeight: 1.5,
35575
35586
  fontSize: { xs: "0.82rem", sm: "0.85rem", md: "0.875rem" },
35576
35587
  display: "-webkit-box",
35577
- WebkitLineClamp: { xs: 2, sm: 4 },
35588
+ WebkitLineClamp: { xs: 2, sm: 3 },
35578
35589
  WebkitBoxOrient: "vertical",
35579
35590
  overflow: "hidden",
35580
- mb: { xs: 1.25, md: 2 },
35581
- minHeight: { xs: "auto", md: "84px" }
35591
+ mb: { xs: 1, md: 1.5 },
35592
+ minHeight: { xs: "auto", md: "auto" }
35582
35593
  },
35583
35594
  children: template.description
35584
35595
  }
@@ -35613,18 +35624,7 @@ var PersonalitiesTab = ({
35613
35624
  ] })
35614
35625
  },
35615
35626
  index
35616
- )) }),
35617
- !isMobile && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
35618
- import_material40.Alert,
35619
- {
35620
- severity: "info",
35621
- sx: { mt: { xs: 2.5, md: 4 }, borderRadius: 2, px: { xs: 1.5, sm: 2 }, py: { xs: 1.25, sm: 1.5 } },
35622
- children: [
35623
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_material40.Typography, { variant: "body2", sx: { fontWeight: 600, fontSize: { xs: "0.85rem", sm: "0.9rem" } }, children: "Pro Tip:" }),
35624
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_material40.Typography, { variant: "body2", sx: { fontSize: { xs: "0.85rem", sm: "0.9rem" }, lineHeight: 1.5 }, children: "Click any template to automatically switch to the Create/Edit tab with the form pre-filled. Mix and match ideas to create your perfect AI personality!" })
35625
- ]
35626
- }
35627
- )
35627
+ )) })
35628
35628
  ] })
35629
35629
  ] });
35630
35630
  const renderCreateEditTab = () => /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_material40.Box, { sx: { p: { xs: 1.5, sm: 2 } }, children: [