Skip to content

Commit

Permalink
Add verify command (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
GAllen98 authored Dec 5, 2024
1 parent 2a9627a commit 147c2ce
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 12 deletions.
53 changes: 53 additions & 0 deletions src/commands/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Command } from "commander";

import { PluginService } from "../services/plugin";
import { deployedUrl } from "../utils/deployed-url";
import { validateAndParseOpenApiSpec } from "../utils/openapi";
import { getHostname, getSpecUrl } from "../utils/url-utils";

export const verifyCommand = new Command()
.name("verify")
.description("Request verification of your deployed AI agent plugin")
.requiredOption("-u, --url <url>", "Specify the url of the deployed plugin")
.requiredOption(
"-e, --email <email>",
"Provide an email so we can contact you regarding the verification process",
)
.requiredOption(
"-r, --repo <repoUrl>",
"To verify a plugin we need the url for a public repository containing the plugin's code",
)
.option(
"-v, --version <versionNumber>",
"Specify the version of the plugin in case of an update",
)
.action(async (options) => {
const url = options.url || deployedUrl;

if (!url) {
console.error("Deployed URL could not be determined.");
return;
}

const pluginId = getHostname(url);
const specUrl = getSpecUrl(url);
const { isValid, accountId } = await validateAndParseOpenApiSpec(specUrl);

if (!isValid) {
console.error("OpenAPI specification validation failed.");
return;
}

if (!accountId) {
console.error("Failed to parse account ID from OpenAPI specification.");
return;
}

await new PluginService().verify({
pluginId,
accountId,
email: options.email,
repo: options.repo,
version: options.version,
});
});
20 changes: 9 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { deployCommand } from "./commands/deploy";
import { devCommand } from "./commands/dev";
import { registerCommand } from "./commands/register";
import { updateCommand } from "./commands/update";
import { verifyCommand } from "./commands/verify";

dotenv.config();

Expand All @@ -17,16 +18,13 @@ program
.description("CLI tool for managing AI agents")
.version(packageJson.version);

program.addCommand(devCommand);

program.addCommand(deployCommand);

program.addCommand(contractCommand);

program.addCommand(registerCommand);

program.addCommand(updateCommand);

program.addCommand(deleteCommand);
program
.addCommand(devCommand)
.addCommand(deployCommand)
.addCommand(contractCommand)
.addCommand(registerCommand)
.addCommand(updateCommand)
.addCommand(deleteCommand)
.addCommand(verifyCommand);

program.parse();
4 changes: 3 additions & 1 deletion src/services/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export class AuthenticationService {
server.listen(SIGN_MESSAGE_PORT, () => {
const postEndpoint = `http://localhost:${SIGN_MESSAGE_PORT}`;
const nonce = crypto.randomBytes(16).toString("hex");
const signUrl = `${this.bitteUrls.SIGN_MESSAGE_URL}?message=${encodeURIComponent(
const signUrl = `${
this.bitteUrls.SIGN_MESSAGE_URL
}?message=${encodeURIComponent(
SIGN_MESSAGE,
)}&callbackUrl=${encodeURIComponent(
this.bitteUrls.SIGN_MESSAGE_SUCCESS_URL,
Expand Down
52 changes: 52 additions & 0 deletions src/services/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,56 @@ export class PluginService {
console.error(`Error deleting plugin: ${await response.text()}`);
}
}

async verify({
pluginId,
email,
repo,
version,
accountId,
}: {
pluginId: string;
email: string;
repo: string;
version?: string;
accountId?: string;
}): Promise<void> {
const message = await this.auth.getAuthentication(accountId);
if (!message) {
console.error("No API key found. Unable to request plugin verification.");
return;
}

try {
//const res = await fetch(`${this.bitteUrls.BASE_URL}/verify/${pluginId}`, {
const res = await fetch(
`http://localhost:3001/api/ai-plugins/verify/${pluginId}`,
{
method: "POST",
headers: { "bitte-api-key": message },
body: JSON.stringify({
repo: repo,
email: email,
version: version,
}),
},
);

if (res.ok) {
console.log(
"Your verification request has been uploaded and will be processed in the following days.",
);
} else {
console.error(
`Failed to upload verification request: ${JSON.stringify(
await res.json(),
)} \nStatus: ${res.status}`,
);
}
} catch (error) {
const msg =
error instanceof Error ? error.message : JSON.stringify(error);
console.error(`Failed to request plugin verification: ${msg}`);
}
}
}

0 comments on commit 147c2ce

Please sign in to comment.