-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
62 lines (55 loc) · 1.94 KB
/
Copy pathindex.ts
File metadata and controls
62 lines (55 loc) · 1.94 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
53
54
55
56
57
58
59
60
61
62
import type { Plugin } from "@opencode-ai/plugin";
import type { Config as ConfigV2 } from "@opencode-ai/sdk/v2"
import { existsSync, readFileSync } from "node:fs";
import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";
const current_dir = dirname(fileURLToPath(import.meta.url));
const root_dir = path.join(current_dir, "..");
export const ApifyPlugin: Plugin = async () => {
const agentPath = path.join(root_dir, "agents/apify.md")
if (!existsSync(agentPath)) {
throw new Error('Apify agent.md not found')
}
const agent = readFileSync(agentPath, "utf8")
const skillsPath = path.join(root_dir, "skills")
if (!existsSync(skillsPath)) {
throw new Error('Apify skills not found')
}
const instructionsPath = path.join(root_dir, "instructions/apify-routing.md")
if (!existsSync(instructionsPath)) {
throw new Error('Apify instructions not found')
}
return {
config: async (config) => {
// ConfigV2 includes `skills` which isn't in the plugin's Config type yet
const cfg = config as typeof config & Pick<ConfigV2, "skills">
cfg.mcp = { ...cfg.mcp, apify: { type: "remote", enabled: true, url: "https://mcp.apify.com/?client=opencode+plugin" } }
cfg.agent = {
...cfg.agent,
apify: {
prompt: agent,
mode: "all",
tools: {
"apify_*": true,
},
description: "Anything related to Apify, use the apify_* tools to interact with the Apify platform.",
},
}
cfg.skills = {
...cfg.skills,
paths: [...(cfg.skills?.paths ?? []), skillsPath],
}
cfg.tools = {
...cfg.tools,
"apify_*": true,
}
cfg.instructions = [...(cfg.instructions ?? []), instructionsPath]
},
"shell.env": async (_input, output) => {
if (process.env.APIFY_TOKEN) {
output.env.APIFY_TOKEN = process.env.APIFY_TOKEN;
}
},
}
}
export default ApifyPlugin;