Dax 3 месяцев назад
Родитель
Сommit
16fdc90976

+ 5 - 1
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

@@ -9,7 +9,7 @@ import {
   fg,
   type KeyBinding,
 } from "@opentui/core"
-import { createEffect, createMemo, Match, Switch, type JSX, onMount, batch } from "solid-js"
+import { createEffect, createMemo, Match, Switch, type JSX, onMount } from "solid-js"
 import { useLocal } from "@tui/context/local"
 import { useTheme } from "@tui/context/theme"
 import { SplitBorder } from "@tui/component/border"
@@ -425,6 +425,10 @@ export function Prompt(props: PromptProps) {
         },
         body: {
           agent: local.agent.current().name,
+          model: {
+            providerID: local.model.current().providerID,
+            modelID: local.model.current().modelID,
+          },
           command: inputText,
         },
       })

+ 13 - 15
packages/opencode/src/session/prompt.ts

@@ -600,12 +600,9 @@ export namespace SessionPrompt {
     throw new Error("Impossible")
   })
 
-  async function resolveModel(input: { model: PromptInput["model"]; agent: Agent.Info }) {
-    if (input.model) {
-      return input.model
-    }
-    if (input.agent.model) {
-      return input.agent.model
+  async function lastModel(sessionID: string) {
+    for await (const item of MessageV2.stream(sessionID)) {
+      if (item.info.role === "user" && item.info.model) return item.info.model
     }
     return Provider.defaultModel()
   }
@@ -794,10 +791,7 @@ export namespace SessionPrompt {
       tools: input.tools,
       system: input.system,
       agent: agent.name,
-      model: await resolveModel({
-        model: input.model,
-        agent,
-      }),
+      model: input.model ?? agent.model ?? (await lastModel(input.sessionID)),
     }
 
     const parts = await Promise.all(
@@ -1091,6 +1085,12 @@ export namespace SessionPrompt {
   export const ShellInput = z.object({
     sessionID: Identifier.schema("session"),
     agent: z.string(),
+    model: z
+      .object({
+        providerID: z.string(),
+        modelID: z.string(),
+      })
+      .optional(),
     command: z.string(),
   })
   export type ShellInput = z.infer<typeof ShellInput>
@@ -1100,7 +1100,7 @@ export namespace SessionPrompt {
       SessionRevert.cleanup(session)
     }
     const agent = await Agent.get(input.agent)
-    const model = await resolveModel({ agent, model: undefined })
+    const model = input.model ?? agent.model ?? (await lastModel(input.sessionID))
     const userMsg: MessageV2.User = {
       id: Identifier.ascending("message"),
       sessionID: input.sessionID,
@@ -1338,10 +1338,8 @@ export namespace SessionPrompt {
           return cmdAgent.model
         }
       }
-      if (input.model) {
-        return Provider.parseModel(input.model)
-      }
-      return await Provider.defaultModel()
+      if (input.model) return Provider.parseModel(input.model)
+      return await lastModel(input.sessionID)
     })()
     const agent = await Agent.get(agentName)
 

+ 4 - 0
packages/sdk/js/src/gen/types.gen.ts

@@ -2294,6 +2294,10 @@ export type SessionCommandResponse = SessionCommandResponses[keyof SessionComman
 export type SessionShellData = {
   body?: {
     agent: string
+    model?: {
+      providerID: string
+      modelID: string
+    }
     command: string
   }
   path: {