Skip to content

Commit 8ba1aa2

Browse files
authored
feat(js-x-ray-ai): implement a workspace to combine ai + js-X-ray (#404)
1 parent 4a4154b commit 8ba1aa2

File tree

13 files changed

+1060
-1
lines changed

13 files changed

+1060
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"workspaces/sec-literal",
1515
"workspaces/ts-source-parser",
1616
"workspaces/tracer",
17-
"workspaces/js-x-ray"
17+
"workspaces/js-x-ray",
18+
"workspaces/js-x-ray-ai"
1819
],
1920
"author": "GENTILHOMME Thomas <[email protected]>",
2021
"license": "MIT",

workspaces/js-x-ray-ai/CHANGELOG.md

Whitespace-only changes.

workspaces/js-x-ray-ai/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-2024 NodeSecure
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

workspaces/js-x-ray-ai/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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

Comments
 (0)