// Parent-message context injection for Teams channel thread replies. // // When an inbound message arrives as a reply inside a Teams channel thread, // the triggering message often makes no sense on its own (for example, a // one-word "yes" or "go ahead"). Per-thread session isolation (PR #62713) // gives each thread its own session, but the first message in a brand-new // thread session still has no parent context. // // This module fetches the parent message via Graph and prepends a compact // `Replying to @sender: …` system event to the next agent turn so the agent // knows what is being responded to. Fetches are cached to avoid repeated // Graph calls within the same active thread, and per-session dedupe ensures // the same parent is not re-injected on every subsequent reply in the // thread.
import { fetchChannelMessage, stripHtmlFromTeamsMessage } from "./graph-thread.js"; import type { GraphThreadMessage } from "./graph-thread.js";
// LRU cache for parent message fetches. Keyed by `teamId:channelId:parentId`. // 5-minute TTL and 100-entry cap keep active-thread chatter fast without // holding stale data when a thread goes quiet. Eviction uses Map insertion // order for LRU semantics (get() re-inserts on hit). const PARENT_CACHE_TTL_MS = 5 * 60 * 1000; const PARENT_CACHE_MAX = 100;
const parentCache = new Map<string, ParentCacheEntry>();
// Per-session dedupe: remembers the most recent parent id we injected for a // given session key. When the same thread session sees another reply against // the same parent, we skip re-enqueueing the identical system event. We keep // a small LRU so idle sessions eventually drop out. const INJECTED_MAX = 200; const injectedParents = new Map<string, string>();
export type ParentContextSummary = { /** Display name of the parent message author, or "unknown". */
sender: string; /** Stripped, single-line parent body text (or empty if unresolved). */
text: string;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.