MCPcopy Create free account
hub / github.com/agentrpc/agentrpc / executeFn

Function executeFn

sdk-node/src/execute-fn.ts:11–66  ·  view source on GitHub ↗
(
  fn: ToolRegistrationInput<any>["handler"],
  args: Parameters<ToolRegistrationInput<any>["handler"]>,
)

Source from the content-addressed store, hash-verified

9};
10
11export const executeFn = async (
12 fn: ToolRegistrationInput<any>["handler"],
13 args: Parameters<ToolRegistrationInput<any>["handler"]>,
14): Promise<Result> => {
15 const start = Date.now();
16 try {
17 const result = await fn(...args);
18
19 const interupt = extractInterrupt(result);
20
21 if (interupt) {
22 return {
23 content: interupt,
24 type: "interrupt",
25 functionExecutionTime: Date.now() - start,
26 };
27 }
28
29 return {
30 content: result,
31 type: "resolution",
32 functionExecutionTime: Date.now() - start,
33 };
34 } catch (e) {
35 const interupt = extractInterrupt(e);
36 if (interupt) {
37 return {
38 content: interupt,
39 type: "interrupt",
40 functionExecutionTime: Date.now() - start,
41 };
42 }
43 const functionExecutionTime = Date.now() - start;
44 if (e instanceof Error) {
45 return {
46 content: serializeError(e),
47 type: "rejection",
48 functionExecutionTime,
49 };
50 } else if (typeof e === "string") {
51 return {
52 content: serializeError(new Error(e)),
53 type: "rejection",
54 functionExecutionTime,
55 };
56 } else {
57 return {
58 content: new Error(
59 "Inferable encountered an unexpected error type. Make sure you are throwing an Error object.",
60 ),
61 type: "rejection",
62 functionExecutionTime,
63 };
64 }
65 }
66};

Callers 2

execute-fn.test.tsFile · 0.90
processCallMethod · 0.90

Calls 3

extractInterruptFunction · 0.90
serializeErrorFunction · 0.90
fnFunction · 0.85

Tested by

no test coverage detected