feat: Add rawResponse property to OrchestrationStreamResponse& getRequestId-helpers#1464
feat: Add rawResponse property to OrchestrationStreamResponse& getRequestId-helpers#1464ZhongpinWang merged 11 commits intomainfrom
rawResponse property to OrchestrationStreamResponse& getRequestId-helpers#1464Conversation
There was a problem hiding this comment.
I called it rawHttpResponse instead of rawResponse to stress that it doesn't contain the actual data being streamed.
There was a problem hiding this comment.
It breaks namespace consistency across the API.
The stream use case is orthogonal, so the collision is not a concern here.
There was a problem hiding this comment.
@jerome-benoit Please clarify what you mean with "namespace consistency across the API" in this context. Would you prefer it being called rawResponse? Given the other review comments I will be renaming it to rawResponse.
There was a problem hiding this comment.
@jerome-benoit Please clarify what you mean with "namespace consistency across the API" in this context. Would you prefer it being called
rawResponse? Given the other review comments I will be renaming it torawResponse.
Two different transport layers - slightly -, same overall semantic expected on both content => the namespace should match.
rawHttpResponse property to OrchestrationStreamResponserawHttpResponse property to OrchestrationStreamResponse& getRequestId-helpers
|
The initial streaming HTTP response does not actually contain a |
There was a problem hiding this comment.
This file did not have tests yet, the AI decided to generate a bunch for things that were not covered.
I kept these to increase overall code coverage, but I would be glad to remove additional tests unrelated to the primary PR objective to ease reviewing.
There was a problem hiding this comment.
[pp] I prefer adding this test file in a separate PR. This file is a bit too much to be considered as a small improvement. But thanks for considering the test coverage and please do create a follow-up for this. 👍
ZhongpinWang
left a comment
There was a problem hiding this comment.
The idea if I understand correctly, is just to expose the HttpResponse as part of the OrchestrationStreamResponse object. HttpResponse contains headers, status, data, and every other things that is returned and set by Axios. In case of streaming, data property contains a Node.js Readable object, which users can parse by themselves. (Need to check though if the stream is for sure not consumed by us if user does not iterate the async iterable causing the Readable object been consumed and SSE been parsed.)
There was a problem hiding this comment.
This HttpResponse contains data property, which is a Node.js Readable stream object set by Axios.
See how we are parsing the SSE.
The idea is to expose this HttpResponse object in OrchestrationStreamResponse so that users can parse the data SSE by themselves. And if they do parse by themselves, then OrchestrationStreamResponse cannot be used but then it is user's choice.
But please double check, if data is consumable. My understanding is that if user consumes the stream by running a for await loop, then the stream is not consumable any more. So please check if it is not consumed by a for await, then can the Readable object still be consumed directly from the raw response.
There was a problem hiding this comment.
I have confirmed data can be streamed, but decided against adding an e2e-test for this feature for now. Edit: I added a unit test for this.
| ), | ||
| new OrchestrationStreamResponse() | ||
| new OrchestrationStreamResponse({} as any) | ||
| ); |
There was a problem hiding this comment.
[pp/req] Unfortunately, we have exposed OrchestrationStreamResponse not just as a type. Adding an additional required property in the constructor is a breaking change. Please consider using setter later.
Or perhaps we accept this as a compatibility note. WDYT?
There was a problem hiding this comment.
I did add a compatibility note.
I decided on doing it this way because it means that the new property does not have to be optional, and OrchestrationResponse also add the raw response via a constructor argument.
And while this is a breaking change at the type-level, it doesn't break anything at runtime.
There was a problem hiding this comment.
Make sense. Would of course be nicer if we have exported this as a type only
Perhaps something you can consider doing, also for other response types.
There was a problem hiding this comment.
I've changed the code to handle this gracefully by deprecating the constructor without the OrchestrationResponse, and throwing if OrchestrationResponse is undefined when rawResponse is accessed.
There was a problem hiding this comment.
[pp] I prefer adding this test file in a separate PR. This file is a bit too much to be considered as a small improvement. But thanks for considering the test coverage and please do create a follow-up for this. 👍
There was a problem hiding this comment.
Also please call this property rawResponse same as in the non-streaming response. (I see that we have some inconsistency between embedding and chat client... embedding response calls this response instead of rawResponse... But let's be at least consistent within one client.)
There was a problem hiding this comment.
[pp] If you want, consider deprecate response in embedding client and rename it to rawResponse and check docs. Cosmetic stuff cc @KavithaSiva WDYT?
rawHttpResponse property to OrchestrationStreamResponse& getRequestId-helpersrawResponse property to OrchestrationStreamResponse& getRequestId-helpers
There was a problem hiding this comment.
The pull request adds rawResponse property and getRequestId() helpers to orchestration response classes. I identified three related issues around type consistency and defensive programming for the getRequestId() implementations. The streaming version returns string | undefined while the non-streaming versions return string, but all read from the same field that could theoretically be missing until data is received. This inconsistency should be addressed to prevent potential runtime errors.
PR Bot Information
Version: 1.17.50 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback
- Correlation ID:
fbca84c0-01c3-11f1-911c-0616ae270023 - Event Trigger:
issue_comment.created - LLM:
anthropic--claude-4.5-sonnet
Co-authored-by: Zhongpin Wang <zhongpin.wang@sap.com>
Co-authored-by: Zhongpin Wang <zhongpin.wang@sap.com>
…-streaming * origin/main: feat: Support orchestration prompt module fallback (#1454) v2.7.0 chore: Fix pnpm-lockfile refresh merge condition handling (#1497) feat: Add `rawResponse` property to `OrchestrationStreamResponse`& `getRequestId`-helpers (#1464) chore: Combine ai client type headers (#1545) chore(deps-dev): Bump @sap/cds-dk from 9.7.1 to 9.7.2 (#1548) chore: update pnpm transitive dependencies (#1544)
…uet-cloud-sdk * origin/main: (38 commits) feat: Support orchestration prompt module fallback (#1454) v2.7.0 chore: Fix pnpm-lockfile refresh merge condition handling (#1497) feat: Add `rawResponse` property to `OrchestrationStreamResponse`& `getRequestId`-helpers (#1464) chore: Combine ai client type headers (#1545) chore(deps-dev): Bump @sap/cds-dk from 9.7.1 to 9.7.2 (#1548) chore: update pnpm transitive dependencies (#1544) chore(deps-dev): Bump glob from 13.0.2 to 13.0.3 (#1541) chore(deps-dev): Bump dotenv from 17.2.4 to 17.3.1 (#1540) chore(deps): Bump the langchain group with 3 updates (#1538) feat: Update ai-api specification (#1489) feat: Advertise AbortSignal support for HTTP request cancellation (#1480) chore(deps-dev): Bump orval from 8.2.0 to 8.3.0 (#1536) chore(deps): Bump the langchain group with 3 updates (#1535) feat: Added support for custom headers in document grounding and open ai clients (#1519) chore: Fix rpt (#1533) chore(deps-dev): Bump @types/node from 22.19.10 to 22.19.11 (#1532) chore(deps-dev): Bump glob from 13.0.1 to 13.0.2 (#1530) chore(deps-dev): Bump nock from 14.0.10 to 14.0.11 (#1529) chore(deps): Bump the langchain group with 3 updates (#1528) ...
* origin/main: (39 commits) chore: Improve test coverage on `OrchestrationStreamResponse` (#1478) feat: Support orchestration prompt module fallback (#1454) v2.7.0 chore: Fix pnpm-lockfile refresh merge condition handling (#1497) feat: Add `rawResponse` property to `OrchestrationStreamResponse`& `getRequestId`-helpers (#1464) chore: Combine ai client type headers (#1545) chore(deps-dev): Bump @sap/cds-dk from 9.7.1 to 9.7.2 (#1548) chore: update pnpm transitive dependencies (#1544) chore(deps-dev): Bump glob from 13.0.2 to 13.0.3 (#1541) chore(deps-dev): Bump dotenv from 17.2.4 to 17.3.1 (#1540) chore(deps): Bump the langchain group with 3 updates (#1538) feat: Update ai-api specification (#1489) feat: Advertise AbortSignal support for HTTP request cancellation (#1480) chore(deps-dev): Bump orval from 8.2.0 to 8.3.0 (#1536) chore(deps): Bump the langchain group with 3 updates (#1535) feat: Added support for custom headers in document grounding and open ai clients (#1519) chore: Fix rpt (#1533) chore(deps-dev): Bump @types/node from 22.19.10 to 22.19.11 (#1532) chore(deps-dev): Bump glob from 13.0.1 to 13.0.2 (#1530) chore(deps-dev): Bump nock from 14.0.10 to 14.0.11 (#1529) ...
Context
Closes SAP/ai-sdk-js-backlog#457.
What this PR does and why it is needed