-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ba7aeeb
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
node_modules | ||
dist | ||
.wrangler | ||
.dev.vars | ||
|
||
# Change them to your taste: | ||
wrangler.toml | ||
package-lock.json | ||
yarn.lock | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
``` | ||
npm install | ||
npm run dev | ||
``` | ||
|
||
``` | ||
npm run deploy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"scripts": { | ||
"dev": "wrangler dev src/index.ts", | ||
"deploy": "wrangler deploy --minify src/index.ts" | ||
}, | ||
"dependencies": { | ||
"@hono/zod-openapi": "^0.9.5", | ||
"hono": "^3.12.6" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20231218.0", | ||
"wrangler": "^3.22.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi"; | ||
|
||
type Bindings = { | ||
OPENAPI_VERSION: string; | ||
TOOL_VERSION: string; | ||
TOOL_NAME: string; | ||
TOOL_DESCRIPTION: string; | ||
}; | ||
|
||
const app = new OpenAPIHono<{ Bindings: Bindings }>(); | ||
|
||
app.doc31("/doc", (c) => ({ | ||
openapi: c.env.OPENAPI_VERSION, | ||
info: { | ||
version: c.env.TOOL_VERSION, | ||
title: c.env.TOOL_NAME, | ||
description: c.env.TOOL_DESCRIPTION, | ||
}, | ||
servers: [{ url: new URL(c.req.url).origin }], | ||
})); | ||
|
||
const reqSchema = z.object({ | ||
count: z.number().openapi({ example: 1, description: "Number of quotes to get" }), | ||
}); | ||
|
||
const resSchema = z.object({ | ||
result: z.string().openapi({ example: "ok" }), | ||
}); | ||
|
||
const quoteRoute = createRoute({ | ||
method: "post", | ||
path: "/quotes", | ||
summary: "Get quotes from Breaking Bad", | ||
description: "Retrieve quotes from the Breaking Bad series", | ||
operationId: "GetQuotesFromBreakingBad", | ||
request: { | ||
body: { | ||
content: { | ||
"application/json": { schema: reqSchema }, | ||
}, | ||
}, | ||
}, | ||
responses: { | ||
200: { | ||
content: { | ||
"application/json": { schema: resSchema }, | ||
}, | ||
description: "OK", | ||
}, | ||
}, | ||
}); | ||
|
||
app.openapi(quoteRoute, async (c) => { | ||
const { count } = c.req.valid("json"); | ||
const url = `https://api.breakingbadquotes.xyz/v1/quotes/${count}`; | ||
const result = await fetch(url).then((res) => res.text()); | ||
return c.json({ result }); | ||
}); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"lib": [ | ||
"esnext" | ||
], | ||
"types": [ | ||
"@cloudflare/workers-types" | ||
], | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "hono/jsx" | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name = "dify-custom-tool" | ||
compatibility_date = "2023-12-01" | ||
|
||
# [vars] | ||
OPENAPI_VERSION = "3.1.0" | ||
TOOL_VERSION = "1.0.0" | ||
TOOL_NAME = "Dify Custom Tool" | ||
TOOL_DESCRIPTION = "Dify Custom Tool" | ||
|
||
# [[kv_namespaces]] | ||
# binding = "MY_KV_NAMESPACE" | ||
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
# [[r2_buckets]] | ||
# binding = "MY_BUCKET" | ||
# bucket_name = "my-bucket" | ||
|
||
# [[d1_databases]] | ||
# binding = "DB" | ||
# database_name = "my-database" | ||
# database_id = "" |