Add howto function and update metadata for new script file

This change introduces a new asynchronous `howto` function in `deno-ai-mod.ts` that fetches command-line how-to summaries, modifies existing functions to use a new `getBearerToken` utility, and adds metadata for the new `howto.ts` script in `script-meta-v2.json`.
This commit is contained in:
2026-04-12 13:51:23 +08:00
parent 1a5c0f99d2
commit 5a95e619dd
3 changed files with 67 additions and 2 deletions

View File

@@ -5,6 +5,32 @@ import {
term,
} from "https://script.hatter.ink/@67/deno-commons-mod.ts";
export async function howto(message: string): Promise<string> {
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<string> {
const gitStatus = (await execCommand("git", ["status"]))
.assertSuccess().getStdoutAsStringThenTrim();
@@ -15,8 +41,9 @@ export async function summarizeGitStatusDiff(): Promise<string> {
{
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<string> {
}
return (await response.json())["data"]["summary"];
}
async function getBearerToken(token: string): Promise<string> {
return "Bearer " + await getSecretValue(token);
}

View File

@@ -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,

25
single-scripts/howto.ts Executable file
View File

@@ -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<string> => {
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==