Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof getUserPrompt>>["promptFiles"]

Expand All @@ -146,15 +146,15 @@ try {
const repoData = await fetchRepo()
session = await client.session.create<true>().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<true>({ path: session })
return session.id.slice(-8)
const result = await client.session.share<true>({ 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
Expand All @@ -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
Expand All @@ -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 })}`)
}
}
Expand Down Expand Up @@ -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 `<a href="${useShareUrl()}/s/${shareId}"><img width="200" alt="${titleAlt}" src="https://social-cards.sst.dev/opencode-share/${title64}.png?model=${providerID}/${modelID}&version=${session.version}&id=${shareId}" /></a>\n`
return `<a href="${shareUrl}"><img width="200" alt="${titleAlt}" src="https://social-cards.sst.dev/opencode-share/${title64}.png?model=${providerID}/${modelID}&version=${session.version}&id=${shareId}" /></a>\n`
})()
const shareUrl = shareId ? `[opencode session](${useShareUrl()}/s/${shareId})&nbsp;&nbsp;|&nbsp;&nbsp;` : ""
return `\n\n${image}${shareUrl}[github run](${useEnvRunUrl()})`
const shareLinkText = shareUrl ? `[opencode session](${shareUrl})&nbsp;&nbsp;|&nbsp;&nbsp;` : ""
return `\n\n${image}${shareLinkText}[github run](${useEnvRunUrl()})`
}

async function fetchRepo() {
Expand Down
21 changes: 11 additions & 10 deletions packages/opencode/src/cli/cmd/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof getUserPrompt>>["promptFiles"]
const triggerCommentId = isCommentEvent
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 `<a href="${shareBaseUrl}/s/${shareId}"><img width="200" alt="${titleAlt}" src="https://social-cards.sst.dev/opencode-share/${title64}.png?model=${providerID}/${modelID}&version=${session.version}&id=${shareId}" /></a>\n`
return `<a href="${shareUrl}"><img width="200" alt="${titleAlt}" src="https://social-cards.sst.dev/opencode-share/${title64}.png?model=${providerID}/${modelID}&version=${session.version}&id=${shareId}" /></a>\n`
})()
const shareUrl = shareId ? `[opencode session](${shareBaseUrl}/s/${shareId})&nbsp;&nbsp;|&nbsp;&nbsp;` : ""
return `\n\n${image}${shareUrl}[github run](${runUrl})`
const shareLinkText = shareUrl ? `[opencode session](${shareUrl})&nbsp;&nbsp;|&nbsp;&nbsp;` : ""
return `\n\n${image}${shareLinkText}[github run](${runUrl})`
}

async function fetchRepo() {
Expand Down
13 changes: 13 additions & 0 deletions packages/sdk/js/src/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,18 @@ export type VcsInfo = {
branch: string
}

export type OutputFormatText = {
type: "text"
}

export type OutputFormatJsonSchema = {
type: "json_schema"
schema: Record<string, unknown>
retryCount?: number
}

export type OutputFormat = OutputFormatText | OutputFormatJsonSchema

export type TextPartInput = {
id?: string
type: "text"
Expand Down Expand Up @@ -2595,6 +2607,7 @@ export type SessionPromptData = {
tools?: {
[key: string]: boolean
}
format?: OutputFormat
parts: Array<TextPartInput | FilePartInput | AgentPartInput | SubtaskPartInput>
}
path: {
Expand Down
Loading