MCPcopy Index your code
hub / github.com/CopilotKit/CopilotKit / attachAssistant

Function attachAssistant

packages/bot-slack/src/assistant.ts:44–157  ·  view source on GitHub ↗
(cfg: AttachAssistantConfig)

Source from the content-addressed store, hash-verified

42
43/** Register the Bolt `Assistant` middleware and bridge it to the engine sink. */
44export function attachAssistant(cfg: AttachAssistantConfig): AssistantHandle {
45 const { app, sink, opts, resolveUser } = cfg;
46
47 // Pane threads seen this process (channelId::threadTs). Populated on
48 // thread_started and (defensively, after a restart) on the first message.
49 const assistantThreads = new Set<string>();
50 // Threads we've already auto-titled, so only the FIRST user message titles.
51 const titled = new Set<string>();
52
53 const titleAuto = opts.title !== false; // default "auto"
54
55 const assistant = new Assistant({
56 threadStarted: async ({ event, say, setSuggestedPrompts }) => {
57 const at = (event as { assistant_thread?: AssistantThreadMeta })
58 .assistant_thread;
59 if (!at?.channel_id || !at.thread_ts) return;
60 const channelId = at.channel_id;
61 const threadTs = at.thread_ts;
62 assistantThreads.add(threadKey(channelId, threadTs));
63
64 // ── Static defaults first (greeting + prompts). Degrade, never throw. ──
65 if (opts.greeting) {
66 try {
67 await say(opts.greeting);
68 } catch (err) {
69 console.error("[slack-assistant] greeting failed:", err);
70 }
71 }
72 if (opts.suggestedPrompts && opts.suggestedPrompts.length > 0) {
73 try {
74 await setSuggestedPrompts({
75 prompts: opts.suggestedPrompts.map((p) => ({
76 title: p.title,
77 message: p.message,
78 })) as [
79 { title: string; message: string },
80 ...{ title: string; message: string }[],
81 ],
82 });
83 } catch (err) {
84 console.error("[slack-assistant] setSuggestedPrompts failed:", err);
85 }
86 }
87
88 // ── Then hand off to the engine (onThreadStarted handlers layer on top). ──
89 const user = at.user_id ? await resolveUser(at.user_id) : undefined;
90 await sink.onThreadStarted({
91 conversationKey: conversationKeyOf({ channelId, scope: threadTs }),
92 replyTarget: {
93 channel: channelId,
94 threadTs,
95 recipientUserId: at.user_id,
96 },
97 user,
98 platform: "slack",
99 });
100 },
101

Callers 2

startMethod · 0.85
setupFunction · 0.85

Calls 7

threadKeyFunction · 0.85
setTitleFunction · 0.85
conversationKeyOfFunction · 0.70
errorMethod · 0.65
onThreadStartedMethod · 0.65
onTurnMethod · 0.65
hasMethod · 0.45

Tested by 1

setupFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…