Skip to content

Commit 89d887c

Browse files
authored
Added new action query-codebase (#12904)
1 parent 1d23dfc commit 89d887c

File tree

6 files changed

+161
-8
lines changed

6 files changed

+161
-8
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import app from "../../greptile.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "greptile-query-codebase",
6+
name: "Query Codebase",
7+
description: "Search the user's codebase using a natural language query. [See the documentation](https://docs.greptile.com/apps/overview)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
query: {
13+
type: "string",
14+
label: "Query",
15+
description: "A string containing the question in natural language.",
16+
},
17+
repositories: {
18+
type: "string[]",
19+
label: "Repositories",
20+
description: "List of repositories indexed in Greptile to reference while answering your question. Array of JSON objects with keys `remote`, `branch` and `repository` eg. `{\"remote\":\"github\",\"branch\":\"main\",\"repository\":\"PipedreamHQ/pipedream\"}`",
21+
},
22+
sessionId: {
23+
type: "string",
24+
label: "Session ID",
25+
description: "Only use this if you intend to need to retrieve chat history later.",
26+
optional: true,
27+
},
28+
genius: {
29+
type: "boolean",
30+
label: "Genius",
31+
description: "Genius requests are smarter but 8-10 seconds slower, great for complex usecases like reviewing PR and updating technical docs.",
32+
optional: true,
33+
},
34+
},
35+
methods: {
36+
queryCodebase(args = {}) {
37+
return this.app.post({
38+
path: "/query",
39+
...args,
40+
});
41+
},
42+
},
43+
async run({ $ }) {
44+
const {
45+
queryCodebase,
46+
query,
47+
repositories,
48+
sessionId,
49+
genius,
50+
} = this;
51+
52+
const response = await queryCodebase({
53+
$,
54+
data: {
55+
messages: [
56+
{
57+
content: query,
58+
},
59+
],
60+
repositories: utils.parseArray(repositories),
61+
sessionId,
62+
genius,
63+
},
64+
});
65+
$.export("$summary", "Successfully queried the codebase.");
66+
return response;
67+
},
68+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const BASE_URL = "https://api.greptile.com";
2+
const VERSION_PATH = "/v2";
3+
4+
export default {
5+
BASE_URL,
6+
VERSION_PATH,
7+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
3+
function isJson(value) {
4+
value =
5+
typeof(value) !== "string"
6+
? JSON.stringify(value)
7+
: value;
8+
9+
try {
10+
value = JSON.parse(value);
11+
} catch (e) {
12+
return false;
13+
}
14+
15+
return typeof(value) === "object" && value !== null;
16+
}
17+
18+
function valueToObject(value) {
19+
if (!isJson(value)) {
20+
return value;
21+
}
22+
return JSON.parse(value);
23+
}
24+
25+
function parseArray(value) {
26+
try {
27+
if (!value) {
28+
return [];
29+
}
30+
31+
if (Array.isArray(value)) {
32+
return value;
33+
}
34+
35+
const parsedValue = JSON.parse(value);
36+
37+
if (!Array.isArray(parsedValue)) {
38+
throw new Error("Not an array");
39+
}
40+
41+
return parsedValue;
42+
43+
} catch (e) {
44+
throw new ConfigurationError("Make sure the custom expression contains a valid JSON array object");
45+
}
46+
}
47+
48+
export default {
49+
parseArray: (value) => parseArray(value).map(valueToObject),
50+
};
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "greptile",
4-
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
getUrl(path) {
9+
return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`;
10+
},
11+
getHeaders(headers) {
12+
return {
13+
...headers,
14+
Authorization: `Bearer ${this.$auth.api_key}`,
15+
};
16+
},
17+
_makeRequest({
18+
$ = this, path, headers, ...args
19+
} = {}) {
20+
return axios($, {
21+
...args,
22+
url: this.getUrl(path),
23+
headers: this.getHeaders(headers),
24+
});
25+
},
26+
post(args = {}) {
27+
return this._makeRequest({
28+
method: "POST",
29+
...args,
30+
});
931
},
1032
},
11-
};
33+
};

components/greptile/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/greptile",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Greptile Components",
55
"main": "greptile.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.0"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)