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

Function executeJavaScript

app/src/utils/handlers/javascript.ts:61–740  ·  view source on GitHub ↗
(
  response: string,
  agentId: string,
  code: string,
  iterationId: string, // <-- New parameter
  getToken?: TokenProvider,
  preprocessResult?: PreProcessorResult
)

Source from the content-addressed store, hash-verified

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

Callers 1

postProcessFunction · 0.90

Calls 12

getAgentImageMemoryFunction · 0.90
startAgentLoopFunction · 0.90
stopAgentLoopFunction · 0.90
extractErrorMessageFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80
notifyMethod · 0.80
startClipMethod · 0.80
stopClipMethod · 0.80
getVideoMethod · 0.80
handlerFunction · 0.50
debugMethod · 0.45

Tested by

no test coverage detected