Dax Raad 8 месяцев назад
Родитель
Сommit
9147108675

+ 9 - 3
packages/opencode/src/session/index.ts

@@ -185,7 +185,7 @@ export namespace Session {
         previous.metadata.assistant.tokens.output
       if (
         tokens >
-        (model.info.contextWindow - (model.info.maxOutputTokens ?? 0)) * 0.9
+        (model.info.limit.context - (model.info.limit.output ?? 0)) * 0.9
       ) {
         await summarize({
           sessionID: input.sessionID,
@@ -507,6 +507,7 @@ export namespace Session {
         await updateMessage(next)
       },
       onError(input) {
+        log.error("error", input)
         if (input.error instanceof Error) {
           next.metadata.error = input.error.toString()
         }
@@ -520,7 +521,6 @@ export namespace Session {
       },
       toolCallStreaming: false,
       abortSignal: abort.signal,
-      maxRetries: 6,
       stopWhen: stepCountIs(1000),
       messages: convertToModelMessages(msgs),
       temperature: 0,
@@ -530,7 +530,13 @@ export namespace Session {
       },
       model: model.language,
     })
-    await result.consumeStream()
+    await result.consumeStream({
+      onError: (err) => {
+        log.error("error", {
+          err,
+        })
+      },
+    })
     next.metadata!.time.completed = Date.now()
     await updateMessage(next)
     return next

+ 8 - 1
packages/opencode/src/tool/webfetch.ts

@@ -99,6 +99,13 @@ function extractTextFromHTML(html: string): string {
 }
 
 function convertHTMLToMarkdown(html: string): string {
-  const turndownService = new TurndownService()
+  const turndownService = new TurndownService({
+    headingStyle: "atx",
+    hr: "---",
+    bulletListMarker: "-",
+    codeBlockStyle: "fenced",
+    emDelimiter: "*",
+  })
+  turndownService.remove(["script", "style", "meta", "link"])
   return turndownService.turndown(html)
 }

+ 2 - 2
packages/opencode/src/util/log.ts

@@ -51,10 +51,10 @@ export namespace Log {
         write.out(build(message, extra))
       },
       error(message?: any, extra?: Record<string, any>) {
-        write.err(build(message, extra))
+        write.out(build(message, extra))
       },
       warn(message?: any, extra?: Record<string, any>) {
-        write.err(build(message, extra))
+        write.out(build(message, extra))
       },
       tag(key: string, value: string) {
         if (tags) tags[key] = value