MCPcopy
hub / github.com/ElricLiu/AutoGPT-Next-Web / extractArray

Function extractArray

src/utils/helpers.ts:39–56  ·  view source on GitHub ↗
(inputStr: string)

Source from the content-addressed store, hash-verified

37};
38
39export const extractArray = (inputStr: string): string[] => {
40 // Match an outer array of strings (including nested arrays)
41 const regex =
42 /(\[(?:\s*(?:"(?:[^"\\]|\\.|\n)*"|'(?:[^'\\]|\\.|\n)*')\s*,?)+\s*\])/;
43 const match = inputStr.match(regex);
44
45 if (match && match[0]) {
46 try {
47 // Parse the matched string to get the array
48 return JSON.parse(match[0]) as string[];
49 } catch (error) {
50 console.error("Error parsing the matched array:", error);
51 }
52 }
53
54 console.warn("Error, could not extract array from inputString:", inputStr);
55 return [];
56};
57
58// Model will return tasks such as "No tasks added". We should filter these
59export const realTasksFilter = (input: string): boolean => {

Callers 2

extractTasksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected