MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / getCalledActions

Function getCalledActions

lib/edge-runtime/dataAnalysis.ts:213–271  ·  view source on GitHub ↗
(
  assistantFnMessagePairs: (AssistantMessage & {
    functionMessages: FunctionMessage[];
  })[],
  actions: Action[],
)

Source from the content-addressed store, hash-verified

211}
212
213export function getCalledActions(
214 assistantFnMessagePairs: (AssistantMessage & {
215 functionMessages: FunctionMessage[];
216 })[],
217 actions: Action[],
218): CalledAction[] {
219 console.log(
220 "actions",
221 actions.map((a) => a === undefined),
222 );
223 const calledActions = assistantFnMessagePairs
224 .map((pair) => {
225 const parsedOutput = parseOutput(pair.content);
226
227 // TODO: Remove API calls since last successful data analysis call
228 return (
229 parsedOutput.commands
230 // Remove the data analysis action
231 .filter(
232 (command) =>
233 ![dataAnalysisActionName, "instruct_coder"].includes(
234 command?.name,
235 ),
236 )
237 .map((command, idx) => {
238 let output: Json = pair.functionMessages[idx]?.content;
239 try {
240 output = JSON.parse(pair.functionMessages[idx]?.content);
241 } catch {}
242 console.log(`command ${idx}:`, command);
243 return {
244 action: actions.find((a) => a.name === command.name)!,
245 args: command.args,
246 output,
247 };
248 })
249 );
250 })
251 .flat();
252 console.log(
253 "calledActions",
254 calledActions.map((a) => a === undefined),
255 );
256
257 return calledActions
258 .reverse()
259 .filter((a, idx) => {
260 // Keep most recent call if identical calls are made >once
261 const earliestCall =
262 calledActions.findIndex(
263 (otherAction) =>
264 otherAction.action?.name === a.action?.name &&
265 _.isEqual(otherAction.args, a.args),
266 ) ?? idx;
267 return idx === earliestCall;
268 // Reversed it earlier, so need to re-reverse
269 })
270 .reverse();

Callers 2

runDataAnalysisFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected