MCPcopy Create free account
hub / github.com/Roy3838/Observer / executeJavaScript

Function executeJavaScript

app/src/utils/handlers/javascript.ts:74–841  ·  view source on GitHub ↗
(
  response: string | null,
  agentId: string,
  code: string,
  iterationId: string, // <-- New parameter
  getToken?: TokenProvider,
  preprocessResult?: PreProcessorResult,
  decision: Decision | null = null
)

Source from the content-addressed store, hash-verified

72 * Execute JavaScript handler for processing agent responses
73 */
74export async function executeJavaScript(
75 response: string | null,
76 agentId: string,
77 code: string,
78 iterationId: string, // <-- New parameter
79 getToken?: TokenProvider,
80 preprocessResult?: PreProcessorResult,
81 decision: Decision | null = null
82): Promise<boolean> {
83 // Fetch current agent's image memory to make it always available
84 const currentAgentImageMemory = await getAgentImageMemory(agentId);
85
86 const context = {
87 prompt: preprocessResult?.modifiedPrompt || "",
88 response,
89 decision,
90 agentId,
91 // Image variables from preprocessing
92 images: preprocessResult?.images || [],
93 screen: preprocessResult?.imageSources?.screen ? [preprocessResult.imageSources.screen] : [],
94 camera: preprocessResult?.imageSources?.camera ? [preprocessResult.imageSources.camera] : [],
95 microphone: preprocessResult?.microphone || "",
96 screenAudio: preprocessResult?.screenAudio || "",
97 allAudio: preprocessResult?.allAudio || "",
98 imemory: currentAgentImageMemory,
99 getMemory: async (targetId = agentId) => {
100 try {
101 const result = await utils.getMemory(targetId);
102 Logger.info(agentId, `Memory retrieved for ${targetId}`, {
103 logType: 'tool-success',
104 iterationId,
105 content: { tool: 'getMemory', params: { targetId }, result: result.slice(0, 100) + (result.length > 100 ? '...' : '') }
106 });
107 return result;
108 } catch (error) {
109 Logger.error(agentId, `Failed to get memory for ${targetId}`, {
110 logType: 'tool-error',
111 iterationId,
112 content: { tool: 'getMemory', params: { targetId }, error: extractErrorMessage(error) }
113 });
114 throw error;
115 }
116 },
117 setMemory: async (targetId: string, value?: any) => {
118 try {
119 let result;
120 if (value === undefined) {
121 result = await utils.setMemory(agentId, targetId);
122 Logger.info(agentId, `Memory set for ${agentId}`, {
123 logType: 'tool-success',
124 iterationId,
125 content: { tool: 'setMemory', params: { targetId: agentId, value: String(targetId).slice(0, 100) } }
126 });
127 } else {
128 result = await utils.setMemory(targetId, value);
129 Logger.info(agentId, `Memory set for ${targetId}`, {
130 logType: 'tool-success',
131 iterationId,

Callers 1

postProcessFunction · 0.90

Calls 15

getAgentImageMemoryFunction · 0.90
startAgentLoopFunction · 0.90
stopAgentLoopFunction · 0.90
getAgentFunction · 0.90
wakeMCPFunction · 0.90
extractErrorMessageFunction · 0.85
flattenMediaFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80
notifyMethod · 0.80
startClipMethod · 0.80
stopClipMethod · 0.80

Tested by

no test coverage detected