Explorar el Código

switch gpt-5 to codex prompt

Dax Raad hace 6 meses
padre
commit
13d3fba86b

+ 3 - 2
packages/opencode/src/plugin/index.ts

@@ -4,7 +4,8 @@ import { Config } from "../config/config"
 import { Bus } from "../bus"
 import { Bus } from "../bus"
 import { Log } from "../util/log"
 import { Log } from "../util/log"
 import { createOpencodeClient } from "@opencode-ai/sdk"
 import { createOpencodeClient } from "@opencode-ai/sdk"
-import { Server } from "../server/server"
+// Lazy import to avoid circular dependency with session/tool registry
+// import { Server } from "../server/server"
 import { BunProc } from "../bun"
 import { BunProc } from "../bun"
 
 
 export namespace Plugin {
 export namespace Plugin {
@@ -13,7 +14,7 @@ export namespace Plugin {
   const state = App.state("plugin", async (app) => {
   const state = App.state("plugin", async (app) => {
     const client = createOpencodeClient({
     const client = createOpencodeClient({
       baseUrl: "http://localhost:4096",
       baseUrl: "http://localhost:4096",
-      fetch: async (...args) => Server.app().fetch(...args),
+      fetch: async (...args) => (await import("../server/server")).Server.app().fetch(...args),
     })
     })
     const config = await Config.get()
     const config = await Config.get()
     const hooks = []
     const hooks = []

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

@@ -1007,7 +1007,7 @@ export namespace Session {
       async process(stream: StreamTextResult<Record<string, AITool>, never>) {
       async process(stream: StreamTextResult<Record<string, AITool>, never>) {
         try {
         try {
           let currentText: MessageV2.TextPart | undefined
           let currentText: MessageV2.TextPart | undefined
-          let reasoningMap: Record<string, MessageV2.ReasoningPart> = {}
+          // let reasoningMap: Record<string, MessageV2.ReasoningPart> = {}
 
 
           for await (const value of stream.fullStream) {
           for await (const value of stream.fullStream) {
             log.info("part", {
             log.info("part", {
@@ -1017,6 +1017,7 @@ export namespace Session {
               case "start":
               case "start":
                 break
                 break
 
 
+              /*
               case "reasoning-start":
               case "reasoning-start":
                 if (value.id in reasoningMap) {
                 if (value.id in reasoningMap) {
                   continue
                   continue
@@ -1045,15 +1046,16 @@ export namespace Session {
                 if (value.id in reasoningMap) {
                 if (value.id in reasoningMap) {
                   const part = reasoningMap[value.id]
                   const part = reasoningMap[value.id]
                   part.text = part.text.trimEnd()
                   part.text = part.text.trimEnd()
-                  part.providerMetadata = value.providerMetadata
+                  part.metadata = value.providerMetadata
                   part.time = {
                   part.time = {
-                    start: Date.now(),
+                    ...part.time,
                     end: Date.now(),
                     end: Date.now(),
                   }
                   }
                   await updatePart(part)
                   await updatePart(part)
                   delete reasoningMap[value.id]
                   delete reasoningMap[value.id]
                 }
                 }
                 break
                 break
+                */
 
 
               case "tool-input-start":
               case "tool-input-start":
                 const part = await updatePart({
                 const part = await updatePart({

+ 5 - 7
packages/opencode/src/session/message-v2.ts

@@ -121,13 +121,11 @@ export namespace MessageV2 {
   export const ReasoningPart = PartBase.extend({
   export const ReasoningPart = PartBase.extend({
     type: z.literal("reasoning"),
     type: z.literal("reasoning"),
     text: z.string(),
     text: z.string(),
-    providerMetadata: z.record(z.any()).optional(),
-    time: z
-      .object({
-        start: z.number(),
-        end: z.number().optional(),
-      })
-      .optional(),
+    metadata: z.record(z.any()).optional(),
+    time: z.object({
+      start: z.number(),
+      end: z.number().optional(),
+    }),
   }).openapi({
   }).openapi({
     ref: "ReasoningPart",
     ref: "ReasoningPart",
   })
   })

+ 2 - 0
packages/opencode/src/session/system.ts

@@ -13,6 +13,7 @@ import PROMPT_GEMINI from "./prompt/gemini.txt"
 import PROMPT_ANTHROPIC_SPOOF from "./prompt/anthropic_spoof.txt"
 import PROMPT_ANTHROPIC_SPOOF from "./prompt/anthropic_spoof.txt"
 import PROMPT_SUMMARIZE from "./prompt/summarize.txt"
 import PROMPT_SUMMARIZE from "./prompt/summarize.txt"
 import PROMPT_TITLE from "./prompt/title.txt"
 import PROMPT_TITLE from "./prompt/title.txt"
+import PROMPT_CODEX from "./prompt/codex.txt"
 
 
 export namespace SystemPrompt {
 export namespace SystemPrompt {
   export function header(providerID: string) {
   export function header(providerID: string) {
@@ -20,6 +21,7 @@ export namespace SystemPrompt {
     return []
     return []
   }
   }
   export function provider(modelID: string) {
   export function provider(modelID: string) {
+    if (modelID.includes("gpt-5")) return [PROMPT_CODEX]
     if (modelID.includes("gpt-") || modelID.includes("o1") || modelID.includes("o3")) return [PROMPT_BEAST]
     if (modelID.includes("gpt-") || modelID.includes("o1") || modelID.includes("o3")) return [PROMPT_BEAST]
     if (modelID.includes("gemini-")) return [PROMPT_GEMINI]
     if (modelID.includes("gemini-")) return [PROMPT_GEMINI]
     if (modelID.includes("claude")) return [PROMPT_ANTHROPIC]
     if (modelID.includes("claude")) return [PROMPT_ANTHROPIC]