Skip to content

Adding Context

Use addSources() to inject structured business context at runtime.

import { addSources } from "https://cdn.docuworm.ai/docuworm.js";
const widget = document.querySelector("docuworm-chat");
addSources(
[
{
title: "Case Summary",
text: "Customer reported duplicate transaction from merchant ACME.",
category: "case",
},
{
title: "Recent Transactions",
text: "2026-02-02: $48.99 ACME\n2026-02-05: $48.99 ACME",
category: "transactions",
},
],
widget,
);
type Source = {
title: string;
text: string;
category?: string;
};
  • If a thread exists, sources are added immediately.
  • If a thread is not ready yet, sources are queued and applied once ready.
  • Calling addSources() can trigger thread initialization when needed.
  • Keep titles stable and descriptive.
  • Use categories that map to your domain (case, policy, billing, profile).
  • Keep text concise and high-signal.
  • Update context whenever the active app entity changes.
function applyCaseContext(widget: HTMLElement, summary: string) {
addSources([{ title: "Case Summary", text: summary, category: "case" }], widget);
}
function applyCaseContext(widget: HTMLElement, summary: string) {
addSources([{ title: "Case Summary", text: summary, category: "case" }], widget);
}
<script lang="ts">
function applyCaseContext(widget: HTMLElement, summary: string) {
addSources([{ title: "Case Summary", text: summary, category: "case" }], widget);
}
</script>
  1. Load entity data from your backend.
  2. Upload related documents programmatically.
  3. Add structured context with addSources().
  4. Let users continue with manual uploads from the widget UI.