import { GptApi } from "https://esm.town/v/xkonti/gptApiFramework";
import { Hono } from "npm:hono@3";
import { z } from "npm:zod";
const api = new GptApi({
url: "https://xkonti-tempsimplegptexample.web.val.run",
title: "Some API",
description: "API for something",
version: "1.0.0",
});
const ResponseCommandSchema = z.object({
feedback: z.string().describe("Feedback regarding submitted action"),
data: z.string().optional().describe("Additional data related to the given command"),
}).describe("Contains feedback regarding submitted action");
export type ResponseCommand = z.infer<typeof ResponseCommandSchema>;
api.nothingToJson<ResponseCommand>({
verb: "post",
path: "/someendpoint",
operationId: "doSomething",
desc: "Does something to do something",
requestSchema: null,
requestDesc: null,
responseSchema: ResponseCommandSchema,
responseDesc: "Summary of executed action",
}, async (ctx) => {
return {
feedback: "Did something.",
data: "124 miles",
};
});
const ThingsRequestSchema = z.object({
things: z.array(z.string().describe("A thing to do something with")).describe("A list of things "),
}).describe("Input for the action containing some things");
type ThingsRequest = z.infer<typeof ThingsRequestSchema>;
api.jsonToJson<ThingsRequest, ResponseCommand>({
verb: "post",
path: "/submitthings",
operationId: "submit-things",
desc: "Endpoint for submitting some things",
requestSchema: ThingsRequestSchema,
requestDesc: "Things to do things with",
responseSchema: ResponseCommandSchema,
responseDesc: "Feedback on things",
}, async (ctx, dto) => {
return {
feedback: "Things have been done to things.",
data: "15 things processed",
};
});
export default api.serve();