Skip to content

Commit a552493

Browse files
committed
chore: code improvements
1 parent 32fcebc commit a552493

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

packages/types/src/provider-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ const openAiNativeSchema = apiModelIdProviderModelSchema.extend({
296296
// OpenAI Responses API service tier for openai-native provider only.
297297
// UI should only expose this when the selected model supports flex/priority.
298298
openAiNativeServiceTier: serviceTierSchema.optional(),
299+
// Disable features that require identity verification.
299300
openAiNativeUnverifiedOrg: z.boolean().optional(),
300301
})
301302

src/api/providers/__tests__/openai-native.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,4 +1954,51 @@ describe("Unverified org gating behavior", () => {
19541954
expect(body.reasoning?.effort).toBeDefined()
19551955
expect(body.reasoning?.summary).toBeUndefined()
19561956
})
1957+
1958+
it("include reasoning.summary in createMessage request when unverified org is false", async () => {
1959+
// Arrange
1960+
const handler = new OpenAiNativeHandler({
1961+
apiModelId: "gpt-5-2025-08-07",
1962+
openAiNativeApiKey: "test-api-key",
1963+
openAiNativeUnverifiedOrg: false, // => stream=true, and summary should be included
1964+
})
1965+
1966+
// Mock SDK to return a proper async iterable for streaming
1967+
const createMockStream = (chunks: any[]) => {
1968+
return {
1969+
async *[Symbol.asyncIterator]() {
1970+
for (const chunk of chunks) {
1971+
yield chunk
1972+
}
1973+
},
1974+
}
1975+
}
1976+
1977+
mockResponsesCreate.mockResolvedValueOnce(
1978+
createMockStream([
1979+
{ type: "response.text.delta", delta: "Test" },
1980+
{
1981+
type: "response.done",
1982+
response: { id: "resp_stream_1", usage: { prompt_tokens: 10, completion_tokens: 1 } },
1983+
},
1984+
]),
1985+
)
1986+
1987+
// Act
1988+
const systemPrompt = "You are a helpful assistant."
1989+
const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hello!" }]
1990+
const stream = handler.createMessage(systemPrompt, messages)
1991+
for await (const _ of stream) {
1992+
// drain
1993+
}
1994+
1995+
// Assert
1996+
expect(mockResponsesCreate).toHaveBeenCalledTimes(1)
1997+
const body = mockResponsesCreate.mock.calls[0][0]
1998+
expect(body.model).toBe("gpt-5-2025-08-07")
1999+
expect(body.stream).toBe(true)
2000+
// GPT-5 includes reasoning effort and summary should be "auto" when unverified org is false
2001+
expect(body.reasoning?.effort).toBeDefined()
2002+
expect(body.reasoning?.summary).toBe("auto")
2003+
})
19572004
})

src/api/providers/openai-native.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
221221
yield* this.executeRequest(requestBody, model, metadata, systemPrompt, messages)
222222
}
223223

224-
private isStreamingAllowed(): boolean {
224+
private canOrganizationUseStreaming(): boolean {
225225
return !this.options.openAiNativeUnverifiedOrg
226226
}
227227

228-
private isReasoningSummaryAllowed(): boolean {
228+
private canOrganizationUseGpt5ReasoningSummary(): boolean {
229229
return !!(this.options.enableGpt5ReasoningSummary && !this.options.openAiNativeUnverifiedOrg)
230230
}
231231

@@ -260,8 +260,8 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
260260
const allowedTierNames = new Set(model.info.tiers?.map((t) => t.name).filter(Boolean) || [])
261261

262262
// Centralized gating for unverified organizations
263-
const stream = this.isStreamingAllowed()
264-
const enableGpt5ReasoningSummary = this.isReasoningSummaryAllowed()
263+
const stream = this.canOrganizationUseStreaming()
264+
const enableGpt5ReasoningSummary = this.canOrganizationUseGpt5ReasoningSummary()
265265

266266
const body: Gpt5RequestBody = {
267267
model: model.id,
@@ -1427,7 +1427,7 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
14271427
if (reasoningEffort) {
14281428
requestBody.reasoning = {
14291429
effort: reasoningEffort,
1430-
...(this.isReasoningSummaryAllowed() ? { summary: "auto" as const } : {}),
1430+
...(this.canOrganizationUseGpt5ReasoningSummary() ? { summary: "auto" as const } : {}),
14311431
}
14321432
}
14331433

0 commit comments

Comments
 (0)