Add upload tool and related APIs (#187)
* Add utils for r2 upload * Add the tool and new routes * fix auth issue * sign headers * add comment * use our own API key to auth signed uploads * Restructure things slightly * tweak * tweak * add comments * tweak * revert a thing * twaek * drop mime type filtering * new incarnation of mime type filtering * jsut allow all octet-streams * simplify further * tweak * update lockfile --------- Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
This commit is contained in:
committed by
pullfrog[bot]
parent
cac9b0e645
commit
071e885d63
@@ -0,0 +1,91 @@
|
||||
import type { AgentName, BashPermission, ToolPermission } from "../external.ts";
|
||||
import type { RepoContext } from "./github.ts";
|
||||
|
||||
export interface Mode {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
prompt: string;
|
||||
}
|
||||
|
||||
export interface RepoSettings {
|
||||
defaultAgent: AgentName | null;
|
||||
modes: Mode[];
|
||||
repoInstructions: string;
|
||||
web: ToolPermission;
|
||||
search: ToolPermission;
|
||||
write: ToolPermission;
|
||||
bash: BashPermission;
|
||||
}
|
||||
|
||||
export interface RunContext {
|
||||
settings: RepoSettings;
|
||||
apiToken: string;
|
||||
}
|
||||
|
||||
const defaultSettings: RepoSettings = {
|
||||
defaultAgent: null,
|
||||
modes: [],
|
||||
repoInstructions: "",
|
||||
web: "enabled",
|
||||
search: "enabled",
|
||||
write: "enabled",
|
||||
bash: "restricted",
|
||||
};
|
||||
|
||||
const defaultRunContext: RunContext = {
|
||||
settings: defaultSettings,
|
||||
apiToken: "",
|
||||
};
|
||||
|
||||
/**
|
||||
* fetch run context from Pullfrog API
|
||||
* returns settings + API token for subsequent calls
|
||||
* returns defaults if fetch fails
|
||||
*/
|
||||
export async function fetchRunContext(params: {
|
||||
token: string;
|
||||
repoContext: RepoContext;
|
||||
}): Promise<RunContext> {
|
||||
const apiUrl = process.env.API_URL || "https://pullfrog.com";
|
||||
const timeoutMs = 30000;
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${apiUrl}/api/repo/${params.repoContext.owner}/${params.repoContext.name}/run-context`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${params.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
signal: controller.signal,
|
||||
}
|
||||
);
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (!response.ok) {
|
||||
return defaultRunContext;
|
||||
}
|
||||
|
||||
const data = (await response.json()) as {
|
||||
settings: RepoSettings | null;
|
||||
apiToken: string;
|
||||
} | null;
|
||||
|
||||
if (data === null) {
|
||||
return defaultRunContext;
|
||||
}
|
||||
|
||||
return {
|
||||
settings: data.settings ?? defaultSettings,
|
||||
apiToken: data.apiToken,
|
||||
};
|
||||
} catch {
|
||||
clearTimeout(timeoutId);
|
||||
return defaultRunContext;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user