Josh Mabry

Josh Mabry

// Name: Search Open PRs
// Description: Search open PRs in a repo
import "@johnlindquist/kit";
const fetch = await npm("node-fetch");
const variables = {
owner: "knapsack-labs",
repoName: "app-monorepo",
};
let token = await env("GITHUB_AUTH_TOKEN", {
hint: `Grab a key from <a href="https://github.com/settings/tokens">here</a>`,
});
const query = `
query getPrs($owner: String!, $repoName: String!) {
repository(owner: $owner, name: $repoName) {
pullRequests(last: 100, states: OPEN) {
nodes {
body
createdAt
mergeable
number
state
title
updatedAt
url
author {
avatarUrl
login
}
}
}
}
}
`;
async function getPrs() {
return fetch("https://api.github.com/graphql", {
headers: {
authorization: `bearer ${token}`,
},
method: "POST",
body: JSON.stringify({ query, variables }),
})
.then((res) => res.json())
.catch((err) => {
console.log(err);
exit();
});
}
const prs = await getPrs();
const openPRs = prs.data.repository.pullRequests.nodes;
const sortedPrs = openPRs.sort(
(a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt)
);
const pr = await arg(
{
placeholder: `Select a PR to view`,
},
sortedPrs.map((pr) => {
return {
name: `${pr.number} - ${pr.title}`,
preview: () =>
`<div class="p-2">
<h2>${pr.number} - ${pr.title}</h2>
<hr class="mb-4"/>
<p>Ready to Merge: ${pr.mergeable === "MERGEABLE" ? "✅" : "⛔"}</p>
<p class="my-4">${md(pr.body)}</p>
<span class="flex flex-row">
<p>Author: ${pr.author.login}</p>
<img class="w-5 h-5 ml-2" src="${pr.author.avatarUrl}" />
</span>
</div>`,
value: pr.number,
};
})
);
const prInfo = sortedPrs.find((p) => p.number === pr);
browse(prInfo.url);

let { GoogleAuth } = await import("google-auth-library");
let { DiscussServiceClient } = await import("@google-ai/generativelanguage");
import "@johnlindquist/kit";
const MODEL_NAME = "models/chat-bison-001";
const API_KEY = await env("PALM_API_KEY", {
hint: `Signup for waitlist here <a href="https://developers.generativeai.google/">here</a>`,
});
const client = new DiscussServiceClient({
authClient: new GoogleAuth().fromAPIKey(API_KEY),
});
const config = {
model: MODEL_NAME,
temperature: 0.75,
candidateCount: 1,
top_k: 40,
top_p: 0.95,
};
const chatHistory = [];
const generateText = async (text) => {
chatHistory.push({ content: text });
const response = await client.generateMessage({
...config,
prompt: {
context: "You are a funny and helpful assistant.",
messages: chatHistory,
},
});
log(response);
log(response[0].filters);
if (response[0].filters.length > 0) {
return `The model has rejected your input. Reason: ${response[0].filters[0].reason}`;
} else {
chatHistory.push({ content: response[0].candidates[0].content });
return response[0].candidates[0].content;
}
};
await chat({
onSubmit: async (input) => {
setLoading(true);
try {
const response = await generateText(input);
let message = md(response);
chat.addMessage("");
chat.setMessage(-1, message);
} catch (e) {
console.log(e);
chat.addMessage("");
chat.setMessage(-1, md("Error: " + e.message));
}
setLoading(false);
},
});

// Name: Static to Dynamic
// Description: Convert static import to dynamic import
// e.g. import { Foo } from "bar";
// to let { Foo } = await import("bar");
// Author: Josh Mabry
// Twitter: @AI_Citizen
import "@johnlindquist/kit";
const text = await getSelectedText();
function convertImportString(input) {
const importRegex = /import\s+({[^}]+})\s+from\s+"([^"]+)";/;
if (!importRegex.test(input)) {
throw new Error("Invalid import string format");
}
const [_, importList, modulePath] = input.match(importRegex);
const output = `let ${importList} = await import("${modulePath}");`;
return output;
}
const output = convertImportString(text);
await setSelectedText(output);