diff --git a/github/index.ts b/github/index.ts index 51ee2a46a531..9b20e6056282 100644 --- a/github/index.ts +++ b/github/index.ts @@ -120,7 +120,7 @@ let octoGraph: typeof graphql let commentId: number let gitConfig: string let session: { id: string; title: string; version: string } -let shareId: string | undefined +let shareUrl: string | undefined let exitCode = 0 type PromptFiles = Awaited>["promptFiles"] @@ -146,15 +146,15 @@ try { const repoData = await fetchRepo() session = await client.session.create().then((r) => r.data) await subscribeSessionEvents() - shareId = await (async () => { + shareUrl = await (async () => { if (useEnvShare() === false) return if (!useEnvShare() && repoData.data.private) return - await client.session.share({ path: session }) - return session.id.slice(-8) + const result = await client.session.share({ path: session }) + return result.data?.share?.url })() console.log("opencode session", session.id) - if (shareId) { - console.log("Share link:", `${useShareUrl()}/s/${shareId}`) + if (shareUrl) { + console.log("Share link:", shareUrl) } // Handle 3 cases @@ -172,7 +172,7 @@ try { const summary = await summarize(response) await pushToLocalBranch(summary) } - const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${useShareUrl()}/s/${shareId}`)) + const hasShared = shareUrl ? prData.comments.nodes.some((c) => c.body.includes(shareUrl)) : false await updateComment(`${response}${footer({ image: !hasShared })}`) } // Fork PR @@ -184,7 +184,7 @@ try { const summary = await summarize(response) await pushToForkBranch(summary, prData) } - const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${useShareUrl()}/s/${shareId}`)) + const hasShared = shareUrl ? prData.comments.nodes.some((c) => c.body.includes(shareUrl)) : false await updateComment(`${response}${footer({ image: !hasShared })}`) } } @@ -815,16 +815,17 @@ function footer(opts?: { image?: boolean }) { const { providerID, modelID } = useEnvModel() const image = (() => { - if (!shareId) return "" + if (!shareUrl) return "" if (!opts?.image) return "" const titleAlt = encodeURIComponent(session.title.substring(0, 50)) const title64 = Buffer.from(session.title.substring(0, 700), "utf8").toString("base64") + const shareId = shareUrl.split("/").pop() || "" - return `${titleAlt}\n` + return `${titleAlt}\n` })() - const shareUrl = shareId ? `[opencode session](${useShareUrl()}/s/${shareId})  |  ` : "" - return `\n\n${image}${shareUrl}[github run](${useEnvRunUrl()})` + const shareLinkText = shareUrl ? `[opencode session](${shareUrl})  |  ` : "" + return `\n\n${image}${shareLinkText}[github run](${useEnvRunUrl()})` } async function fetchRepo() { diff --git a/packages/opencode/src/cli/cmd/github.ts b/packages/opencode/src/cli/cmd/github.ts index a6754ec2df63..0783eb6d683b 100644 --- a/packages/opencode/src/cli/cmd/github.ts +++ b/packages/opencode/src/cli/cmd/github.ts @@ -485,7 +485,7 @@ export const GithubRunCommand = effectCmd({ let octoGraph: typeof graphql let gitConfig: string let session: { id: SessionID; title: string; version: string } - let shareId: string | undefined + let shareUrl: string | undefined let exitCode = 0 type PromptFiles = Awaited>["promptFiles"] const triggerCommentId = isCommentEvent @@ -560,11 +560,11 @@ export const GithubRunCommand = effectCmd({ }), ) subscribeSessionEvents() - shareId = await (async () => { + shareUrl = await (async () => { if (share === false) return if (!share && repoData.data.private) return - await Effect.runPromise(sessionShare.share(session.id)) - return session.id.slice(-8) + const result = await Effect.runPromise(sessionShare.share(session.id)) + return result.url })() console.log("opencode session", session.id) @@ -624,7 +624,7 @@ export const GithubRunCommand = effectCmd({ const summary = await summarize(response) await pushToLocalBranch(summary, uncommittedChanges) } - const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`)) + const hasShared = shareUrl ? prData.comments.nodes.some((c) => c.body.includes(shareUrl)) : false await createComment(`${response}${footer({ image: !hasShared })}`) await removeReaction(commentType) } @@ -642,7 +642,7 @@ export const GithubRunCommand = effectCmd({ const summary = await summarize(response) await pushToForkBranch(summary, prData, uncommittedChanges) } - const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`)) + const hasShared = shareUrl ? prData.comments.nodes.some((c) => c.body.includes(shareUrl)) : false await createComment(`${response}${footer({ image: !hasShared })}`) await removeReaction(commentType) } @@ -1393,16 +1393,17 @@ export const GithubRunCommand = effectCmd({ function footer(opts?: { image?: boolean }) { const image = (() => { - if (!shareId) return "" + if (!shareUrl) return "" if (!opts?.image) return "" const titleAlt = encodeURIComponent(session.title.substring(0, 50)) const title64 = Buffer.from(session.title.substring(0, 700), "utf8").toString("base64") + const shareId = shareUrl.split("/").pop() || "" - return `${titleAlt}\n` + return `${titleAlt}\n` })() - const shareUrl = shareId ? `[opencode session](${shareBaseUrl}/s/${shareId})  |  ` : "" - return `\n\n${image}${shareUrl}[github run](${runUrl})` + const shareLinkText = shareUrl ? `[opencode session](${shareUrl})  |  ` : "" + return `\n\n${image}${shareLinkText}[github run](${runUrl})` } async function fetchRepo() { diff --git a/packages/sdk/js/src/gen/types.gen.ts b/packages/sdk/js/src/gen/types.gen.ts index 8eefe5bfe985..59d01b3dc766 100644 --- a/packages/sdk/js/src/gen/types.gen.ts +++ b/packages/sdk/js/src/gen/types.gen.ts @@ -1401,6 +1401,18 @@ export type VcsInfo = { branch: string } +export type OutputFormatText = { + type: "text" +} + +export type OutputFormatJsonSchema = { + type: "json_schema" + schema: Record + retryCount?: number +} + +export type OutputFormat = OutputFormatText | OutputFormatJsonSchema + export type TextPartInput = { id?: string type: "text" @@ -2595,6 +2607,7 @@ export type SessionPromptData = { tools?: { [key: string]: boolean } + format?: OutputFormat parts: Array } path: {