mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix: enable OpenAI console logging by default
- Add openAiStoreEnabled configuration option to control OpenAI API request logging - Default store parameter to true to ensure requests appear in OpenAI dashboard - Add comprehensive tests for store parameter behavior - Fixes #7569 where OpenAI API calls were not appearing in console logs
This commit is contained in:
parent
63b71d8299
commit
a22c570bcb
3 changed files with 165 additions and 1 deletions
|
|
@ -1530,5 +1530,161 @@ describe("GPT-5 streaming event coverage (additional)", () => {
|
|||
expect(bodyStr).not.toContain('"verbosity"')
|
||||
})
|
||||
})
|
||||
|
||||
describe("Store parameter behavior", () => {
|
||||
it("should default store to true when openAiStoreEnabled is not set", async () => {
|
||||
const mockFetch = vitest.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
body: new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(
|
||||
new TextEncoder().encode('data: {"type":"response.done","response":{}}\n\n'),
|
||||
)
|
||||
controller.enqueue(new TextEncoder().encode("data: [DONE]\n\n"))
|
||||
controller.close()
|
||||
},
|
||||
}),
|
||||
})
|
||||
;(global as any).fetch = mockFetch as any
|
||||
|
||||
// Force SDK path to fail so we use fetch fallback
|
||||
mockResponsesCreate.mockRejectedValue(new Error("SDK not available"))
|
||||
|
||||
const handler = new OpenAiNativeHandler({
|
||||
apiModelId: "gpt-5-2025-08-07",
|
||||
openAiNativeApiKey: "test-api-key",
|
||||
// openAiStoreEnabled not set - should default to true
|
||||
})
|
||||
|
||||
const systemPrompt = "You are a helpful assistant."
|
||||
const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hello!" }]
|
||||
const stream = handler.createMessage(systemPrompt, messages)
|
||||
|
||||
for await (const _ of stream) {
|
||||
// drain
|
||||
}
|
||||
|
||||
const bodyStr = (mockFetch.mock.calls[0][1] as any).body as string
|
||||
const parsedBody = JSON.parse(bodyStr)
|
||||
expect(parsedBody.store).toBe(true)
|
||||
})
|
||||
|
||||
it("should set store to false when openAiStoreEnabled is false", async () => {
|
||||
const mockFetch = vitest.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
body: new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(
|
||||
new TextEncoder().encode('data: {"type":"response.done","response":{}}\n\n'),
|
||||
)
|
||||
controller.enqueue(new TextEncoder().encode("data: [DONE]\n\n"))
|
||||
controller.close()
|
||||
},
|
||||
}),
|
||||
})
|
||||
;(global as any).fetch = mockFetch as any
|
||||
|
||||
// Force SDK path to fail so we use fetch fallback
|
||||
mockResponsesCreate.mockRejectedValue(new Error("SDK not available"))
|
||||
|
||||
const handler = new OpenAiNativeHandler({
|
||||
apiModelId: "gpt-5-2025-08-07",
|
||||
openAiNativeApiKey: "test-api-key",
|
||||
openAiStoreEnabled: false, // Explicitly disable store
|
||||
})
|
||||
|
||||
const systemPrompt = "You are a helpful assistant."
|
||||
const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hello!" }]
|
||||
const stream = handler.createMessage(systemPrompt, messages)
|
||||
|
||||
for await (const _ of stream) {
|
||||
// drain
|
||||
}
|
||||
|
||||
const bodyStr = (mockFetch.mock.calls[0][1] as any).body as string
|
||||
const parsedBody = JSON.parse(bodyStr)
|
||||
expect(parsedBody.store).toBe(false)
|
||||
})
|
||||
|
||||
it("should respect metadata.store=false even when openAiStoreEnabled is true", async () => {
|
||||
const mockFetch = vitest.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
body: new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(
|
||||
new TextEncoder().encode('data: {"type":"response.done","response":{}}\n\n'),
|
||||
)
|
||||
controller.enqueue(new TextEncoder().encode("data: [DONE]\n\n"))
|
||||
controller.close()
|
||||
},
|
||||
}),
|
||||
})
|
||||
;(global as any).fetch = mockFetch as any
|
||||
|
||||
// Force SDK path to fail so we use fetch fallback
|
||||
mockResponsesCreate.mockRejectedValue(new Error("SDK not available"))
|
||||
|
||||
const handler = new OpenAiNativeHandler({
|
||||
apiModelId: "gpt-5-2025-08-07",
|
||||
openAiNativeApiKey: "test-api-key",
|
||||
openAiStoreEnabled: true, // Store enabled globally
|
||||
})
|
||||
|
||||
const systemPrompt = "You are a helpful assistant."
|
||||
const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hello!" }]
|
||||
const stream = handler.createMessage(systemPrompt, messages, {
|
||||
taskId: "test-task",
|
||||
store: false, // Override with metadata
|
||||
})
|
||||
|
||||
for await (const _ of stream) {
|
||||
// drain
|
||||
}
|
||||
|
||||
const bodyStr = (mockFetch.mock.calls[0][1] as any).body as string
|
||||
const parsedBody = JSON.parse(bodyStr)
|
||||
expect(parsedBody.store).toBe(false)
|
||||
})
|
||||
|
||||
it("should set store to true when both openAiStoreEnabled and metadata.store are not false", async () => {
|
||||
const mockFetch = vitest.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
body: new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(
|
||||
new TextEncoder().encode('data: {"type":"response.done","response":{}}\n\n'),
|
||||
)
|
||||
controller.enqueue(new TextEncoder().encode("data: [DONE]\n\n"))
|
||||
controller.close()
|
||||
},
|
||||
}),
|
||||
})
|
||||
;(global as any).fetch = mockFetch as any
|
||||
|
||||
// Force SDK path to fail so we use fetch fallback
|
||||
mockResponsesCreate.mockRejectedValue(new Error("SDK not available"))
|
||||
|
||||
const handler = new OpenAiNativeHandler({
|
||||
apiModelId: "gpt-5-2025-08-07",
|
||||
openAiNativeApiKey: "test-api-key",
|
||||
openAiStoreEnabled: true,
|
||||
})
|
||||
|
||||
const systemPrompt = "You are a helpful assistant."
|
||||
const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hello!" }]
|
||||
const stream = handler.createMessage(systemPrompt, messages, {
|
||||
taskId: "test-task",
|
||||
// store not specified in metadata - should use global setting
|
||||
})
|
||||
|
||||
for await (const _ of stream) {
|
||||
// drain
|
||||
}
|
||||
|
||||
const bodyStr = (mockFetch.mock.calls[0][1] as any).body as string
|
||||
const parsedBody = JSON.parse(bodyStr)
|
||||
expect(parsedBody.store).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -210,7 +210,9 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
|
|||
model: model.id,
|
||||
input: formattedInput,
|
||||
stream: true,
|
||||
store: metadata?.store !== false, // Default to true unless explicitly set to false
|
||||
// Enable store by default to ensure OpenAI console logging works
|
||||
// Only disable if explicitly set to false via metadata or options
|
||||
store: this.options.openAiStoreEnabled !== false && metadata?.store !== false,
|
||||
// Always include instructions (system prompt) for Responses API.
|
||||
// Unlike Chat Completions, system/developer roles in input have no special semantics here.
|
||||
// The official way to set system behavior is the top-level `instructions` field.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,12 @@ export type ApiHandlerOptions = Omit<ProviderSettings, "apiProvider"> & {
|
|||
* Defaults to true; set to false to disable summaries.
|
||||
*/
|
||||
enableGpt5ReasoningSummary?: boolean
|
||||
/**
|
||||
* Controls whether OpenAI API requests are stored/logged in the OpenAI console.
|
||||
* When true (default), requests will appear in your OpenAI dashboard usage logs.
|
||||
* Set to false to disable OpenAI console logging for privacy or compliance reasons.
|
||||
*/
|
||||
openAiStoreEnabled?: boolean
|
||||
}
|
||||
|
||||
// RouterName
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue