generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugin.ts
38 lines (36 loc) · 1.37 KB
/
plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Octokit } from "@octokit/rest";
import { PluginInputs } from "./types";
import { Context } from "./types";
import { Env } from "./types/env";
import { createAdapters } from "./adapters";
import { createClient } from "@supabase/supabase-js";
import { VoyageAIClient } from "voyageai";
import OpenAI from "openai";
import { proxyCallbacks } from "./helpers/callback-proxy";
import { logger } from "./helpers/errors";
export async function plugin(inputs: PluginInputs, env: Env) {
const octokit = new Octokit({ auth: inputs.authToken });
const supabase = createClient(env.SUPABASE_URL, env.SUPABASE_KEY);
const voyageClient = new VoyageAIClient({
apiKey: env.VOYAGEAI_API_KEY,
});
const openAiObject = {
apiKey: (inputs.settings.openAiBaseUrl && env.OPENROUTER_API_KEY) || env.OPENAI_API_KEY,
...(inputs.settings.openAiBaseUrl && { baseURL: inputs.settings.openAiBaseUrl }),
};
const openaiClient = new OpenAI(openAiObject);
const context: Context = {
eventName: inputs.eventName,
payload: inputs.eventPayload,
config: inputs.settings,
octokit,
env,
logger,
adapters: {} as ReturnType<typeof createAdapters>,
};
context.adapters = createAdapters(supabase, voyageClient, openaiClient, context);
return runPlugin(context);
}
export async function runPlugin(context: Context) {
return proxyCallbacks(context)[context.eventName];
}