Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete draftIssue and add slash commands to default config #1087

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@ continue_server.build
continue_server.dist

Icon
Icon?
Icon?
68 changes: 57 additions & 11 deletions core/commands/slash/draftIssue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { ChatMessage, SlashCommand } from "../..";
import { stripImages } from "../../llm/countTokens";
import { removeQuotesAndEscapes } from "../../util";
import axios from 'axios';

// Interfaces for command configuration and issue data
interface CommandConfig {
repositoryUrl: string;
githubToken: string;
}

interface IssueData {
title: string;
body: string;
}

const PROMPT = (
input: string,
Expand All @@ -25,19 +37,17 @@ const DraftIssueCommand: SlashCommand = {
name: "issue",
description: "Draft a GitHub issue",
run: async function* ({ input, llm, history, params }) {
if (params?.repositoryUrl === undefined) {
yield "This command requires a repository URL to be set in the config file.";
return;
}
//get issue title
let title = await llm.complete(
`Generate a title for the GitHub issue requested in this user input: '${input}'. Use no more than 20 words and output nothing other than the title. Do not surround it with quotes. The title is: `,
{ maxTokens: 20 },
);

title = removeQuotesAndEscapes(title.trim()) + "\n\n";
title = '# DRAFT (Continue-generated): ' + removeQuotesAndEscapes(title.trim()) + "\n\n";
yield title;

let body = "";

//get issue body
let body = "## DRAFT: GENERATED BY CONTINUE \n";
const messages: ChatMessage[] = [
...history,
{ role: "user", content: PROMPT(input, title) },
Expand All @@ -48,11 +58,47 @@ const DraftIssueCommand: SlashCommand = {
yield stripImages(chunk.content);
}

const url = `${params.repositoryUrl}/issues/new?title=${encodeURIComponent(
title,
)}&body=${encodeURIComponent(body)}`;
yield `\n\n[Link to draft of issue](${url})`;
//Create isssue in github via api
if (params?.repositoryUrl === undefined || params?.repositoryUrl === "") {
yield "\n\n---\n\n ## Continue Message: No issue link generated: \n" +
"In order to automatically generate a github issue a repository URL needs to be set in the config file.\n";
} else {
const createIssueResponse = await createGitHubIssue(title, body, {
repositoryUrl: params?.repositoryUrl,//this?.params?.repositoryUrl,
githubToken: params?.githubToken || process.env.GITHUB_TOKEN
});

yield '\n\n'+createIssueResponse
}
},
};

async function createGitHubIssue(title: string, body: string, config: CommandConfig): Promise<string> {
if (config.githubToken === undefined) {
return "Github token not provided - define it in env vars or in config params"
}

const url = `${config.repositoryUrl}/issues`;
try {
const response = await axios.post(url, {
title: title.trim(),
body
}, {
headers: {
'Authorization': `token ${config.githubToken}`,
'Accept': 'application/vnd.github.v3+json'
}
});
return `[Link to draft of issue](${response.data.html_url})`; // Returns the URL to the created issue
} catch (error) {
if (axios.isAxiosError(error)) {
console.error('Error creating issue:', error.response?.data || error.message);
return 'Error creating issue:' + (error.response?.data || error.message)
} else {
console.error('Unknown error type:', error);
return 'Error creating issue '+ error
}
}
}

export default DraftIssueCommand;
1 change: 1 addition & 0 deletions core/commands/slash/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const HttpSlashCommand: SlashCommand = {
run: async function* ({ ide, llm, input, params }) {
const url = params?.url;
if (!url) {
yield "URL is not defined in params"
throw new Error("URL is not defined in params");
}
const response = await fetch(url, {
Expand Down
40 changes: 40 additions & 0 deletions core/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ export const defaultConfig: SerializedContinueConfig = {
name: "cmd",
description: "Generate a shell command",
},
{
name: "issue",
description: "Generate a link to a drafted GitHub issue",
params:{
"repositoryUrl": ""
}
},
{
name: "http",
description: "Does something custom",
params: {
"repositoryUrl": ""
}
},
{
name: "commit",
description: "Generate a commit message for the current changes"
},
],
customCommands: [
{
Expand Down Expand Up @@ -112,6 +130,28 @@ export const defaultConfigJetBrains: SerializedContinueConfig = {
name: "share",
description: "Export this session as markdown",
},
{
name: "cmd",
description: "Generate a shell command",
},
{
name: "issue",
description: "Draft a github issue",
params:{
"repositoryUrl": ""
}
},
{
name: "http",
description: "Do something custom",
params: {
"repositoryUrl": ""
}
},
{
name: "commit",
description: "Generate a commit message for the current changes"
},
],
customCommands: [
{
Expand Down
8 changes: 4 additions & 4 deletions core/config/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ function finalToBrowserConfig(
})),
systemMessage: final.systemMessage,
completionOptions: final.completionOptions,
slashCommands: final.slashCommands?.map((m) => ({
name: m.name,
description: m.description,
options: m.params,
slashCommands: final.slashCommands?.map((s) => ({
name: s.name,
description: s.description,
params: s.params,
})),
contextProviders: final.contextProviders?.map((c) => c.description),
disableIndexing: final.disableIndexing,
Expand Down
17 changes: 6 additions & 11 deletions core/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@
resolved "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@esbuild/darwin-arm64@0.19.12":
"@esbuild/linux-x64@0.19.12":
version "0.19.12"
resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.12.tgz"
integrity sha512-B6IeSgZgtEzGC42jsI+YYu9Z3HKRxp8ZT3cqhvliEHovq8HSX2YX8lNocDn79gCKJXOSaEot9MVYky7AKjCs8g==
resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.12.tgz"
integrity sha512-B71g1QpxfwBvNrfyJdVDexenDIt1CiDN1TIXLbhOw0KhJzE78KIFGX6OJ9MrtC0oOqMWf+0xop4qEU8JrJTwCg==

"@eslint-community/eslint-utils@^4.2.0":
version "4.4.0"
Expand Down Expand Up @@ -632,10 +632,10 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@lancedb/vectordb-darwin-arm64@0.4.12":
"@lancedb/vectordb-linux-x64-gnu@0.4.12":
version "0.4.12"
resolved "https://registry.npmjs.org/@lancedb/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.4.12.tgz"
integrity sha512-38/rkJRlWXkPWXuj9onzvbrhnIWcIUQjgEp5G9v5ixPosBowm7A4j8e2Q8CJMsVSNcVX2JLqwWVldiWegZFuYw==
resolved "https://registry.npmjs.org/@lancedb/vectordb-linux-x64-gnu/-/vectordb-linux-x64-gnu-0.4.12.tgz"
integrity sha512-gJqYR0aymrS+C60xc4EQPzmQ5/69XfeFv2ofBvAj7qW+c6BcnoAcfVl+7s1IrcWeGz251sm5cD5Lx4AzJd89dA==

"@mozilla/readability@^0.5.0":
version "0.5.0"
Expand Down Expand Up @@ -2667,11 +2667,6 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@^2.3.2:
version "2.3.3"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==

function-bind@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"
Expand Down
23 changes: 9 additions & 14 deletions extensions/vscode/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@
tar "^6.0.5"
yargs "^17.0.1"

"@esbuild/darwin-arm64@0.17.19":
"@esbuild/linux-x64@0.17.19":
version "0.17.19"
resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.19.tgz"
integrity sha512-80wEoCfF/hFKM6WE1FyBHc9SfUblloAWx6FJkFWTWiCoht9Mc0ARGEM47e67W9rI09YoUxJL68WHfDRYEAvOhg==
resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.19.tgz"
integrity sha512-68ngA9lg2H6zkZcyp22tsVt38mlhWde8l3eJLWkyLrp4HwMUr3c1s/M2t7+kHIhvMjglIBrFpncX1SzMckomGw==

"@esbuild/darwin-arm64@0.18.20":
"@esbuild/linux-x64@0.18.20":
version "0.18.20"
resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.20.tgz"
integrity sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==
resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.20.tgz"
integrity sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==

"@eslint-community/eslint-utils@^4.2.0":
version "4.4.0"
Expand Down Expand Up @@ -691,10 +691,10 @@
resolved "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz"
integrity sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==

"@lancedb/vectordb-darwin-arm64@0.4.12":
"@lancedb/vectordb-linux-x64-gnu@0.4.12":
version "0.4.12"
resolved "https://registry.npmjs.org/@lancedb/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.4.12.tgz"
integrity sha512-38/rkJRlWXkPWXuj9onzvbrhnIWcIUQjgEp5G9v5ixPosBowm7A4j8e2Q8CJMsVSNcVX2JLqwWVldiWegZFuYw==
resolved "https://registry.npmjs.org/@lancedb/vectordb-linux-x64-gnu/-/vectordb-linux-x64-gnu-0.4.12.tgz"
integrity sha512-gJqYR0aymrS+C60xc4EQPzmQ5/69XfeFv2ofBvAj7qW+c6BcnoAcfVl+7s1IrcWeGz251sm5cD5Lx4AzJd89dA==

"@lukeed/csprng@^1.0.0":
version "1.1.0"
Expand Down Expand Up @@ -3445,11 +3445,6 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@^2.3.2, fsevents@~2.3.2:
version "2.3.3"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==

function-bind@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"
Expand Down