@burtson-labs/bandit-engine 2.0.102 → 2.0.103

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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  chat_default
3
- } from "./chunk-R3HBSHLE.mjs";
3
+ } from "./chunk-GM5V2RJS.mjs";
4
4
  import {
5
5
  chat_provider_default
6
6
  } from "./chunk-VTKRZNLI.mjs";
@@ -10,7 +10,7 @@ import {
10
10
  useGatewayHealth,
11
11
  useGatewayMemory,
12
12
  useGatewayModels
13
- } from "./chunk-7NXSMMCU.mjs";
13
+ } from "./chunk-SWLZ7QJB.mjs";
14
14
  import "./chunk-KYC7CC6C.mjs";
15
15
  import "./chunk-HAUDGBUS.mjs";
16
16
  import "./chunk-BN3D45E2.mjs";
@@ -20365,7 +20365,7 @@ var init_bandit_chat_logo = __esm({
20365
20365
  });
20366
20366
 
20367
20367
  // src/chat/source-chips.tsx
20368
- var import_react43, import_material35, import_jsx_runtime35, parseWebSources, stripSourcesForDisplay, domainOf, SourceChip, SourceChips, source_chips_default;
20368
+ var import_react43, import_material35, import_jsx_runtime35, parseWebSources, stripSourcesForDisplay, linkifyCitations, domainOf, SourceChip, SourceChips, source_chips_default;
20369
20369
  var init_source_chips = __esm({
20370
20370
  "src/chat/source-chips.tsx"() {
20371
20371
  "use strict";
@@ -20400,6 +20400,14 @@ var init_source_chips = __esm({
20400
20400
  );
20401
20401
  return c.replace(/\s+$/u, "");
20402
20402
  };
20403
+ linkifyCitations = (content, sources) => {
20404
+ if (!content || sources.length === 0) return content;
20405
+ const link = (text) => text.replace(/\[(\d{1,2})\]/g, (full, num) => {
20406
+ const src = sources[parseInt(num, 10) - 1];
20407
+ return src ? `[\\[${num}\\]](${src.url})` : full;
20408
+ });
20409
+ return content.split(/(```[\s\S]*?```)/g).map((seg, i) => i % 2 === 0 ? link(seg) : seg).join("");
20410
+ };
20403
20411
  domainOf = (url) => {
20404
20412
  try {
20405
20413
  return new URL(url).hostname.replace(/^www\./, "");
@@ -20608,7 +20616,7 @@ var init_chat_messages = __esm({
20608
20616
  /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
20609
20617
  StreamingMarkdown_default,
20610
20618
  {
20611
- content: stripSourcesForDisplay(content),
20619
+ content: linkifyCitations(stripSourcesForDisplay(content), parseWebSources(content)),
20612
20620
  isStreaming: isStreaming && isLast,
20613
20621
  sources: sourceSummaries
20614
20622
  }
@@ -24136,6 +24144,29 @@ _This link is temporary and expires in about ${mins} minutes._`;
24136
24144
  try {
24137
24145
  const toolResultsText = summarizableResults.map((r) => `## ${r.name}
24138
24146
  ${r.output}`).join("\n\n");
24147
+ const dedupeSources = (arr) => {
24148
+ const seen = /* @__PURE__ */ new Set();
24149
+ return arr.filter((s) => seen.has(s.url) ? false : (seen.add(s.url), true));
24150
+ };
24151
+ const citeDomain = (u) => {
24152
+ try {
24153
+ return new URL(u).hostname.replace(/^www\./, "");
24154
+ } catch {
24155
+ return u;
24156
+ }
24157
+ };
24158
+ const buildCitationGuide = () => {
24159
+ const cite = dedupeSources(collectedSources).slice(0, 6);
24160
+ if (!cite.length)
24161
+ return `
24162
+
24163
+ Do NOT add citations, footnotes, superscript reference numbers, or a Sources list \u2014 sources are attached automatically.`;
24164
+ const list = cite.map((s, i) => `[${i + 1}] ${s.title || citeDomain(s.url)}`).join("\n");
24165
+ return `
24166
+
24167
+ When a statement is supported by one of the sources below, add an inline citation right after it using that source's number in square brackets \u2014 e.g. [1] or [2]. Use ONLY these numbers, never invent one, never use superscripts, and do NOT write your own Sources/References list (the numbered list is attached automatically below your answer):
24168
+ ${list}`;
24169
+ };
24139
24170
  const MAX_CHAIN_ROUNDS = 4;
24140
24171
  const enabledToolsForChain = getEnabledMCPToolsForAI();
24141
24172
  const convo = [
@@ -24151,7 +24182,7 @@ ${r.output}`).join("\n\n");
24151
24182
  ${toolResultsText}
24152
24183
  ===END TOOL RESULTS===
24153
24184
 
24154
- Use them to fully complete my original request. If you still need to take an action I asked for (for example, actually create a file I want to download), call the appropriate tool now with a \`\`\`tool_code\`\`\` block. Otherwise give your final answer. Do NOT add citations, footnotes, superscript reference numbers (e.g. \xB9 \xB2 \xB3), or a Sources/References/Citations list \u2014 the sources are attached automatically below your answer. Just write the answer naturally.`
24185
+ Use them to fully complete my original request. If you still need to take an action I asked for (for example, actually create a file I want to download), call the appropriate tool now with a \`\`\`tool_code\`\`\` block. Otherwise give your final answer.${buildCitationGuide()}`
24155
24186
  }
24156
24187
  ];
24157
24188
  const streamTurn = (req) => new Promise((resolve) => {
@@ -24297,7 +24328,7 @@ That step failed: ${e instanceof Error ? e.message : String(e)}`);
24297
24328
  ${roundOut.join("\n\n")}
24298
24329
  ===END TOOL RESULTS===
24299
24330
 
24300
- Now give your final answer to my original request, or call another tool if you still genuinely need to. Do NOT add citations, footnotes, superscript reference numbers, or a Sources list \u2014 sources are attached automatically.`
24331
+ Now give your final answer to my original request, or call another tool if you still genuinely need to.${buildCitationGuide()}`
24301
24332
  });
24302
24333
  }
24303
24334
  setIsThinking?.(false);
@@ -24310,7 +24341,7 @@ Now give your final answer to my original request, or call another tool if you s
24310
24341
  const sourcesMd = collectedSources.length ? `
24311
24342
 
24312
24343
  **Sources**
24313
- ${collectedSources.slice(0, 6).map((s) => {
24344
+ ${dedupeSources(collectedSources).slice(0, 6).map((s) => {
24314
24345
  let domain = s.url;
24315
24346
  try {
24316
24347
  domain = new URL(s.url).hostname.replace(/^www\./, "");