diff --git a/libraries/deno-ai-mod.ts b/libraries/deno-ai-mod.ts index ec55152..6211a29 100644 --- a/libraries/deno-ai-mod.ts +++ b/libraries/deno-ai-mod.ts @@ -5,6 +5,32 @@ import { 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(); @@ -15,8 +41,9 @@ export async function summarizeGitStatusDiff(): Promise { { method: "POST", headers: { - "Authorization": "Bearer " + - await getSecretValue("ai-commit-summarize-token"), + "Authorization": await getBearerToken( + "ai-commit-summarize-token", + ), }, body: new URLSearchParams({ "gitStatus": gitStatus, @@ -34,3 +61,7 @@ export async function summarizeGitStatusDiff(): Promise { } return (await response.json())["data"]["summary"]; } + +async function getBearerToken(token: string): Promise { + return "Bearer " + await getSecretValue(token); +} diff --git a/script-meta-v2.json b/script-meta-v2.json index 013fa29..c775275 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -151,6 +151,15 @@ "publish_time": 1737375737613, "update_time": 1770822121766 }, + "howto.ts": { + "script_name": "howto.ts", + "script_length": 821, + "script_sha256": "184a8887383342c7aa56adf9d68f1ab87e14cabf2461e9445c1dc975cdc6407f", + "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/howto.ts", + "single_script_file": true, + "publish_time": 1775973075081, + "update_time": 1775973075081 + }, "init-cheatsheet.ts": { "script_name": "init-cheatsheet.ts", "script_length": 1257, diff --git a/single-scripts/howto.ts b/single-scripts/howto.ts new file mode 100755 index 0000000..248ce82 --- /dev/null +++ b/single-scripts/howto.ts @@ -0,0 +1,25 @@ +#!/usr/bin/env runts -- --allow-all + +import {log, ProcessBar,} from "https://script.hatter.ink/@67/deno-commons-mod.ts"; +import {howto} from "https://script.hatter.ink/@1/deno-ai-mod.ts"; + +async function main() { + const message = prompt("Input your message: "); + if (!message) { + throw new Error("Message is required"); + } + const summary = await new ProcessBar("AI howto").call( + async (): Promise => { + return await howto(message); + }, + ); + log.success(`AI howto command line message: \n${summary}`); +} + +main().catch((err) => { + log.error(err); + process.exit(0); +}).then(() => process.exit(0)); + +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T135106+08:00.MEQCICWC9h53VEbG8dkDhZRg +// LBcxOktVwEDhnmlQU0MDXiCEAiAB3frJ/GSnacJJ6FXmljy8NmL9kFbqg6hBJUn49QOOYA==