create-cloudflare 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +55072 -44132
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -5
- package/templates/chatgptPlugin/ts/.assets/example.png +0 -0
- package/templates/chatgptPlugin/ts/README.md +25 -0
- package/templates/chatgptPlugin/ts/package-lock.json +1971 -0
- package/templates/chatgptPlugin/ts/package.json +16 -0
- package/templates/chatgptPlugin/ts/src/index.ts +33 -0
- package/templates/chatgptPlugin/ts/src/search.ts +63 -0
- package/templates/chatgptPlugin/ts/wrangler.toml +3 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cloudflare-workers-chatgpt-plugin-example",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"deploy": "wrangler publish",
|
|
7
|
+
"start": "wrangler dev"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@cloudflare/itty-router-openapi": "^0.1.2"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@cloudflare/workers-types": "^4.20230404.0",
|
|
14
|
+
"wrangler": "^2.15.1"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OpenAPIRouter } from "@cloudflare/itty-router-openapi";
|
|
2
|
+
import { GetSearch } from "./search";
|
|
3
|
+
|
|
4
|
+
export const router = OpenAPIRouter({
|
|
5
|
+
schema: {
|
|
6
|
+
info: {
|
|
7
|
+
title: "GitHub Repositories Search API",
|
|
8
|
+
description:
|
|
9
|
+
"A plugin that allows the user to search for GitHub repositories using ChatGPT",
|
|
10
|
+
version: "v0.0.1",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
docs_url: "/",
|
|
14
|
+
aiPlugin: {
|
|
15
|
+
name_for_human: "GitHub Repositories Search",
|
|
16
|
+
name_for_model: "github_repositories_search",
|
|
17
|
+
description_for_human: "GitHub Repositories Search plugin for ChatGPT.",
|
|
18
|
+
description_for_model:
|
|
19
|
+
"GitHub Repositories Search plugin for ChatGPT. You can search for GitHub repositories using this plugin.",
|
|
20
|
+
contact_email: "support@example.com",
|
|
21
|
+
legal_info_url: "http://www.example.com/legal",
|
|
22
|
+
logo_url: "https://workers.cloudflare.com/resources/logo/logo.svg",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
router.get("/search", GetSearch);
|
|
27
|
+
|
|
28
|
+
// 404 for everything else
|
|
29
|
+
router.all("*", () => new Response("Not Found.", { status: 404 }));
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
fetch: router.handle,
|
|
33
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiException,
|
|
3
|
+
OpenAPIRoute,
|
|
4
|
+
Query,
|
|
5
|
+
ValidationError,
|
|
6
|
+
} from "@cloudflare/itty-router-openapi";
|
|
7
|
+
|
|
8
|
+
export class GetSearch extends OpenAPIRoute {
|
|
9
|
+
static schema = {
|
|
10
|
+
tags: ["Search"],
|
|
11
|
+
summary: "Search repositories by a query parameter",
|
|
12
|
+
parameters: {
|
|
13
|
+
q: Query(String, {
|
|
14
|
+
description: "The query to search for",
|
|
15
|
+
default: "cloudflare workers",
|
|
16
|
+
}),
|
|
17
|
+
},
|
|
18
|
+
responses: {
|
|
19
|
+
"200": {
|
|
20
|
+
schema: {
|
|
21
|
+
repos: [
|
|
22
|
+
{
|
|
23
|
+
name: "itty-router-openapi",
|
|
24
|
+
description:
|
|
25
|
+
"OpenAPI 3 schema generator and validator for Cloudflare Workers",
|
|
26
|
+
stars: "80",
|
|
27
|
+
url: "https://github.com/cloudflare/itty-router-openapi",
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
async handle(request: Request, env, ctx, data: Record<string, any>) {
|
|
36
|
+
const url = `https://api.github.com/search/repositories?q=${data.q}`;
|
|
37
|
+
|
|
38
|
+
const resp = await fetch(url, {
|
|
39
|
+
headers: {
|
|
40
|
+
Accept: "application/vnd.github.v3+json",
|
|
41
|
+
"User-Agent": "RepoAI - Cloudflare Workers ChatGPT Plugin Example",
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (!resp.ok) {
|
|
46
|
+
return new Response(await resp.text(), { status: 400 });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const json = await resp.json();
|
|
50
|
+
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
const repos = json.items.map((item: any) => ({
|
|
53
|
+
name: item.name,
|
|
54
|
+
description: item.description,
|
|
55
|
+
stars: item.stargazers_count,
|
|
56
|
+
url: item.html_url,
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
repos: repos,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|