|
| 1 | +<p align="center"> |
| 2 | + <h1 align="center"> |
| 3 | + @nodesecure/js-x-ray-ai |
| 4 | + </h1> |
| 5 | +</p> |
| 6 | + |
| 7 | +<p align="center"> |
| 8 | + JavaScript AST analysis powered by AI |
| 9 | +</p> |
| 10 | + |
| 11 | +## Getting Started |
| 12 | + |
| 13 | +This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com). |
| 14 | + |
| 15 | +```bash |
| 16 | +$ npm i @nodesecure/js-x-ray-ai |
| 17 | +# or |
| 18 | +$ yarn add @nodesecure/js-x-ray-ai |
| 19 | +``` |
| 20 | + |
| 21 | +## Usage example |
| 22 | + |
| 23 | +```javascript |
| 24 | +import { AiAstAnalyser } from "@nodesecure/js-x-ray-ai"; |
| 25 | + |
| 26 | +async function main() { |
| 27 | + const analyzer = new AiAstAnalyser({ |
| 28 | + provider: "openai", |
| 29 | + apiKey: process.env.API_KEY |
| 30 | + }); |
| 31 | + |
| 32 | + const code = ` |
| 33 | + const http = require("http"); |
| 34 | + http.get("http://example.com"); |
| 35 | + `; |
| 36 | + |
| 37 | + const { llm, jsXRay } = await analyzer.analyze(code, "gpt-5"); |
| 38 | + |
| 39 | + console.log(llm); |
| 40 | + console.log(jsXRay); |
| 41 | +} |
| 42 | +main().catch(console.error); |
| 43 | +``` |
| 44 | + |
| 45 | +## API |
| 46 | + |
| 47 | +```ts |
| 48 | +export type Indicator = { |
| 49 | + id: string; |
| 50 | + type: string; |
| 51 | + description: string; |
| 52 | + evidence: string; |
| 53 | + severity: "Critical" | "High" | "Medium" | "Low"; |
| 54 | +}; |
| 55 | + |
| 56 | +export type LlmReport = { |
| 57 | + tldr: string; |
| 58 | + behavior: string; |
| 59 | + indicators: Indicator[]; |
| 60 | + impact: string; |
| 61 | + remediation: string; |
| 62 | + remediationSummary: string; |
| 63 | + confidence: "High" | "Medium" | "Low"; |
| 64 | + confidenceReason: string; |
| 65 | + metadata: { |
| 66 | + linesReferenced: string; |
| 67 | + redactedSecrets: { |
| 68 | + label: string; |
| 69 | + hash: string; |
| 70 | + }; |
| 71 | + }; |
| 72 | +}; |
| 73 | + |
| 74 | +export type Analyses = { |
| 75 | + llm: LlmReport; |
| 76 | + jsXRay: Report; // from @nodesecure/js-x-ray |
| 77 | +}; |
| 78 | + |
| 79 | +export type AiAstAnalyzerOptions = { |
| 80 | + model: string; |
| 81 | + runtimeOptions?: RuntimeOptions; // from @nodesecure/js-x-ray |
| 82 | +}; |
| 83 | + |
| 84 | +export type LlmOptions = { |
| 85 | + provider: "google" | "openai"; |
| 86 | + apiKey: string; |
| 87 | +}; |
| 88 | + |
| 89 | +export class AiAstAnalyser { |
| 90 | + constructor( |
| 91 | + llmOptions: LlmOptions, |
| 92 | + astAnalyzerOptions?: AiAstAnalyzerOptions |
| 93 | + ); |
| 94 | + analyze( |
| 95 | + code: string, |
| 96 | + model: string, |
| 97 | + options?: RuntimeOptions // from @nodesecure/js-x-ray |
| 98 | + ): Promise<Analyses>; |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +## License |
| 103 | + |
| 104 | +MIT |
0 commit comments