MCPcopy Create free account
hub / github.com/code100x/mobile-magic / parse

Method parse

mobile-magic/apps/worker/parser.ts:27–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25 }
26
27 parse() {
28 const latestActionStart = this.currentArtifact.split("\n").findIndex((line) => line.includes("<boltAction type="));
29 const latestActionEnd = this.currentArtifact.split("\n").findIndex((line) => line.includes("</boltAction>")) ?? (this.currentArtifact.split("\n").length - 1);
30
31 if (latestActionStart === -1) {
32 return;
33 }
34
35 const latestActionType = this.currentArtifact.split("\n")[latestActionStart].split("type=")[1].split(" ")[0].split(">")[0];
36 const latestActionContent = this.currentArtifact.split("\n").slice(latestActionStart, latestActionEnd + 1).join("\n");
37
38 try {
39 if (latestActionType === "\"shell\"") {
40 let shellCommand = latestActionContent.split('\n').slice(1).join('\n');
41 if (shellCommand.includes("</boltAction>")) {
42 shellCommand = shellCommand.split("</boltAction>")[0];
43 this.currentArtifact = this.currentArtifact.split(latestActionContent)[1];
44 this.onShellCommand(shellCommand);
45 }
46 } else if (latestActionType === "\"file\"") {
47 const filePath = this.currentArtifact.split("\n")[latestActionStart].split("filePath=")[1].split(">")[0];
48 let fileContent = latestActionContent.split("\n").slice(1).join("\n");
49 if (fileContent.includes("</boltAction>")) {
50 fileContent = fileContent.split("</boltAction>")[0];
51 this.currentArtifact = this.currentArtifact.split(latestActionContent)[1];
52 this.onFileContent(filePath.split("\"")[1], fileContent);
53 }
54 }
55 } catch(e) {}
56 }
57}

Callers 5

initWsFunction · 0.80
index.tsFile · 0.80
constructorMethod · 0.80
worker.test.tsFile · 0.80
messageFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected