@burtson-labs/bandit-engine 2.0.125 → 2.0.126

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  chat_default
3
- } from "./chunk-2WFTEJPS.mjs";
3
+ } from "./chunk-JXFPCLEY.mjs";
4
4
  import "./chunk-ONQMRE2G.mjs";
5
5
  import "./chunk-574ILQTT.mjs";
6
6
  import "./chunk-K2JGFKEB.mjs";
@@ -13,4 +13,4 @@ import "./chunk-BJTO5JO5.mjs";
13
13
  export {
14
14
  chat_default as default
15
15
  };
16
- //# sourceMappingURL=chat-SC6CFUED.mjs.map
16
+ //# sourceMappingURL=chat-Z3GRZ7GA.mjs.map
@@ -723,6 +723,38 @@ var source_chips_default = SourceChips;
723
723
 
724
724
  // src/chat/chat-messages.tsx
725
725
  import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
726
+ var WORKING_TOKEN_RE = /\s*<<working:([^>]*)>>\s*$/;
727
+ var ToolWorkingChip = ({ label }) => /* @__PURE__ */ jsxs3(
728
+ Box4,
729
+ {
730
+ sx: (theme) => ({
731
+ display: "inline-flex",
732
+ alignItems: "center",
733
+ gap: 1.25,
734
+ mt: 1.5,
735
+ px: 1.75,
736
+ py: 0.9,
737
+ borderRadius: 999,
738
+ bgcolor: theme.palette.action.hover,
739
+ border: `1px solid ${theme.palette.divider}`
740
+ }),
741
+ children: [
742
+ /* @__PURE__ */ jsxs3("div", { className: "typing-only", children: [
743
+ /* @__PURE__ */ jsx6("span", { className: "dot" }),
744
+ /* @__PURE__ */ jsx6("span", { className: "dot" }),
745
+ /* @__PURE__ */ jsx6("span", { className: "dot" })
746
+ ] }),
747
+ /* @__PURE__ */ jsx6(
748
+ Box4,
749
+ {
750
+ component: "span",
751
+ sx: { fontSize: "0.85rem", fontWeight: 500, color: "text.secondary", userSelect: "none" },
752
+ children: label || "Working on it"
753
+ }
754
+ )
755
+ ]
756
+ }
757
+ );
726
758
  var ChatMessages = ({
727
759
  pendingMessage,
728
760
  streamBuffer,
@@ -748,7 +780,9 @@ var ChatMessages = ({
748
780
  const isPlaceholder = entry.answer === "...";
749
781
  const showLoader = isLast && isStreaming && streamBuffer.trim() === "";
750
782
  const showThinking = showLoader && isThinking;
751
- const content = isLast ? isStreaming ? streamBuffer || "" : isPlaceholder ? "" : entry.answer : entry.answer;
783
+ const rawContent = isLast ? isStreaming ? streamBuffer || "" : isPlaceholder ? "" : entry.answer : entry.answer;
784
+ const workingMatch = isLast && isStreaming ? rawContent.match(WORKING_TOKEN_RE) : null;
785
+ const content = workingMatch ? rawContent.replace(WORKING_TOKEN_RE, "") : rawContent;
752
786
  const rawSources = entry.sourceFiles;
753
787
  const sourceSummaries = rawSources ? rawSources.filter((doc) => doc && typeof doc.name === "string" && doc.name.trim()).map((doc) => ({ id: doc.id || doc.name, name: doc.name.trim() })) : void 0;
754
788
  const responseNode = /* @__PURE__ */ jsxs3(
@@ -821,6 +855,7 @@ var ChatMessages = ({
821
855
  sources: sourceSummaries
822
856
  }
823
857
  ),
858
+ workingMatch && /* @__PURE__ */ jsx6(ToolWorkingChip, { label: workingMatch[1] }),
824
859
  /* @__PURE__ */ jsx6(source_chips_default, { content })
825
860
  ]
826
861
  }
@@ -833,7 +868,7 @@ var ChatMessages = ({
833
868
  {
834
869
  question: entry.question,
835
870
  response: responseNode,
836
- responseText: isLast ? isStreaming ? streamBuffer || "" : isPlaceholder ? "" : entry.answer : entry.answer,
871
+ responseText: content,
837
872
  backgroundColor: "#444",
838
873
  images: entry.images,
839
874
  memoryUpdated: entry.memoryUpdated && !isPlaceholder,
@@ -4214,8 +4249,20 @@ ${protocol}`;
4214
4249
  return result.trimStart();
4215
4250
  };
4216
4251
  const stripToolBlocks = (text) => text.replace(/```(?:tool_code|TOOL_CODE)\s*\n[\s\S]*?\n```/gi, "").trim();
4252
+ const truncateAtToolApparatus = (text) => {
4253
+ let t = text;
4254
+ const fenceIdx = t.search(/```(?:tool_code|TOOL_CODE)/);
4255
+ if (fenceIdx !== -1) t = t.slice(0, fenceIdx);
4256
+ const callIdx = t.search(
4257
+ /\b(?:web_search|web_fetch|image_generation|create_file|ask_user)\s*\(/
4258
+ );
4259
+ if (callIdx !== -1) t = t.slice(0, callIdx);
4260
+ t = t.replace(/```[\w-]*\s*$/, "");
4261
+ const fenceCount = (t.match(/```/g) || []).length;
4262
+ if (fenceCount % 2 === 1) t = t.slice(0, t.lastIndexOf("```"));
4263
+ return t.trim();
4264
+ };
4217
4265
  let workingLabel = "Working on it";
4218
- let workingPreamble = "";
4219
4266
  const stopWorking = () => {
4220
4267
  if (workingTimer) {
4221
4268
  clearInterval(workingTimer);
@@ -4224,17 +4271,10 @@ ${protocol}`;
4224
4271
  };
4225
4272
  const startWorking = (label = "Working on it") => {
4226
4273
  workingLabel = label.replace(/[.…]+\s*$/, "").trim() || "Working on it";
4227
- workingPreamble = stripToolBlocks(stripThinking(fullMessage)).trim();
4228
- if (workingTimer) return;
4229
- let dots = 0;
4230
- const render = () => {
4231
- dots = (dots + 1) % 4;
4232
- setStreamBuffer(
4233
- `${workingPreamble}${workingPreamble ? "\n\n" : ""}_${workingLabel}${".".repeat(dots)}_`
4234
- );
4235
- };
4236
- render();
4237
- workingTimer = setInterval(render, 450);
4274
+ const preamble = truncateAtToolApparatus(stripToolBlocks(stripThinking(fullMessage)));
4275
+ setStreamBuffer(
4276
+ `${preamble}${preamble ? "\n\n" : ""}<<working:${workingLabel}>>`
4277
+ );
4238
4278
  };
4239
4279
  const flushNow = () => {
4240
4280
  clearFlushTimer();
@@ -4280,10 +4320,16 @@ ${protocol}`;
4280
4320
  const inThinkBlock = /<think>/.test(fullMessage) && !/<think>[\s\S]*<\/think>/.test(fullMessage);
4281
4321
  setIsThinking?.(inThinkBlock);
4282
4322
  const visibleMessage = stripThinking(fullMessage);
4283
- if (/```(?:tool_code|TOOL_CODE)/.test(visibleMessage) || /\b(?:web_search|web_fetch|image_generation|create_file|ask_user)\s*\(/.test(visibleMessage)) {
4323
+ const bareToolMatch = visibleMessage.match(
4324
+ /\b(web_search|web_fetch|image_generation|create_file|ask_user)\s*\(/
4325
+ );
4326
+ if (/```(?:tool_code|TOOL_CODE)/.test(visibleMessage) || bareToolMatch) {
4284
4327
  sawToolBlock = true;
4285
4328
  clearFlushTimer();
4286
- startWorking();
4329
+ const fn = bareToolMatch?.[1];
4330
+ startWorking(
4331
+ fn === "create_file" ? "Creating your file" : fn === "web_search" ? "Searching the web" : fn === "web_fetch" ? "Reading the page" : fn === "image_generation" ? "Generating the image" : "Working on it"
4332
+ );
4287
4333
  }
4288
4334
  latestDisplayMessage = visibleMessage;
4289
4335
  if (!sawToolBlock) {
@@ -11498,4 +11544,4 @@ var chat_default = Chat;
11498
11544
  export {
11499
11545
  chat_default
11500
11546
  };
11501
- //# sourceMappingURL=chunk-2WFTEJPS.mjs.map
11547
+ //# sourceMappingURL=chunk-JXFPCLEY.mjs.map