feature: add Bilig WorkPaper formula readback tool#6427
Open
gregkonush wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a new tool, bilig_workpaper_formula_readback, which enables agents to edit spreadsheet inputs and verify formula readbacks via the Bilig API. The review feedback identifies opportunities to improve the robustness of the tool's JavaScript implementation, specifically by adding a null check for the parsed JSON response to prevent potential runtime errors and adopting more idiomatic loose equality checks for nullish values.
| "color": "linear-gradient(rgb(24,96,122), rgb(48,159,108))", | ||
| "iconSrc": "https://github.com/proompteng.png", | ||
| "schema": "[{\"id\":0,\"property\":\"baseUrl\",\"description\":\"Bilig base URL. Use https://bilig.proompteng.ai for the hosted demo or your self-hosted Bilig URL.\",\"type\":\"string\",\"required\":false},{\"id\":1,\"property\":\"sheetName\",\"description\":\"Worksheet containing the editable forecast input. Default: Inputs\",\"type\":\"string\",\"required\":false},{\"id\":2,\"property\":\"address\",\"description\":\"A1-style input cell address to edit. Default: B3\",\"type\":\"string\",\"required\":false},{\"id\":3,\"property\":\"value\",\"description\":\"Numeric value to write before formula readback. Default: 0.4\",\"type\":\"number\",\"required\":false}]", | ||
| "func": "const fetch = require('node-fetch');\n\nconst baseUrl = String($baseUrl || 'https://bilig.proompteng.ai').replace(/\\/$/, '');\nconst sheetName = String($sheetName || 'Inputs');\nconst address = String($address || 'B3').toUpperCase();\nconst value = $value === undefined || $value === null || $value === '' ? 0.4 : Number($value);\n\nif (!baseUrl.startsWith('http://') && !baseUrl.startsWith('https://')) {\n return 'Bilig WorkPaper formula readback failed: baseUrl must start with http:// or https://';\n}\n\nif (!Number.isFinite(value)) {\n return `Bilig WorkPaper formula readback failed: value must be numeric, received ${JSON.stringify($value)}`;\n}\n\nconst response = await fetch(`${baseUrl}/api/workpaper/n8n/forecast`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': 'application/json',\n 'User-Agent': 'Flowise-Bilig-WorkPaper-Tool/0.1'\n },\n body: JSON.stringify({ sheetName, address, value })\n});\n\nconst text = await response.text();\nlet proof;\ntry {\n proof = JSON.parse(text);\n} catch (error) {\n return `Bilig WorkPaper formula readback failed: expected JSON but received ${text.slice(0, 500)}`;\n}\n\nif (!response.ok) {\n return `Bilig WorkPaper formula readback failed: HTTP ${response.status} ${response.statusText} - ${JSON.stringify(proof)}`;\n}\n\nif (proof.verified !== true) {\n return `Bilig WorkPaper formula readback failed: unverified response ${JSON.stringify(proof)}`;\n}\n\nconst checks = proof.checks || {};\nconst before = proof.before || {};\nconst after = proof.after || {};\nconst compactProof = {\n verified: true,\n editedCell: proof.editedCell,\n before: {\n expectedArr: before.expectedArr,\n targetGap: before.targetGap\n },\n after: {\n expectedArr: after.expectedArr,\n targetGap: after.targetGap\n },\n checks: {\n formulasPersisted: checks.formulasPersisted === true,\n restoredMatchesAfter: checks.restoredMatchesAfter === true,\n computedOutputChanged: checks.computedOutputChanged === true\n },\n source: 'Bilig WorkPaper',\n github: 'https://github.com/proompteng/bilig'\n};\n\nreturn JSON.stringify(compactProof, null, 2);" |
Contributor
There was a problem hiding this comment.
There are two improvements for the func implementation:
- Defensive Programming:
JSON.parse()can returnnull(e.g., if the response body is the string"null"). Adding a check forproofbefore accessingproof.verifiedprevents a potentialTypeError. - Idiomatic Style: Per the repository's general rules, use loose equality (
== null) for nullish checks instead of checkingundefinedandnullseparately.
Additionally, ensure that the proof object is checked for existence before accessing properties like editedCell.
Suggested change
| "func": "const fetch = require('node-fetch');\n\nconst baseUrl = String($baseUrl || 'https://bilig.proompteng.ai').replace(/\\/$/, '');\nconst sheetName = String($sheetName || 'Inputs');\nconst address = String($address || 'B3').toUpperCase();\nconst value = $value === undefined || $value === null || $value === '' ? 0.4 : Number($value);\n\nif (!baseUrl.startsWith('http://') && !baseUrl.startsWith('https://')) {\n return 'Bilig WorkPaper formula readback failed: baseUrl must start with http:// or https://';\n}\n\nif (!Number.isFinite(value)) {\n return `Bilig WorkPaper formula readback failed: value must be numeric, received ${JSON.stringify($value)}`;\n}\n\nconst response = await fetch(`${baseUrl}/api/workpaper/n8n/forecast`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': 'application/json',\n 'User-Agent': 'Flowise-Bilig-WorkPaper-Tool/0.1'\n },\n body: JSON.stringify({ sheetName, address, value })\n});\n\nconst text = await response.text();\nlet proof;\ntry {\n proof = JSON.parse(text);\n} catch (error) {\n return `Bilig WorkPaper formula readback failed: expected JSON but received ${text.slice(0, 500)}`;\n}\n\nif (!response.ok) {\n return `Bilig WorkPaper formula readback failed: HTTP ${response.status} ${response.statusText} - ${JSON.stringify(proof)}`;\n}\n\nif (proof.verified !== true) {\n return `Bilig WorkPaper formula readback failed: unverified response ${JSON.stringify(proof)}`;\n}\n\nconst checks = proof.checks || {};\nconst before = proof.before || {};\nconst after = proof.after || {};\nconst compactProof = {\n verified: true,\n editedCell: proof.editedCell,\n before: {\n expectedArr: before.expectedArr,\n targetGap: before.targetGap\n },\n after: {\n expectedArr: after.expectedArr,\n targetGap: after.targetGap\n },\n checks: {\n formulasPersisted: checks.formulasPersisted === true,\n restoredMatchesAfter: checks.restoredMatchesAfter === true,\n computedOutputChanged: checks.computedOutputChanged === true\n },\n source: 'Bilig WorkPaper',\n github: 'https://github.com/proompteng/bilig'\n};\n\nreturn JSON.stringify(compactProof, null, 2);" | |
| "func": "const fetch = require('node-fetch');\n\nconst baseUrl = String($baseUrl || 'https://bilig.proompteng.ai').replace(/\\/$/, '');\nconst sheetName = String($sheetName || 'Inputs');\nconst address = String($address || 'B3').toUpperCase();\nconst value = ($value == null || $value === '') ? 0.4 : Number($value);\n\nif (!baseUrl.startsWith('http://') && !baseUrl.startsWith('https://')) {\n return 'Bilig WorkPaper formula readback failed: baseUrl must start with http:// or https://';\n}\n\nif (!Number.isFinite(value)) {\n return 'Bilig WorkPaper formula readback failed: value must be numeric, received ' + JSON.stringify($value);\n}\n\nconst response = await fetch(baseUrl + '/api/workpaper/n8n/forecast', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': 'application/json',\n 'User-Agent': 'Flowise-Bilig-WorkPaper-Tool/0.1'\n },\n body: JSON.stringify({ sheetName, address, value })\n});\n\nconst text = await response.text();\nlet proof;\ntry {\n proof = JSON.parse(text);\n} catch (error) {\n return 'Bilig WorkPaper formula readback failed: expected JSON but received ' + text.slice(0, 500);\n}\n\nif (!response.ok) {\n return 'Bilig WorkPaper formula readback failed: HTTP ' + response.status + ' ' + response.statusText + ' - ' + JSON.stringify(proof);\n}\n\nif (!proof || proof.verified !== true) {\n return 'Bilig WorkPaper formula readback failed: unverified response ' + JSON.stringify(proof);\n}\n\nconst checks = proof.checks || {};\nconst before = proof.before || {};\nconst after = proof.after || {};\nconst compactProof = {\n verified: true,\n editedCell: proof.editedCell,\n before: {\n expectedArr: before.expectedArr,\n targetGap: before.targetGap\n },\n after: {\n expectedArr: after.expectedArr,\n targetGap: after.targetGap\n },\n checks: {\n formulasPersisted: checks.formulasPersisted === true,\n restoredMatchesAfter: checks.restoredMatchesAfter === true,\n computedOutputChanged: checks.computedOutputChanged === true\n },\n source: 'Bilig WorkPaper',\n github: 'https://github.com/proompteng/bilig'\n};\n\nreturn JSON.stringify(compactProof, null, 2);" |
References
- In JavaScript/TypeScript, use loose equality (== null) as a standard idiom for a 'nullish' check that covers both null and undefined.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a Flowise marketplace custom tool for Bilig WorkPaper formula readback.
The tool writes one forecast input cell, calls Bilig to recalculate formulas server-side, rejects unverified responses, and returns a compact before/after proof object. This gives agents a spreadsheet-backed calculation tool without Excel, Google Sheets, browser automation, or trusting stale cached formula values.
Validation
jq empty 'packages/server/marketplaces/tools/Bilig WorkPaper Formula Readback.json'jq -r '.schema' 'packages/server/marketplaces/tools/Bilig WorkPaper Formula Readback.json' | jq emptyfuncfrom the marketplace JSON with Node againsthttps://bilig.proompteng.ai; verifiedverified: trueandafter.expectedArr: 96000Notes
This is a marketplace tool template only. It does not add dependencies or change Flowise runtime code.