fix: provide first-party OpenAI LLM provider - #1004
Conversation
|
Warning Review limit reached
More reviews will be available in 36 minutes and 24 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (50)
📝 WalkthroughWalkthrough
Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as 호출자
participant OpenAiLlmModel
participant OpenAiTransport
participant normalizeOpenAiError
participant TelemetryApi
Caller->>OpenAiLlmModel: generate(params)
OpenAiLlmModel->>OpenAiLlmModel: resolveApiKey()
OpenAiLlmModel->>OpenAiLlmModel: createResponseRequest()
OpenAiLlmModel->>OpenAiTransport: createResponse(request, {signal})
alt 성공
OpenAiTransport-->>OpenAiLlmModel: OpenAiResponse
OpenAiLlmModel->>OpenAiLlmModel: extractOutputText() + mapUsage()
OpenAiLlmModel->>TelemetryApi: recordEvent(llm.openai.usage)
OpenAiLlmModel-->>Caller: GenerateResult
else 오류
OpenAiTransport-->>OpenAiLlmModel: throw Error
OpenAiLlmModel->>normalizeOpenAiError: normalizeOpenAiError(error, "generate")
normalizeOpenAiError-->>OpenAiLlmModel: OpenAi*Problem
OpenAiLlmModel-->>Caller: throw Problem
end
sequenceDiagram
participant Caller as 호출자
participant OpenAiLlmModel
participant OpenAiTransport
Caller->>OpenAiLlmModel: stream(params)
OpenAiLlmModel->>OpenAiLlmModel: abort 사전 검사
OpenAiLlmModel->>OpenAiTransport: streamResponse(request)
OpenAiTransport-->>OpenAiLlmModel: AsyncIterable~OpenAiStreamEvent~
loop 스트림 이벤트
OpenAiLlmModel->>OpenAiLlmModel: eventToStreamChunk(event)
alt delta 이벤트
OpenAiLlmModel-->>Caller: StreamChunk (delta)
else 완료 이벤트
OpenAiLlmModel-->>Caller: StreamChunk (usage 포함 최종 chunk)
else abort 발생
OpenAiLlmModel-->>Caller: throw OpenAiAbortProblem
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📊 Benchmark Results❌ Some benchmarks failed Gate failures
Updated: 2026-06-19T16:46:39.123Z · Commit: 34f5805 |
e65d8e3 to
9476dfa
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/llm-openai/README.md`:
- Around line 27-30: The example code in the OpenAiLlmModel constructor contains
a non-existent model ID "gpt-5.5" which will cause API validation errors for
users who copy this example. Replace the modelId parameter value "gpt-5.5" with
an actual OpenAI model ID such as "gpt-4o" or "gpt-4-turbo" to ensure the
example code works correctly when users copy and use it.
In `@packages/llm-openai/src/libs/OpenAiLlmModel.ts`:
- Around line 485-486: The embedding index mapping in the find operation within
the `embedMany` function has a logic error where the fallback operator
(`entry.index ?? index`) causes entries with missing indices to match any index
being searched, resulting in misaligned embeddings. Remove the fallback operator
and ensure the find condition directly compares `entry.index === index` to match
entries strictly by their actual index values from the response.
In `@packages/llm-openai/src/tests/OpenAiLiveSmoke.spec.ts`:
- Around line 35-38: The requireApiKey function is throwing a generic Error
instead of a Problem subclass, which violates the repository coding guidelines.
Replace the throw statement in the requireApiKey function that currently uses
throw new Error with an appropriate Problem subclass such as
OpenAiMissingConfigProblem to maintain consistent exception handling throughout
the codebase.
In `@packages/llm-openai/src/tests/OpenAiLlmModel.spec.ts`:
- Around line 344-411: Replace all instances of the assertion pattern
rejects.toBeInstanceOf(...) with rejects.toThrow(...) throughout the test file.
Specifically, update the four test cases that check for error conditions: the
initial stream abort test, the "surfaces mid-stream aborts as Croco Problems"
test using iterator.next(), the "fails deterministically when SDK-backed
configuration is missing" test for OpenAiMissingConfigProblem, and the "rejects
invalid provider payloads with Croco Problems" and "rejects non-object tool
argument payloads with Croco Problems" tests for OpenAiInvalidResponseProblem.
Change expect(...).rejects.toBeInstanceOf(ErrorClass) to
expect(...).rejects.toThrow(ErrorClass) for each assertion to align with the
testing guidelines.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6e39b0d0-e521-46b4-a109-352321003917
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (48)
.changeset/llm-openai-provider.mdREADME.mddocs/package-catalog.jsondocs/package-docs-report.mdpackages/docs/astro.config.mjspackages/docs/package.jsonpackages/docs/src/content/docs/api/llm-core/src/classes/LlmModel.mdpackages/docs/src/content/docs/api/llm-openai/src/classes/OpenAiAbortProblem.mdpackages/docs/src/content/docs/api/llm-openai/src/classes/OpenAiAuthenticationProblem.mdpackages/docs/src/content/docs/api/llm-openai/src/classes/OpenAiInvalidResponseProblem.mdpackages/docs/src/content/docs/api/llm-openai/src/classes/OpenAiLlmModel.mdpackages/docs/src/content/docs/api/llm-openai/src/classes/OpenAiMissingConfigProblem.mdpackages/docs/src/content/docs/api/llm-openai/src/classes/OpenAiRateLimitProblem.mdpackages/docs/src/content/docs/api/llm-openai/src/classes/OpenAiRetryableUpstreamProblem.mdpackages/docs/src/content/docs/api/llm-openai/src/classes/OpenAiTerminalUpstreamProblem.mdpackages/docs/src/content/docs/api/llm-openai/src/classes/OpenAiValidationProblem.mdpackages/docs/src/content/docs/api/llm-openai/src/functions/createOpenAiSdkTransport.mdpackages/docs/src/content/docs/api/llm-openai/src/functions/normalizeOpenAiError.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiEmbeddingRequest.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiEmbeddingResponse.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiEnvironment.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiInputMessage.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiLlmModelConfig.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiRequestOptions.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiResponse.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiResponseRequest.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiSdkTransportOptions.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiStreamEvent.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiTransport.mdpackages/docs/src/content/docs/api/llm-openai/src/type-aliases/OpenAiUsage.mdpackages/docs/src/content/docs/api/problems-core/src/classes/Problem.mdpackages/docs/src/content/docs/en/reference/extension-matrix.mdpackages/docs/tsconfig.typedoc.jsonpackages/llm-openai/CHANGELOG.mdpackages/llm-openai/README.mdpackages/llm-openai/package.jsonpackages/llm-openai/src/index.tspackages/llm-openai/src/libs/OpenAiLlmModel.tspackages/llm-openai/src/libs/OpenAiSdkTransport.tspackages/llm-openai/src/libs/problems/OpenAiProblems.tspackages/llm-openai/src/libs/types.tspackages/llm-openai/src/tests/OpenAiLiveSmoke.spec.tspackages/llm-openai/src/tests/OpenAiLlmModel.spec.tspackages/llm-openai/src/tests/OpenAiProblems.spec.tspackages/llm-openai/tsconfig.jsonpackages/llm-openai/vitest.config.tspackages/testing/src/libs/llm-provider-conformance.tspublic-api-surface.snapshot.json
9476dfa to
0b77da0
Compare
0b77da0 to
3a07bdf
Compare
3a07bdf to
2e7856e
Compare
Fixes #951.
Summary
@croco/llm-openainow provides a first-party OpenAI provider backed by the OpenAI SDK Responses and Embeddings APIs.The provider covers text generation, streaming with usage and abort behavior, strict JSON schema structured output, function tool calls, single and batch embeddings, deterministic OpenAI-to-Croco Problem normalization, and telemetry spans/events through
@croco/telemetry-apiwithout global SDK initialization.The package is wired into the package catalog, extension matrix, generated API docs, public API snapshot, lockfile, and release changesets. Its README documents configuration, env vars, supported operations, unsupported features, metering, telemetry, and the env-gated live smoke command.
Verification
pnpm --filter @croco/llm-openai test- passed, 23 tests and 1 skipped live smoke.pnpm --filter @croco/llm-openai typecheck- passed.pnpm --filter @croco/llm-openai build- passed.pnpm --filter @croco/testing test- passed, 30 tests.pnpm --filter @croco/testing typecheck- passed.pnpm --filter @croco/testing build- passed.pnpm docs:catalog:check- passed.pnpm public-api:check- passed, 100 snapshots match.pnpm check- passed.pnpm changeset-required:check -- --base origin/trunk --head HEAD- passed.pnpm testpassed, 205/205 Turbo tasks; fullpnpm typecheckpassed, 204/204 Turbo tasks.Self-review gates
OPENAI_API_KEY.Independent review
An independent adversarial review found three actionable issues before the PR was opened: aborted streams completed as success, embedding usage telemetry ignored per-call model overrides, and parsed tool-call arguments were cast without object validation. The final patch now throws deterministic abort Problems, records the effective embedding model in telemetry, validates parsed tool arguments as non-array objects, and includes regression coverage for each case.
Risk
Low-medium. Default CI uses deterministic mocked OpenAI transport; live OpenAI smoke remains credential-gated and was not run locally because no
OPENAI_API_KEYwas present.Summary by CodeRabbit
릴리스 노트
새로운 기능
문서화
테스트