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

Method handleMessage

src/runtime/agent.ts:662–895  ·  view source on GitHub ↗
(
    adapter: RuntimePlatform,
    channelId: string,
    text: string,
    onEvent: (event: AgentEvent) => void,
    attachments?: ChannelAttachment[],
  )

Source from the content-addressed store, hash-verified

660 }
661
662 async handleMessage(
663 adapter: RuntimePlatform,
664 channelId: string,
665 text: string,
666 onEvent: (event: AgentEvent) => void,
667 attachments?: ChannelAttachment[],
668 ): Promise<HandleResult> {
669 const cs = await this.getOrCreateSession(adapter, channelId);
670 const run = async (): Promise<HandleResult> => {
671 cs.running = true;
672
673 let turnHadVisibleOutput = false;
674 let sawAgentStart = false;
675 let sawAgentEnd = false;
676 const runId = randomUUID();
677 let unsubscribe = () => undefined;
678 const waitForQueuedAgentEvents = async (): Promise<void> => {
679 const maybeQueue = (cs.session as { _agentEventQueue?: unknown })
680 ._agentEventQueue;
681 if (
682 !maybeQueue ||
683 typeof (maybeQueue as Promise<unknown>).then !== "function"
684 ) {
685 return;
686 }
687
688 try {
689 await maybeQueue;
690 } catch (error) {
691 log("[PackAgent] Waiting for queued agent events failed:", error);
692 }
693 };
694
695 try {
696 if (this.pendingAbortChannels.delete(channelId)) {
697 return { stopReason: "aborted" };
698 }
699
700 const forwardAgentEvent = (event: AgentEvent): void => {
701 if (event.type === "agent_start") {
702 sawAgentStart = true;
703 } else if (event.type === "agent_end") {
704 if (sawAgentEnd) {
705 return;
706 }
707 sawAgentEnd = true;
708 }
709
710 onEvent(event);
711 };
712
713 // Wire up file output callback for this run
714 cs.fileOutputCallbackRef.current = (event) => {
715 forwardAgentEvent(event);
716 };
717 cs.delegatedToolRunContextRef.current = {
718 runId,
719 channelId,

Callers

nothing calls this directly

Calls 1

getOrCreateSessionMethod · 0.95

Tested by

no test coverage detected