@gendive/chatllm 0.4.0 → 0.5.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.
@@ -359,6 +359,22 @@ ${contextSummary}` },
359
359
  );
360
360
  return;
361
361
  }
362
+ if (typeof result === "object" && "content" in result) {
363
+ setSessions(
364
+ (prev) => prev.map((s) => {
365
+ if (s.id === capturedSessionId) {
366
+ return {
367
+ ...s,
368
+ messages: s.messages.map(
369
+ (m) => m.id === assistantMessageId ? { ...m, content: result.content, sources: result.sources } : m
370
+ )
371
+ };
372
+ }
373
+ return s;
374
+ })
375
+ );
376
+ return;
377
+ }
362
378
  response = new Response(result);
363
379
  } else {
364
380
  response = await fetch(apiEndpoint, {
@@ -518,6 +534,7 @@ ${currentSession.contextSummary}` },
518
534
  const modelConfig = models.find((m) => m.id === targetModel);
519
535
  const provider = modelConfig?.provider || "ollama";
520
536
  let responseContent = "";
537
+ let responseSources;
521
538
  if (onSendMessage) {
522
539
  const result = await onSendMessage({
523
540
  messages: messagesForApi,
@@ -528,6 +545,9 @@ ${currentSession.contextSummary}` },
528
545
  });
529
546
  if (typeof result === "string") {
530
547
  responseContent = result;
548
+ } else if (typeof result === "object" && "content" in result) {
549
+ responseContent = result.content;
550
+ responseSources = result.sources;
531
551
  } else {
532
552
  const reader = result.getReader();
533
553
  const decoder = new TextDecoder();
@@ -591,7 +611,8 @@ ${currentSession.contextSummary}` },
591
611
  id: generateId("alt"),
592
612
  model: targetModel,
593
613
  content: responseContent,
594
- timestamp: Date.now()
614
+ timestamp: Date.now(),
615
+ sources: responseSources
595
616
  };
596
617
  const capturedSessionId = currentSessionId;
597
618
  setSessions(
@@ -2146,6 +2167,7 @@ var MessageBubble = ({
2146
2167
  const otherModels = models?.filter((m) => m.id !== message.model) || [];
2147
2168
  const displayContent = alternatives && alternatives.length > 0 && activeAlternativeIndex > 0 ? alternatives[activeAlternativeIndex - 1]?.content || message.content : message.content;
2148
2169
  const displayModel = alternatives && alternatives.length > 0 && activeAlternativeIndex > 0 ? alternatives[activeAlternativeIndex - 1]?.model : message.model;
2170
+ const displaySources = alternatives && alternatives.length > 0 && activeAlternativeIndex > 0 ? alternatives[activeAlternativeIndex - 1]?.sources : message.sources;
2149
2171
  const handleMouseUp = () => {
2150
2172
  if (!onQuote) return;
2151
2173
  const selection = window.getSelection();
@@ -2270,6 +2292,43 @@ var MessageBubble = ({
2270
2292
  ]
2271
2293
  }
2272
2294
  ),
2295
+ displaySources && displaySources.length > 0 && /* @__PURE__ */ jsxs6(
2296
+ "div",
2297
+ {
2298
+ style: {
2299
+ display: "flex",
2300
+ flexWrap: "wrap",
2301
+ gap: "8px",
2302
+ marginTop: "12px",
2303
+ paddingTop: "12px",
2304
+ borderTop: "1px solid var(--chatllm-border-light, #f3f4f6)"
2305
+ },
2306
+ children: [
2307
+ /* @__PURE__ */ jsx7(
2308
+ "span",
2309
+ {
2310
+ style: {
2311
+ fontSize: "12px",
2312
+ fontWeight: 500,
2313
+ color: "var(--chatllm-text-muted, #9ca3af)",
2314
+ marginRight: "4px"
2315
+ },
2316
+ children: "\uCD9C\uCC98:"
2317
+ }
2318
+ ),
2319
+ displaySources.map((source, index) => /* @__PURE__ */ jsx7(
2320
+ LinkChip,
2321
+ {
2322
+ text: source.title,
2323
+ url: source.url,
2324
+ index: index + 1,
2325
+ showFavicon: true
2326
+ },
2327
+ source.id
2328
+ ))
2329
+ ]
2330
+ }
2331
+ ),
2273
2332
  alternatives && alternatives.length > 0 && /* @__PURE__ */ jsxs6(
2274
2333
  "div",
2275
2334
  {