✨ 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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user