MCPcopy Create free account
hub / github.com/Noumena-Network/code / dispatchAgentSubmit

Function dispatchAgentSubmit

src/session/agentSubmitDispatch.ts:3–57  ·  view source on GitHub ↗
(
  {
    input,
    taskId,
    isLocalAgentTask,
    isRunning,
  }: {
    input: string
    taskId: string
    isLocalAgentTask: boolean
    isRunning: boolean
  },
  {
    appendMessageToLocalAgent,
    queuePendingMessage,
    resumeLocalAgentBackground,
    injectUserMessageToTeammate,
    logDebug,
    notifyResumeAgentFailed,
    clearInput,
    setCursorOffset,
    clearBuffer,
  }: {
    appendMessageToLocalAgent: (taskId: string, input: string) => void
    queuePendingMessage: (taskId: string, input: string) => void
    resumeLocalAgentBackground: (taskId: string, input: string) => Promise<void>
    injectUserMessageToTeammate: (taskId: string, input: string) => void
    logDebug: (message: string) => void
    notifyResumeAgentFailed: (taskId: string, message: string) => void
    clearInput: () => void
    setCursorOffset: (value: number) => void
    clearBuffer: () => void
  },
)

Source from the content-addressed store, hash-verified

1import { errorMessage } from '../utils/errors.js'
2
3export async function dispatchAgentSubmit(
4 {
5 input,
6 taskId,
7 isLocalAgentTask,
8 isRunning,
9 }: {
10 input: string
11 taskId: string
12 isLocalAgentTask: boolean
13 isRunning: boolean
14 },
15 {
16 appendMessageToLocalAgent,
17 queuePendingMessage,
18 resumeLocalAgentBackground,
19 injectUserMessageToTeammate,
20 logDebug,
21 notifyResumeAgentFailed,
22 clearInput,
23 setCursorOffset,
24 clearBuffer,
25 }: {
26 appendMessageToLocalAgent: (taskId: string, input: string) => void
27 queuePendingMessage: (taskId: string, input: string) => void
28 resumeLocalAgentBackground: (taskId: string, input: string) => Promise<void>
29 injectUserMessageToTeammate: (taskId: string, input: string) => void
30 logDebug: (message: string) => void
31 notifyResumeAgentFailed: (taskId: string, message: string) => void
32 clearInput: () => void
33 setCursorOffset: (value: number) => void
34 clearBuffer: () => void
35 },
36): Promise<void> {
37 if (isLocalAgentTask) {
38 appendMessageToLocalAgent(taskId, input)
39 if (isRunning) {
40 queuePendingMessage(taskId, input)
41 } else {
42 try {
43 await resumeLocalAgentBackground(taskId, input)
44 } catch (err) {
45 const message = errorMessage(err)
46 logDebug(`resumeAgentBackground failed: ${message}`)
47 notifyResumeAgentFailed(taskId, message)
48 }
49 }
50 } else {
51 injectUserMessageToTeammate(taskId, input)
52 }
53
54 clearInput()
55 setCursorOffset(0)
56 clearBuffer()
57}

Callers 2

REPLFunction · 0.85

Calls 5

queuePendingMessageFunction · 0.50
errorMessageFunction · 0.50
logDebugFunction · 0.50

Tested by

no test coverage detected