MCPcopy Create free account
hub / github.com/anomalyco/opencode-bench / run

Function run

src/agents/opencode.ts:58–135  ·  view source on GitHub ↗
(model, prompt, options)

Source from the content-addressed store, hash-verified

56
57const opencodeAgent: Agent.Definition = {
58 async run(model, prompt, options) {
59 options.logger.log(`opencode --model ${model} ${prompt}`);
60
61 const cacheKey = sessionKey(model, options.cwd);
62
63 options.logger.log(`Creating session...`);
64 let sessionID = sessionCache.get(cacheKey);
65 if (!sessionID) {
66 const { data: session } = await opencode.client.session.create({
67 query: { directory: options.cwd },
68 throwOnError: true,
69 });
70 sessionID = session.id;
71 sessionCache.set(cacheKey, sessionID);
72 }
73
74 options.logger.log(`Sharing session ${sessionID}...`);
75 try {
76 const { data, error } = await opencode.client.session.share({
77 path: { id: sessionID! },
78 query: { directory: options.cwd },
79 });
80 if (error) throw error;
81
82 const shareUrl = data.share?.url;
83 options.logger.log(`Share URL: ${shareUrl}`);
84 } catch (e) {
85 options.logger.error(
86 `Failed to enable sharing for session ${sessionID}:`,
87 e,
88 );
89 }
90
91 options.logger.log(`Prompting session ${sessionID}...`);
92 const [providerID, modelID] = model.split("/");
93 const actions: string[] = [];
94 const usage = {
95 input: 0,
96 output: 0,
97 cost: 0,
98 };
99 try {
100 const { data, error } = await opencode.client.session.prompt({
101 path: { id: sessionID! },
102 query: { directory: options.cwd },
103 body: {
104 model: {
105 providerID,
106 modelID,
107 },
108 parts: [{ type: "text", text: prompt }],
109 },
110 });
111
112 if (error) throw error;
113 options.logger.debug(`Data: ${JSON.stringify(data)}`);
114
115 const info = data.info;

Callers

nothing calls this directly

Calls 1

sessionKeyFunction · 0.70

Tested by

no test coverage detected