import { execCommand, fetchDataWithTimeout, getSecretValue, term, } from "https://script.hatter.ink/@67/deno-commons-mod.ts"; export async function howto(message: string): Promise { const response = await fetchDataWithTimeout( "https://hatter.ink/ai/command-line-howto.json", { method: "POST", headers: { "Authorization": await getBearerToken( "ai-command-line-howto-token", ), }, body: new URLSearchParams({ "message": message, }), }, ); if (response.status != 200) { console.log( term.yellow( `Howto command line failed, status: ${response.status}`, ), ); return null; } return (await response.json())["data"]["summary"]; } export async function summarizeGitStatusDiff(): Promise { const gitStatus = (await execCommand("git", ["status"])) .assertSuccess().getStdoutAsStringThenTrim(); const gitDiff = (await execCommand("git", ["diff"])) .assertSuccess().getStdoutAsStringThenTrim(); const response = await fetchDataWithTimeout( "https://hatter.ink/ai/commit-summarize.json", { method: "POST", headers: { "Authorization": await getBearerToken( "ai-commit-summarize-token", ), }, body: new URLSearchParams({ "gitStatus": gitStatus, "gitDiff": gitDiff, }), }, ); if (response.status != 200) { console.log( term.yellow( `Summarize commit message failed, status: ${response.status}`, ), ); return null; } return (await response.json())["data"]["summary"]; } async function getBearerToken(token: string): Promise { return "Bearer " + await getSecretValue(token); }