feat: add logging
This commit is contained in:
parent
0e55013d64
commit
c961a85add
1 changed files with 13 additions and 2 deletions
15
index.ts
15
index.ts
|
|
@ -177,7 +177,9 @@ try {
|
|||
authConfigDir = await createAuthConfig()
|
||||
process.env["OPENCODE_AUTH_CONFIG_DIR"] = authConfigDir
|
||||
|
||||
proc = spawn(`opencode`, [`serve`, `--hostname=${HOST}`, `--port=${PORT}`])
|
||||
proc = spawn(`opencode`, [`serve`, `--hostname=${HOST}`, `--port=${PORT}`], {
|
||||
stdio: ["ignore", "inherit", "inherit"],
|
||||
})
|
||||
assertContextEvent("issue_comment", "pull_request_review_comment")
|
||||
assertPayloadKeyword()
|
||||
await assertOpencodeConnected()
|
||||
|
|
@ -878,7 +880,16 @@ async function chat(text: string, files: PromptFiles = []) {
|
|||
body: JSON.stringify(body),
|
||||
})
|
||||
|
||||
const chatData = (await chatRes.json()) as { parts?: unknown[]; data?: { parts?: unknown[] } }
|
||||
const rawText = await chatRes.text()
|
||||
if (!chatRes.ok) {
|
||||
throw new Error(`opencode /chat returned ${chatRes.status} ${chatRes.statusText}: ${rawText.slice(0, 1000)}`)
|
||||
}
|
||||
let chatData: { parts?: unknown[]; data?: { parts?: unknown[] } }
|
||||
try {
|
||||
chatData = JSON.parse(rawText)
|
||||
} catch (e) {
|
||||
throw new Error(`opencode /chat returned non-JSON (status ${chatRes.status}, content-type ${chatRes.headers.get("content-type")}): ${rawText.slice(0, 1000)}`)
|
||||
}
|
||||
|
||||
// Find the last text part in the response
|
||||
const parts = chatData?.parts || chatData?.data?.parts || []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue