Skip to content

Commit 0ed77ea

Browse files
committed
share sessions
1 parent e871dfa commit 0ed77ea

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

agents/opencode.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const opencodePort = await detectPort(4096);
2929
// Set OpenCode config before server starts to ensure timeout is applied
3030
const opencodeConfig = {
3131
permission: DEFAULT_PERMISSION_CONFIG,
32+
share: "auto",
3233
provider: {
3334
opencode: {
3435
options: {
@@ -199,13 +200,40 @@ const opencodeAgent: AgentDefinition = {
199200
actions.push(JSON.stringify(info));
200201
}
201202

202-
const parts = Array.isArray(data.parts) ? data.parts : [];
203+
const parts = Array.isArray(data.parts) ? data.parts : null;
204+
assert(
205+
parts && parts.length > 0,
206+
"OpenCode response did not include any assistant parts.",
207+
);
203208
parts.forEach((part) => actions.push(JSON.stringify(part)));
204209

205210
if (info) {
206211
logJson({ info }, options);
207212
}
208213
parts.forEach((part) => logJson(part, options));
214+
215+
try {
216+
const { data: sharedSession, error: shareError } =
217+
await opencode.client.session.share({
218+
path: { id: sessionID! },
219+
query: { directory: cwd },
220+
});
221+
if (shareError) {
222+
throw shareError;
223+
}
224+
225+
const shareUrl = sharedSession.share?.url;
226+
if (shareUrl) {
227+
logJson({ shareUrl }, options);
228+
}
229+
} catch (shareError) {
230+
console.error(
231+
`[opencode] Failed to enable sharing for session ${sessionID}:`,
232+
shareError instanceof Error
233+
? shareError.message
234+
: String(shareError),
235+
);
236+
}
209237
} catch (error) {
210238
console.error(
211239
`[opencode] Error in ${model}:`,

0 commit comments

Comments
 (0)