MCPcopy Create free account
hub / github.com/CreminiAI/skillpack / runAgent

Method runAgent

src/runtime/adapters/slack.ts:293–364  ·  view source on GitHub ↗
(
    channelId: string,
    text: string,
    client: any,
    route: SlackRoute,
    attachments: ChannelAttachment[] = [],
  )

Source from the content-addressed store, hash-verified

291 // -------------------------------------------------------------------------
292
293 private async runAgent(
294 channelId: string,
295 text: string,
296 client: any,
297 route: SlackRoute,
298 attachments: ChannelAttachment[] = [],
299 ): Promise<void> {
300 if (!this.agent) return;
301
302 let finalText = "";
303 let hasError = false;
304 let errorMessage = "";
305 const pendingFiles: Array<{ filePath: string; caption?: string }> = [];
306 const placeholder = await this.sendPlaceholderMessage(client, route);
307
308 const onEvent = (event: AgentEvent) => {
309 if (event.type === "text_delta") {
310 finalText += event.delta;
311 } else if (event.type === "file_output") {
312 pendingFiles.push({
313 filePath: event.filePath,
314 caption: event.caption,
315 });
316 }
317 this.ipcBroadcaster?.broadcastAgentEvent(channelId, event);
318 };
319
320 try {
321 const result = await this.agent.handleMessage(
322 "slack",
323 channelId,
324 text,
325 onEvent,
326 attachments.length > 0 ? attachments : undefined,
327 );
328 if (result.errorMessage) {
329 hasError = true;
330 errorMessage = result.errorMessage;
331 }
332 } catch (err) {
333 hasError = true;
334 errorMessage = this.getErrorMessage(err);
335 }
336
337 if (hasError) {
338 await this.sendOrUpdateSafe(
339 client,
340 route,
341 `❌ Error: ${errorMessage}`,
342 placeholder,
343 );
344 return;
345 }
346
347 if (finalText.trim()) {
348 await this.sendLongMessage(client, route, finalText, placeholder);
349 } else if (pendingFiles.length === 0) {
350 await this.sendOrUpdateSafe(

Callers 2

handleDirectMessageMethod · 0.95
handleMentionMethod · 0.95

Calls 7

getErrorMessageMethod · 0.95
sendOrUpdateSafeMethod · 0.95
sendLongMessageMethod · 0.95
deleteMessageSafeMethod · 0.95
sendFileSafeMethod · 0.95
handleMessageMethod · 0.65

Tested by

no test coverage detected