-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect.ts
More file actions
52 lines (43 loc) · 1.62 KB
/
inspect.ts
File metadata and controls
52 lines (43 loc) · 1.62 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { AIPlugin } from "../ai_plugin";
import { AuthProvider } from "../auth_provider";
import type { TokenProvider } from "../auth_provider";
import { ManifestSchema } from "../manifest_schema";
import { OpenAPIExplorer } from "../openapi_explorer";
import type { Method } from "../openapi_provider";
import { PluginExplorer } from "../plugin_explorer";
import { RedirectValidator } from "../redirect_validator";
const main = async () => {
const [, , url, method, endpoint, parameters, ...others] = process.argv;
if (!url) {
throw new Error("A url must be provided");
}
const redirectValidator = new RedirectValidator();
const explorer = new PluginExplorer(fetch, ManifestSchema, redirectValidator);
console.log("Provided url", url);
const manifest = await explorer.inspect(url);
console.log("Fetched manifest", manifest?.name_for_human);
if (!manifest) {
return;
}
const authProvider = new AuthProvider(manifest, "openai");
const openApiExplorer = new OpenAPIExplorer(fetch, redirectValidator);
const plugin = new AIPlugin(manifest, fetch, authProvider, openApiExplorer);
console.log("Plugin", plugin);
if (endpoint && method) {
console.log("Interacting with", method, endpoint);
// TODO: interact with authenticated plugins
const tokenProvider: TokenProvider = {
getOAuthToken: async () => "",
getUserToken: async () => "",
};
const res = await plugin.interact(
endpoint,
method as Method,
parameters,
tokenProvider
);
console.log("Interacted with", method, endpoint, parameters);
console.log("Received", await res.text());
}
};
main();