Skip to content

Commit ed53b38

Browse files
committed
feat: update configuration handling to support multiple extra prompts and improve prompt retrieval in translation logic
1 parent 871c63a commit ed53b38

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

src/lib/config.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import consola from "consola"
12
import fs from "node:fs"
23

34
import { PATHS } from "./paths"
45

56
export interface AppConfig {
6-
extraPrompt: string
7+
extraPrompts?: Record<string, string>
78
}
89

910
const defaultConfig: AppConfig = {
10-
extraPrompt: `
11+
extraPrompts: {
12+
"gpt-5-codex": `
1113
## Tool use
1214
- You have access to many tools. If a tool exists to perform a specific task, you MUST use that tool instead of running a terminal command to perform that task.
1315
### Bash tool
@@ -24,6 +26,7 @@ When using the TodoWrite tool, follow these rules:
2426
## Special user requests
2527
- If the user makes a simple request (such as asking for the time) which you can fulfill by running a terminal command (such as 'date'), you should do so.
2628
`,
29+
},
2730
}
2831

2932
let cachedConfig: AppConfig | null = null
@@ -57,14 +60,9 @@ function readConfigFromDisk(): AppConfig {
5760
)
5861
return defaultConfig
5962
}
60-
const parsed = JSON.parse(raw) as AppConfig
61-
return parsed
62-
} catch {
63-
fs.writeFileSync(
64-
PATHS.CONFIG_PATH,
65-
`${JSON.stringify(defaultConfig, null, 2)}\n`,
66-
"utf8",
67-
)
63+
return JSON.parse(raw) as AppConfig
64+
} catch (error) {
65+
consola.error("Failed to read config file, using default config", error)
6866
return defaultConfig
6967
}
7068
}
@@ -76,11 +74,7 @@ export function getConfig(): AppConfig {
7674
return cachedConfig
7775
}
7876

79-
export function reloadConfig(): AppConfig {
80-
cachedConfig = null
81-
return getConfig()
82-
}
83-
84-
export function getExtraPrompt(): string {
85-
return getConfig().extraPrompt
77+
export function getExtraPromptForModel(model: string): string {
78+
const config = getConfig()
79+
return config.extraPrompts?.[model] ?? ""
8680
}

src/routes/messages/responses-translation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import consola from "consola"
22

3-
import { getExtraPrompt } from "~/lib/config"
3+
import { getExtraPromptForModel } from "~/lib/config"
44
import {
55
type ResponsesPayload,
66
type ResponseInputContent,
@@ -61,7 +61,7 @@ export const translateAnthropicMessagesToResponsesPayload = (
6161
const responsesPayload: ResponsesPayload = {
6262
model: payload.model,
6363
input,
64-
instructions: translateSystemPrompt(payload.system),
64+
instructions: translateSystemPrompt(payload.system, payload.model),
6565
temperature: payload.temperature ?? null,
6666
top_p: payload.top_p ?? null,
6767
max_output_tokens: payload.max_tokens,
@@ -278,12 +278,13 @@ const createFunctionCallOutput = (
278278

279279
const translateSystemPrompt = (
280280
system: string | Array<AnthropicTextBlock> | undefined,
281+
model: string,
281282
): string | null => {
282283
if (!system) {
283284
return null
284285
}
285286

286-
const extraPrompt = getExtraPrompt()
287+
const extraPrompt = getExtraPromptForModel(model)
287288

288289
if (typeof system === "string") {
289290
return system + extraPrompt

0 commit comments

Comments
 (0)