@sap-ai-sdk/orchestration 1.5.1-20250113013141.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -86,6 +86,125 @@ The client allows you to combine various modules, such as templating and content
86
86
 
87
87
  In addition to the examples below, you can find more **sample code** [here](https://github.com/SAP/ai-sdk-js/blob/main/sample-code/src/orchestration.ts).
88
88
 
89
+ ### Streaming
90
+
91
+ The `OrchestrationClient` supports streaming responses for chat completion requests based on the [Server-sent events](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events) standard.
92
+
93
+ Use the `stream()` method to receive a stream of chunk responses from the model.
94
+ After consuming the stream, call the helper methods to get the finish reason and token usage information.
95
+
96
+ ```ts
97
+ const orchestrationClient = new OrchestrationClient({
98
+ llm: {
99
+ model_name: 'gpt-4o',
100
+ model_params: { max_tokens: 50, temperature: 0.1 }
101
+ },
102
+ templating: {
103
+ template: [
104
+ { role: 'user', content: 'Give a long history of {{?country}}?' }
105
+ ]
106
+ }
107
+ });
108
+
109
+ const response = await orchestrationClient.stream({
110
+ inputParams: { country: 'France' }
111
+ });
112
+
113
+ for await (const chunk of response.stream) {
114
+ console.log(JSON.stringify(chunk));
115
+ }
116
+
117
+ const finishReason = response.getFinishReason();
118
+ const tokenUsage = response.getTokenUsage();
119
+
120
+ console.log(`Finish reason: ${finishReason}\n`);
121
+ console.log(`Token usage: ${JSON.stringify(tokenUsage)}\n`);
122
+ ```
123
+
124
+ #### Streaming the Delta Content
125
+
126
+ The client provides a helper method to extract the text chunks as strings:
127
+
128
+ ```ts
129
+ for await (const chunk of response.stream.toContentStream()) {
130
+ console.log(chunk); // will log the delta content
131
+ }
132
+ ```
133
+
134
+ Each chunk will be a string containing the delta content.
135
+
136
+ #### Streaming with Abort Controller
137
+
138
+ Streaming request can be aborted using the `AbortController` API.
139
+ In case of an error, the SAP Cloud SDK for AI will automatically close the stream.
140
+ Additionally, it can be aborted manually by calling the `stream()` method with an `AbortController` object.
141
+
142
+ ```ts
143
+ const orchestrationClient = new OrchestrationClient({
144
+ llm: {
145
+ model_name: 'gpt-4o',
146
+ model_params: { max_tokens: 50, temperature: 0.1 }
147
+ },
148
+ templating: {
149
+ template: [
150
+ { role: 'user', content: 'Give a long history of {{?country}}?' }
151
+ ]
152
+ }
153
+ });
154
+
155
+ const controller = new AbortController();
156
+ const response = await orchestrationClient.stream(
157
+ {
158
+ inputParams: { country: 'France' }
159
+ },
160
+ controller
161
+ );
162
+
163
+ // Abort the streaming request after one second
164
+ setTimeout(() => {
165
+ controller.abort();
166
+ }, 1000);
167
+
168
+ for await (const chunk of response.stream) {
169
+ console.log(JSON.stringify(chunk));
170
+ }
171
+ ```
172
+
173
+ In this example, streaming request will be aborted after one second.
174
+ Abort controller can be useful, e.g., when end-user wants to stop the stream or refreshes the page.
175
+
176
+ #### Stream Options
177
+
178
+ The orchestration service offers multiple streaming options, which you can configure in addition to the LLM's streaming options.
179
+ These include options like definining the maximum number of characters per chunk or modifying the output filter behavior.
180
+ There are two ways to add specific streaming options to your client, either at initialization of orchestration client, or when calling the stream API.
181
+
182
+ Setting streaming options dynamically could be useful if an initialized orchestration client will also be used for streaming.
183
+
184
+ You can check the list of available stream options in the [orchestration service's documentation](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/streaming).
185
+
186
+ An example for setting the streaming options when calling the stream API looks like the following:
187
+
188
+ ```ts
189
+ const response = orchestrationClient.stream(
190
+ {
191
+ inputParams: { country: 'France' }
192
+ },
193
+ controller,
194
+ {
195
+ llm: { include_usage: false },
196
+ global: { chunk_size: 10 },
197
+ outputFiltering: { overlap: 200 }
198
+ }
199
+ );
200
+ ```
201
+
202
+ Usage metrics are collected by default, if you do not want to receive them, set `include_usage` to `false`.
203
+ If you don't want any streaming options as part of your call to the LLM, set `streamOptions.llm` to `null`.
204
+
205
+ > [!NOTE]
206
+ > When initalizing a client with a JSON module config, providing streaming options is not possible.
207
+
89
208
  ### Templating
90
209
 
91
210
  Use the orchestration client with templating to pass a prompt containing placeholders that will be replaced with input parameters during a chat completion request.
@@ -330,6 +449,7 @@ return response.getContent();
330
449
  ### Grounding
331
450
 
332
451
  Grounding enables integrating external, contextually relevant, domain-specific, or real-time data into AI processes.
452
+ The grounding configuration can be provided as a raw JSON object or by using the `buildDocumentGroundingConfig()` function, which requires only the minimal mandatory values.
333
453
 
334
454
  ```ts
335
455
  const orchestrationClient = new OrchestrationClient({
@@ -346,21 +466,16 @@ const orchestrationClient = new OrchestrationClient({
346
466
  ],
347
467
  defaults: {}
348
468
  },
349
- grounding: {
350
- type: 'document_grounding_service',
351
- config: {
352
- filters: [
469
+ grounding: buildDocumentGroundingConfig(
470
+ input_params: ['groundingRequest'],
471
+ output_param: 'groundingOutput',
472
+ filters: [
353
473
  {
354
474
  id: 'filter1',
355
- data_repositories: ['*'],
356
- search_config: {},
357
- data_repository_type: 'vector'
475
+ data_repositories: ['repository-id']
358
476
  }
359
477
  ],
360
- input_params: ['groundingRequest'],
361
- output_param: 'groundingOutput'
362
- }
363
- }
478
+ )
364
479
  });
365
480
 
366
481
  const response = await orchestrationClient.chatCompletion({
package/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- export type { CompletionPostResponse, ChatMessages, TokenUsage, TemplatingModuleConfig, OrchestrationConfig, ModuleResults, ModuleConfigs, MaskingModuleConfig, MaskingProviderConfig, GroundingModuleConfig, DocumentGroundingFilter, GroundingFilterId, GroundingFilterSearchConfiguration, DataRepositoryType, KeyValueListPair, SearchDocumentKeyValueListPair, SearchSelectOptionEnum, LlmModuleResult, LlmChoice, GenericModuleResult, FilteringModuleConfig, InputFilteringConfig, OutputFilteringConfig, FilterConfig, ErrorResponse, DpiEntities, DpiEntityConfig, DpiConfig, CompletionPostRequest, ChatMessage, AzureThreshold, AzureContentSafety, AzureContentSafetyFilterConfig, ImageContent, TextContent, MultiChatMessageContent, MultiChatMessage } from './client/api/schema/index.js';
2
- export type { OrchestrationModuleConfig, LlmModuleConfig, Prompt, LlmModelParams } from './orchestration-types.js';
1
+ export * from './client/api/schema/index.js';
2
+ export type { OrchestrationModuleConfig, LlmModuleConfig, Prompt, RequestOptions, StreamOptions, DocumentGroundingServiceConfig, DocumentGroundingServiceFilter, LlmModelParams } from './orchestration-types.js';
3
+ export { OrchestrationStreamResponse } from './orchestration-stream-response.js';
4
+ export { OrchestrationStreamChunkResponse } from './orchestration-stream-chunk-response.js';
5
+ export { OrchestrationStream } from './orchestration-stream.js';
3
6
  export { OrchestrationClient } from './orchestration-client.js';
4
- export { buildAzureContentFilter } from './orchestration-utils.js';
7
+ export { buildAzureContentFilter, buildDocumentGroundingConfig } from './orchestration-utils.js';
5
8
  export { OrchestrationResponse } from './orchestration-response.js';
6
9
  export type { ChatModel } from './model-types.js';
7
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,sBAAsB,EACtB,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,EACjB,kCAAkC,EAClC,kBAAkB,EAClB,gBAAgB,EAChB,8BAA8B,EAC9B,sBAAsB,EACtB,eAAe,EACf,SAAS,EACT,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,eAAe,EACf,SAAS,EACT,qBAAqB,EACrB,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,8BAA8B,EAC9B,YAAY,EACZ,WAAW,EACX,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EACV,yBAAyB,EACzB,eAAe,EACf,MAAM,EACN,cAAc,EACf,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAE7C,YAAY,EACV,yBAAyB,EACzB,eAAe,EACf,MAAM,EACN,cAAc,EACd,aAAa,EACb,8BAA8B,EAC9B,8BAA8B,EAC9B,cAAc,EACf,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAE5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,8 @@
1
+ export * from './client/api/schema/index.js';
2
+ export { OrchestrationStreamResponse } from './orchestration-stream-response.js';
3
+ export { OrchestrationStreamChunkResponse } from './orchestration-stream-chunk-response.js';
4
+ export { OrchestrationStream } from './orchestration-stream.js';
1
5
  export { OrchestrationClient } from './orchestration-client.js';
2
- export { buildAzureContentFilter } from './orchestration-utils.js';
6
+ export { buildAzureContentFilter, buildDocumentGroundingConfig } from './orchestration-utils.js';
3
7
  export { OrchestrationResponse } from './orchestration-response.js';
4
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+CA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAa7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAE5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -2,5 +2,5 @@ import type { AiCoreOpenSourceChatModel, AwsBedrockChatModel, AzureOpenAiChatMod
2
2
  /**
3
3
  * Supported chat models for orchestration.
4
4
  */
5
- export type ChatModel = Exclude<AzureOpenAiChatModel, 'gpt-4o-mini'> | GcpVertexAiChatModel | AwsBedrockChatModel | AiCoreOpenSourceChatModel;
5
+ export type ChatModel = AzureOpenAiChatModel | GcpVertexAiChatModel | AwsBedrockChatModel | AiCoreOpenSourceChatModel;
6
6
  //# sourceMappingURL=model-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-types.d.ts","sourceRoot":"","sources":["../src/model-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,OAAO,CAAC,oBAAoB,EAAE,aAAa,CAAC,GAC5C,oBAAoB,GACpB,mBAAmB,GACnB,yBAAyB,CAAC"}
1
+ {"version":3,"file":"model-types.d.ts","sourceRoot":"","sources":["../src/model-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,oBAAoB,GACpB,oBAAoB,GACpB,mBAAmB,GACnB,yBAAyB,CAAC"}
@@ -1,8 +1,9 @@
1
+ import { OrchestrationStreamResponse } from './orchestration-stream-response.js';
1
2
  import { OrchestrationResponse } from './orchestration-response.js';
2
- import type { CustomRequestConfig } from '@sap-ai-sdk/core';
3
+ import type { CustomRequestConfig } from '@sap-cloud-sdk/http-client';
3
4
  import type { ResourceGroupConfig } from '@sap-ai-sdk/ai-api/internal.js';
4
- import type { CompletionPostRequest } from './client/api/schema/index.js';
5
- import type { OrchestrationModuleConfig, Prompt } from './orchestration-types.js';
5
+ import type { OrchestrationModuleConfig, Prompt, StreamOptions } from './orchestration-types.js';
6
+ import type { OrchestrationStreamChunkResponse } from './orchestration-stream-chunk-response.js';
6
7
  import type { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
7
8
  /**
8
9
  * Get the orchestration client.
@@ -18,20 +19,9 @@ export declare class OrchestrationClient {
18
19
  * @param destination - The destination to use for the request.
19
20
  */
20
21
  constructor(config: OrchestrationModuleConfig | string, deploymentConfig?: ResourceGroupConfig | undefined, destination?: HttpDestinationOrFetchOptions | undefined);
21
- /**
22
- * Creates a completion for the chat messages.
23
- * @param prompt - Prompt configuration.
24
- * @param requestConfig - Request configuration.
25
- * @returns The completion result.
26
- */
27
22
  chatCompletion(prompt?: Prompt, requestConfig?: CustomRequestConfig): Promise<OrchestrationResponse>;
23
+ stream(prompt?: Prompt, controller?: AbortController, options?: StreamOptions, requestConfig?: CustomRequestConfig): Promise<OrchestrationStreamResponse<OrchestrationStreamChunkResponse>>;
24
+ private executeRequest;
25
+ private createStreamResponse;
28
26
  }
29
- /**
30
- * @internal
31
- */
32
- export declare function constructCompletionPostRequestFromJson(config: string, prompt?: Prompt): Record<string, any>;
33
- /**
34
- * @internal
35
- */
36
- export declare function constructCompletionPostRequest(config: OrchestrationModuleConfig, prompt?: Prompt): CompletionPostRequest;
37
27
  //# sourceMappingURL=orchestration-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"orchestration-client.d.ts","sourceRoot":"","sources":["../src/orchestration-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EACV,yBAAyB,EACzB,MAAM,EACP,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAEjF;;GAEG;AACH,qBAAa,mBAAmB;IAQ5B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,gBAAgB,CAAC;IACzB,OAAO,CAAC,WAAW,CAAC;IATtB;;;;;OAKG;gBAEO,MAAM,EAAE,yBAAyB,GAAG,MAAM,EAC1C,gBAAgB,CAAC,EAAE,mBAAmB,YAAA,EACtC,WAAW,CAAC,EAAE,6BAA6B,YAAA;IAGrD;;;;;OAKG;IACG,cAAc,CAClB,MAAM,CAAC,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,mBAAmB,GAClC,OAAO,CAAC,qBAAqB,CAAC;CAuBlC;AAED;;GAEG;AACH,wBAAgB,sCAAsC,CACpD,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,GAAG,CA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
  import { executeRequest } from '@sap-ai-sdk/core';
2
2
  import { resolveDeploymentId } from '@sap-ai-sdk/ai-api/internal.js';
3
+ import { createLogger } from '@sap-cloud-sdk/util';
4
+ import { OrchestrationStream } from './orchestration-stream.js';
5
+ import { OrchestrationStreamResponse } from './orchestration-stream-response.js';
3
6
  import { OrchestrationResponse } from './orchestration-response.js';
7
+ import { constructCompletionPostRequest, constructCompletionPostRequestFromJsonModuleConfig } from './orchestration-utils.js';
8
+ const logger = createLogger({
9
+ package: 'orchestration',
10
+ messageContext: 'orchestration-client'
11
+ });
4
12
  /**
5
13
  * Get the orchestration client.
6
14
  */
@@ -18,69 +26,64 @@ export class OrchestrationClient {
18
26
  this.config = config;
19
27
  this.deploymentConfig = deploymentConfig;
20
28
  this.destination = destination;
29
+ try {
30
+ if (typeof config === 'string') {
31
+ JSON.parse(config);
32
+ }
33
+ }
34
+ catch (error) {
35
+ throw new Error(`Could not parse JSON: ${error}`);
36
+ }
21
37
  }
22
- /**
23
- * Creates a completion for the chat messages.
24
- * @param prompt - Prompt configuration.
25
- * @param requestConfig - Request configuration.
26
- * @returns The completion result.
27
- */
28
38
  async chatCompletion(prompt, requestConfig) {
39
+ const response = await this.executeRequest({
40
+ prompt,
41
+ requestConfig,
42
+ stream: false
43
+ });
44
+ return new OrchestrationResponse(response);
45
+ }
46
+ async stream(prompt, controller = new AbortController(), options = {}, requestConfig) {
47
+ if (typeof this.config === 'string' && options) {
48
+ logger.warn('Stream options are not supported when using a JSON module config.');
49
+ }
50
+ return this.createStreamResponse({
51
+ prompt,
52
+ requestConfig,
53
+ stream: true,
54
+ streamOptions: options
55
+ }, controller);
56
+ }
57
+ async executeRequest(options) {
58
+ const { prompt, requestConfig, stream, streamOptions } = options;
29
59
  const body = typeof this.config === 'string'
30
- ? constructCompletionPostRequestFromJson(this.config, prompt)
31
- : constructCompletionPostRequest(this.config, prompt);
60
+ ? constructCompletionPostRequestFromJsonModuleConfig(JSON.parse(this.config), prompt, stream)
61
+ : constructCompletionPostRequest(this.config, prompt, stream, streamOptions);
32
62
  const deploymentId = await resolveDeploymentId({
33
63
  scenarioId: 'orchestration',
34
- resourceGroup: this.deploymentConfig?.resourceGroup
64
+ ...(this.deploymentConfig ?? {})
35
65
  });
36
- const response = await executeRequest({
66
+ return executeRequest({
37
67
  url: `/inference/deployments/${deploymentId}/completion`,
38
- resourceGroup: this.deploymentConfig?.resourceGroup
68
+ ...(this.deploymentConfig ?? {})
39
69
  }, body, requestConfig, this.destination);
40
- return new OrchestrationResponse(response);
41
- }
42
- }
43
- /**
44
- * @internal
45
- */
46
- export function constructCompletionPostRequestFromJson(config, prompt) {
47
- try {
48
- return {
49
- messages_history: prompt?.messagesHistory || [],
50
- input_params: prompt?.inputParams || {},
51
- orchestration_config: JSON.parse(config)
52
- };
53
70
  }
54
- catch (error) {
55
- throw new Error(`Could not parse JSON: ${error}`);
56
- }
57
- }
58
- /**
59
- * @internal
60
- */
61
- export function constructCompletionPostRequest(config, prompt) {
62
- return {
63
- orchestration_config: {
64
- module_configurations: {
65
- templating_module_config: config.templating,
66
- llm_module_config: config.llm,
67
- ...(Object.keys(config?.filtering || {}).length && {
68
- filtering_module_config: config.filtering
69
- }),
70
- ...(Object.keys(config?.masking || {}).length && {
71
- masking_module_config: config.masking
72
- }),
73
- ...(Object.keys(config?.grounding || {}).length && {
74
- grounding_module_config: config.grounding
75
- })
71
+ async createStreamResponse(options, controller) {
72
+ const response = new OrchestrationStreamResponse();
73
+ const streamResponse = await this.executeRequest({
74
+ ...options,
75
+ requestConfig: {
76
+ ...options.requestConfig,
77
+ responseType: 'stream',
78
+ signal: controller.signal
76
79
  }
77
- },
78
- ...(prompt?.inputParams && {
79
- input_params: prompt.inputParams
80
- }),
81
- ...(prompt?.messagesHistory && {
82
- messages_history: prompt.messagesHistory
83
- })
84
- };
80
+ });
81
+ const stream = OrchestrationStream._create(streamResponse, controller);
82
+ response.stream = stream
83
+ ._pipe(OrchestrationStream._processChunk)
84
+ ._pipe(OrchestrationStream._processFinishReason, response)
85
+ ._pipe(OrchestrationStream._processTokenUsage, response);
86
+ return response;
87
+ }
85
88
  }
86
89
  //# sourceMappingURL=orchestration-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"orchestration-client.js","sourceRoot":"","sources":["../src/orchestration-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAUpE;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAQpB;IACA;IACA;IATV;;;;;OAKG;IACH,YACU,MAA0C,EAC1C,gBAAsC,EACtC,WAA2C;QAF3C,WAAM,GAAN,MAAM,CAAoC;QAC1C,qBAAgB,GAAhB,gBAAgB,CAAsB;QACtC,gBAAW,GAAX,WAAW,CAAgC;IAClD,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,cAAc,CAClB,MAAe,EACf,aAAmC;QAEnC,MAAM,IAAI,GACR,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ;YAC7B,CAAC,CAAC,sCAAsC,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;YAC7D,CAAC,CAAC,8BAA8B,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAE1D,MAAM,YAAY,GAAG,MAAM,mBAAmB,CAAC;YAC7C,UAAU,EAAE,eAAe;YAC3B,aAAa,EAAE,IAAI,CAAC,gBAAgB,EAAE,aAAa;SACpD,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,cAAc,CACnC;YACE,GAAG,EAAE,0BAA0B,YAAY,aAAa;YACxD,aAAa,EAAE,IAAI,CAAC,gBAAgB,EAAE,aAAa;SACpD,EACD,IAAI,EACJ,aAAa,EACb,IAAI,CAAC,WAAW,CACjB,CAAC;QAEF,OAAO,IAAI,qBAAqB,CAAC,QA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M,CAAC,eAAe;SACzC,CAAC;KACH,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"orchestration-client.js","sourceRoot":"","sources":["../src/orchestration-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EACL,8BAA8B,EAC9B,kDAAkD,EACnD,MAAM,0BAA0B,CAAC;AAelC,MAAM,MAAM,GAAG,YAAY,CAAC;IAC1B,OAAO,EAAE,eAAe;IACxB,cAAc,EAAE,sBAAsB;CACvC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAQpB;IACA;IACA;IATV;;;;;OAKG;IACH,YACU,MAA0C,EAC1C,gBAAsC,EACtC,WAA2C;QAF3C,WAAM,GAAN,MAAM,CAAoC;QAC1C,qBAAgB,GAAhB,gBAAgB,CAAsB;QACtC,gBAAW,GAAX,WAAW,CAAgC;QAEnD,IAAI,CAAC;YACH,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC/B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,MAAe,EACf,aAAmC;QAEnC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;YACzC,MAAM;YACN,aAAa;YACb,MAAM,EAAE,KA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B,EACvB,UAA2B;QAE3B,MAAM,QAAQ,GACZ,IAAI,2BAA2B,EAAoC,CAAC;QAEtE,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;YAC/C,GAAG,OAAO;YACV,aAAa,EAAE;gBACb,GAAG,OAAO,CAAC,aAAa;gBACxB,YAAY,EAAE,QAAQ;gBACtB,MAAM,EAAE,UAAU,CAAC,MAAM;aAC1B;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QACvE,QAAQ,CAAC,MAAM,GAAG,MAAM;aACrB,KAAK,CAAC,mBAAmB,CAAC,aAAa,CAAC;aACxC,KAAK,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,QAAQ,CAAC;aACzD,KAAK,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;QAE3D,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,27 @@
1
+ import type { CompletionPostResponseStreaming, TokenUsage } from './client/api/schema/index.js';
2
+ /**
3
+ * Orchestration stream chunk response.
4
+ */
5
+ export declare class OrchestrationStreamChunkResponse {
6
+ readonly data: CompletionPostResponseStreaming;
7
+ constructor(data: CompletionPostResponseStreaming);
8
+ /**
9
+ * Usage of tokens in the chunk response.
10
+ * @returns Token usage.
11
+ */
12
+ getTokenUsage(): TokenUsage | undefined;
13
+ /**
14
+ * Reason for stopping the completion stream chunk.
15
+ * @param choiceIndex - The index of the choice to parse.
16
+ * @returns The finish reason.
17
+ */
18
+ getFinishReason(choiceIndex?: number): string | undefined;
19
+ /**
20
+ * Parses the chunk response and returns the delta content.
21
+ * @param choiceIndex - The index of the choice to parse.
22
+ * @returns The message delta content.
23
+ */
24
+ getDeltaContent(choiceIndex?: number): string | undefined;
25
+ private getChoices;
26
+ }
27
+ //# sourceMappingURL=orchestration-stream-chunk-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration-stream-chunk-response.d.ts","sourceRoot":"","sources":["../src/orchestration-stream-chunk-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,+BAA+B,EAE/B,UAAU,EACX,MAAM,8BAA8B,CAAC;AAEtC;;GAEG;AACH,qBAAa,gCAAgC;aACf,IAAI,EAAE,+BAA+B;gBAArC,IAAI,EAAE,+BAA+B;IAIjE;;;OAGG;IACH,aAAa,IAAI,UAAU,GAAG,SAAS;IAIvC;;;;OAIG;IACH,eAAe,CAAC,WAAW,SAAI,GAAG,MAAM,GAAG,SAAS;IAMpD;;;;OAIG;IACH,eAAe,CAAC,WAAW,SAAI,GAAG,MAAM,GAAG,SAAS;IAMpD,OAAO,CAAC,UAAU;CAGnB"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Orchestration stream chunk response.
3
+ */
4
+ export class OrchestrationStreamChunkResponse {
5
+ data;
6
+ constructor(data) {
7
+ this.data = data;
8
+ this.data = data;
9
+ }
10
+ /**
11
+ * Usage of tokens in the chunk response.
12
+ * @returns Token usage.
13
+ */
14
+ getTokenUsage() {
15
+ return this.data.orchestration_result?.usage;
16
+ }
17
+ /**
18
+ * Reason for stopping the completion stream chunk.
19
+ * @param choiceIndex - The index of the choice to parse.
20
+ * @returns The finish reason.
21
+ */
22
+ getFinishReason(choiceIndex = 0) {
23
+ return this.getChoices()?.find((c) => c.index === choiceIndex)?.finish_reason;
24
+ }
25
+ /**
26
+ * Parses the chunk response and returns the delta content.
27
+ * @param choiceIndex - The index of the choice to parse.
28
+ * @returns The message delta content.
29
+ */
30
+ getDeltaContent(choiceIndex = 0) {
31
+ return this.getChoices()?.find((c) => c.index === choiceIndex)?.delta.content;
32
+ }
33
+ getChoices() {
34
+ return this.data.orchestration_result?.choices;
35
+ }
36
+ }
37
+ //# sourceMappingURL=orchestration-stream-chunk-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration-stream-chunk-response.js","sourceRoot":"","sources":["../src/orchestration-stream-chunk-response.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,OAAO,gCAAgC;IACf;IAA5B,YAA4B,IAAqC;QAArC,SAAI,GAAJ,IAAI,CAAiC;QAC/D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,WAAW,GAAG,CAAC;QAC7B,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAC5B,CAAC,CAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,WAAW,CACnD,EAAE,aAAa,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,WAAW,GAAG,CAAC;QAC7B,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAC5B,CAAC,CAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,WAAW,CACnD,EAAE,KAAK,CAAC,OAAO,CAAC;IACnB,CAAC;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC;IACjD,CAAC;CACF"}
@@ -0,0 +1,33 @@
1
+ import type { TokenUsage } from './client/api/schema/index.js';
2
+ import type { OrchestrationStream } from './orchestration-stream.js';
3
+ /**
4
+ * Orchestration stream response.
5
+ */
6
+ export declare class OrchestrationStreamResponse<T> {
7
+ private _usage;
8
+ /**
9
+ * Finish reasons for all choices.
10
+ */
11
+ private _finishReasons;
12
+ private _stream;
13
+ getTokenUsage(): TokenUsage | undefined;
14
+ /**
15
+ * @internal
16
+ */
17
+ _setTokenUsage(usage: TokenUsage): void;
18
+ getFinishReason(choiceIndex?: number): string | undefined;
19
+ /**
20
+ * @internal
21
+ */
22
+ _getFinishReasons(): Map<number, string>;
23
+ /**
24
+ * @internal
25
+ */
26
+ _setFinishReasons(finishReasons: Map<number, string>): void;
27
+ get stream(): OrchestrationStream<T>;
28
+ /**
29
+ * @internal
30
+ */
31
+ set stream(stream: OrchestrationStream<T>);
32
+ }
33
+ //# sourceMappingURL=orchestration-stream-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration-stream-response.d.ts","sourceRoot":"","sources":["../src/orchestration-stream-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE;;GAEG;AACH,qBAAa,2BAA2B,CAAC,CAAC;IACxC,OAAO,CAAC,MAAM,CAAyB;IACvC;;OAEG;IACH,OAAO,CAAC,cAAc,CAAkC;IACxD,OAAO,CAAC,OAAO,CAAqC;IAE7C,aAAa,IAAI,UAAU,GAAG,SAAS;IAI9C;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAIhC,eAAe,CAAC,WAAW,SAAI,GAAG,MAAM,GAAG,SAAS;IAI3D;;OAEG;IACH,iBAAiB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAIxC;;OAEG;IACH,iBAAiB,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAI3D,IAAI,MAAM,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAKnC;IAED;;OAEG;IACH,IAAI,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAExC;CACF"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Orchestration stream response.
3
+ */
4
+ export class OrchestrationStreamResponse {
5
+ _usage;
6
+ /**
7
+ * Finish reasons for all choices.
8
+ */
9
+ _finishReasons = new Map();
10
+ _stream;
11
+ getTokenUsage() {
12
+ return this._usage;
13
+ }
14
+ /**
15
+ * @internal
16
+ */
17
+ _setTokenUsage(usage) {
18
+ this._usage = usage;
19
+ }
20
+ getFinishReason(choiceIndex = 0) {
21
+ return this._finishReasons.get(choiceIndex);
22
+ }
23
+ /**
24
+ * @internal
25
+ */
26
+ _getFinishReasons() {
27
+ return this._finishReasons;
28
+ }
29
+ /**
30
+ * @internal
31
+ */
32
+ _setFinishReasons(finishReasons) {
33
+ this._finishReasons = finishReasons;
34
+ }
35
+ get stream() {
36
+ if (!this._stream) {
37
+ throw new Error('Response stream is undefined.');
38
+ }
39
+ return this._stream;
40
+ }
41
+ /**
42
+ * @internal
43
+ */
44
+ set stream(stream) {
45
+ this._stream = stream;
46
+ }
47
+ }
48
+ //# sourceMappingURL=orchestration-stream-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration-stream-response.js","sourceRoot":"","sources":["../src/orchestration-stream-response.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,2BAA2B;IAC9B,MAAM,CAAyB;IACvC;;OAEG;IACK,cAAc,GAAwB,IAAI,GAAG,EAAE,CAAC;IAChD,OAAO,CAAqC;IAE7C,aAAa;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,KAAiB;QAC9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAEM,eAAe,CAAC,WAAW,GAAG,CAAC;QACpC,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,iBAAiB,CAAC,aAAkC;QAClD,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAED,IAAI,MAAM;QACR,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAI,MAAM,CAAC,MAA8B;QACvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,55 @@
1
+ import { SseStream } from '@sap-ai-sdk/core';
2
+ import { OrchestrationStreamChunkResponse } from './orchestration-stream-chunk-response.js';
3
+ import type { CompletionPostResponseStreaming } from './client/api/schema/index.js';
4
+ import type { HttpResponse } from '@sap-cloud-sdk/http-client';
5
+ import type { OrchestrationStreamResponse } from './orchestration-stream-response.js';
6
+ /**
7
+ * Orchestration stream containing post-processing functions.
8
+ */
9
+ export declare class OrchestrationStream<Item> extends SseStream<Item> {
10
+ iterator: () => AsyncIterator<Item>;
11
+ /**
12
+ * Create an orchestration stream based on the http response.
13
+ * @param response - Http response.
14
+ * @returns An orchestration stream.
15
+ * @internal
16
+ */
17
+ static _create(response: HttpResponse, controller: AbortController): OrchestrationStream<CompletionPostResponseStreaming>;
18
+ /**
19
+ * Wrap raw chunk data with chunk response class to provide helper functions.
20
+ * @param stream - Orchestration stream.
21
+ * @internal
22
+ */
23
+ static _processChunk(stream: OrchestrationStream<CompletionPostResponseStreaming>): AsyncGenerator<OrchestrationStreamChunkResponse>;
24
+ /**
25
+ * @internal
26
+ */
27
+ static _processFinishReason(stream: OrchestrationStream<OrchestrationStreamChunkResponse>, response?: OrchestrationStreamResponse<OrchestrationStreamChunkResponse>): AsyncGenerator<OrchestrationStreamChunkResponse>;
28
+ /**
29
+ * @internal
30
+ */
31
+ static _processTokenUsage(stream: OrchestrationStream<OrchestrationStreamChunkResponse>, response?: OrchestrationStreamResponse<OrchestrationStreamChunkResponse>): AsyncGenerator<OrchestrationStreamChunkResponse>;
32
+ /**
33
+ * Transform a stream of chunks into a stream of content strings.
34
+ * @param stream - Orchestration stream.
35
+ * @param choiceIndex - The index of the choice to parse.
36
+ * @internal
37
+ */
38
+ static _processContentStream(stream: OrchestrationStream<OrchestrationStreamChunkResponse>): AsyncGenerator<string>;
39
+ constructor(iterator: () => AsyncIterator<Item>, controller: AbortController);
40
+ /**
41
+ * Pipe the stream through a processing function.
42
+ * @param processFn - The function to process the input stream.
43
+ * @param response - The `OrchestrationStreamResponse` object for process function to store finish reason, token usage, etc.
44
+ * @returns The output stream containing processed items.
45
+ * @internal
46
+ */
47
+ _pipe<TReturn>(processFn: (stream: OrchestrationStream<Item>, response?: OrchestrationStreamResponse<OrchestrationStreamChunkResponse>) => AsyncIterator<TReturn>, response?: OrchestrationStreamResponse<OrchestrationStreamChunkResponse>): OrchestrationStream<TReturn>;
48
+ /**
49
+ * Transform the stream of chunks into a stream of content strings.
50
+ * @param this - Orchestration stream.
51
+ * @returns A stream of content strings.
52
+ */
53
+ toContentStream(this: OrchestrationStream<OrchestrationStreamChunkResponse>): OrchestrationStream<string>;
54
+ }
55
+ //# sourceMappingURL=orchestration-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration-stream.d.ts","sourceRoot":"","sources":["../src/orchestration-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAC5F,OAAO,KAAK,EACV,+BAA+B,EAEhC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAOtF;;GAEG;AACH,qBAAa,mBAAmB,CAAC,IAAI,CAAE,SAAQ,SAAS,CAAC,IAAI,CAAC;IAkHnD,QAAQ,EAAE,MAAM,aAAa,CAAC,IAAI,CAAC;IAjH5C;;;;;OAKG;WACW,OAAO,CACnB,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,eAAe,GAC1B,mBAAmB,CAAC,+BAA+B,CAAC;IASvD;;;;OAIG;WACW,aAAa,CACzB,MAAM,EAAE,mBAAmB,CAAC,+BAA+B,CAAC,GAC3D,cAAc,CAAC,gCAAgC,CAAC;IAMnD;;OAEG;WACW,oBAAoB,CAChC,MAAM,EAAE,mBAAmB,CAAC,gCAAgC,CAAC,EAC7D,QAAQ,CAAC,EAAE,2BAA2B,CAAC,gCAAgC,CAAC,GACvE,cAAc,CAAC,gCAAgC,CAAC;IAsCnD;;OAEG;WACW,kBAAkB,CAC9B,MAAM,EAAE,mBAAmB,CAAC,gCAAgC,CAAC,EAC7D,QAAQ,CAAC,EAAE,2BAA2B,CAAC,gCAAgC,CAAC,GACvE,cAAc,CAAC,gCAAgC,CAAC;IAanD;;;;;OAKG;WACW,qBAAqB,CACjC,MAAM,EAAE,mBAAmB,CAAC,gCAAgC,CAAC,GAC5D,cAAc,CAAC,MAAM,CAAC;gBAWhB,QAAQ,EAAE,MAAM,aAAa,CAAC,IAAI,CAAC,EAC1C,UAAU,EAAE,eAAe;IAK7B;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EACX,SAAS,EAAE,CACT,MAAM,EAAE,mBAAmB,CAAC,IAAI,CAAC,EACjC,QAAQ,CAAC,EAAE,2BAA2B,CAAC,gCAAgC,CAAC,KACrE,aAAa,CAAC,OAAO,CAAC,EAC3B,QAAQ,CAAC,EAAE,2BAA2B,CAAC,gCAAgC,CAAC,GACvE,mBAAmB,CAAC,OAAO,CAAC;IAU/B;;;;OAIG;IACI,eAAe,CACpB,IAAI,EAAE,mBAAmB,CAAC,gCAAgC,CAAC,GAC1D,mBAAmB,CAAC,MAAM,CAAC;CAM/B"}
@@ -0,0 +1,121 @@
1
+ import { createLogger } from '@sap-cloud-sdk/util';
2
+ import { SseStream } from '@sap-ai-sdk/core';
3
+ import { OrchestrationStreamChunkResponse } from './orchestration-stream-chunk-response.js';
4
+ const logger = createLogger({
5
+ package: 'orchestration',
6
+ messageContext: 'orchestration-chat-completion-stream'
7
+ });
8
+ /**
9
+ * Orchestration stream containing post-processing functions.
10
+ */
11
+ export class OrchestrationStream extends SseStream {
12
+ iterator;
13
+ /**
14
+ * Create an orchestration stream based on the http response.
15
+ * @param response - Http response.
16
+ * @returns An orchestration stream.
17
+ * @internal
18
+ */
19
+ static _create(response, controller) {
20
+ const stream = SseStream.transformToSseStream(response, controller);
21
+ return new OrchestrationStream(stream.iterator, controller);
22
+ }
23
+ /**
24
+ * Wrap raw chunk data with chunk response class to provide helper functions.
25
+ * @param stream - Orchestration stream.
26
+ * @internal
27
+ */
28
+ static async *_processChunk(stream) {
29
+ for await (const chunk of stream) {
30
+ yield new OrchestrationStreamChunkResponse(chunk);
31
+ }
32
+ }
33
+ /**
34
+ * @internal
35
+ */
36
+ static async *_processFinishReason(stream, response) {
37
+ for await (const chunk of stream) {
38
+ chunk.data.orchestration_result?.choices.forEach((choice) => {
39
+ const choiceIndex = choice.index;
40
+ if (choiceIndex >= 0) {
41
+ const finishReason = chunk.getFinishReason(choiceIndex);
42
+ if (finishReason) {
43
+ if (response) {
44
+ response._getFinishReasons().set(choiceIndex, finishReason);
45
+ }
46
+ switch (finishReason) {
47
+ case 'content_filter':
48
+ logger.error(`Choice ${choiceIndex}: Stream finished with content filter hit.`);
49
+ break;
50
+ case 'length':
51
+ logger.error(`Choice ${choiceIndex}: Stream finished with token length exceeded.`);
52
+ break;
53
+ case 'stop':
54
+ logger.debug(`Choice ${choiceIndex}: Stream finished.`);
55
+ break;
56
+ default:
57
+ logger.error(`Choice ${choiceIndex}: Stream finished with unknown reason '${finishReason}'.`);
58
+ }
59
+ }
60
+ }
61
+ });
62
+ yield chunk;
63
+ }
64
+ }
65
+ /**
66
+ * @internal
67
+ */
68
+ static async *_processTokenUsage(stream, response) {
69
+ for await (const chunk of stream) {
70
+ const usage = chunk.getTokenUsage();
71
+ if (usage) {
72
+ if (response) {
73
+ response._setTokenUsage(usage);
74
+ }
75
+ logger.debug(`Token usage: ${JSON.stringify(usage)}`);
76
+ }
77
+ yield chunk;
78
+ }
79
+ }
80
+ /**
81
+ * Transform a stream of chunks into a stream of content strings.
82
+ * @param stream - Orchestration stream.
83
+ * @param choiceIndex - The index of the choice to parse.
84
+ * @internal
85
+ */
86
+ static async *_processContentStream(stream) {
87
+ for await (const chunk of stream) {
88
+ const deltaContent = chunk.getDeltaContent();
89
+ if (!deltaContent) {
90
+ continue;
91
+ }
92
+ yield deltaContent;
93
+ }
94
+ }
95
+ constructor(iterator, controller) {
96
+ super(iterator, controller);
97
+ this.iterator = iterator;
98
+ }
99
+ /**
100
+ * Pipe the stream through a processing function.
101
+ * @param processFn - The function to process the input stream.
102
+ * @param response - The `OrchestrationStreamResponse` object for process function to store finish reason, token usage, etc.
103
+ * @returns The output stream containing processed items.
104
+ * @internal
105
+ */
106
+ _pipe(processFn, response) {
107
+ if (response) {
108
+ return new OrchestrationStream(() => processFn(this, response), this.controller);
109
+ }
110
+ return new OrchestrationStream(() => processFn(this), this.controller);
111
+ }
112
+ /**
113
+ * Transform the stream of chunks into a stream of content strings.
114
+ * @param this - Orchestration stream.
115
+ * @returns A stream of content strings.
116
+ */
117
+ toContentStream() {
118
+ return new OrchestrationStream(() => OrchestrationStream._processContentStream(this), this.controller);
119
+ }
120
+ }
121
+ //# sourceMappingURL=orchestration-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration-stream.js","sourceRoot":"","sources":["../src/orchestration-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAQ5F,MAAM,MAAM,GAAG,YAAY,CAAC;IAC1B,OAAO,EAAE,eAAe;IACxB,cAAc,EAAE,sCAAsC;CACvD,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,OAAO,mBAA0B,SAAQ,SAAe;IAkHnD;IAjHT;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CACnB,QAAsB,EACtB,UAA2B;QAE3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AC,IAAI,EAAE,QAAQ,CAAC,EAC/B,IAAI,CAAC,UAAU,CAChB,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,mBAAmB,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzE,CAAC;IAED;;;;OAIG;IACI,eAAe;QAGpB,OAAO,IAAI,mBAAmB,CAC5B,GAAG,EAAE,CAAC,mBAAmB,CAAC,qBAAqB,CAAC,IAAI,CAAC,EACrD,IAAI,CAAC,UAAU,CAChB,CAAC;IACJ,CAAC;CACF"}
@@ -1,5 +1,6 @@
1
+ import type { CustomRequestConfig } from '@sap-cloud-sdk/http-client';
1
2
  import type { ChatModel } from './model-types.js';
2
- import type { ChatMessages, FilteringModuleConfig, GroundingModuleConfig, MaskingModuleConfig, LlmModuleConfig as OriginalLlmModuleConfig, TemplatingModuleConfig } from './client/api/schema/index.js';
3
+ import type { ChatMessages, DataRepositoryType, DocumentGroundingFilter, FilteringModuleConfig, FilteringStreamOptions, GlobalStreamOptions, GroundingModuleConfig, MaskingModuleConfig, LlmModuleConfig as OriginalLlmModuleConfig, TemplatingModuleConfig } from './client/api/schema/index.js';
3
4
  /**
4
5
  * Prompt configuration.
5
6
  */
@@ -57,4 +58,73 @@ export interface OrchestrationModuleConfig {
57
58
  */
58
59
  grounding?: GroundingModuleConfig;
59
60
  }
61
+ /**
62
+ * Request options for orchestration.
63
+ */
64
+ export interface RequestOptions {
65
+ /**
66
+ * Prompt configuration.
67
+ */
68
+ prompt?: Prompt;
69
+ /**
70
+ * Custom request configuration.
71
+ */
72
+ requestConfig?: CustomRequestConfig;
73
+ /**
74
+ * Whether to stream the response.
75
+ */
76
+ stream?: boolean;
77
+ /**
78
+ * Options for the stream.
79
+ */
80
+ streamOptions?: StreamOptions;
81
+ }
82
+ /**
83
+ * Options for the stream.
84
+ */
85
+ export interface StreamOptions {
86
+ /**
87
+ * LLM specific stream options.
88
+ */
89
+ llm?: {
90
+ include_usage?: boolean;
91
+ [key: string]: any;
92
+ } | null;
93
+ /**
94
+ * Output filtering stream options.
95
+ */
96
+ outputFiltering?: FilteringStreamOptions;
97
+ /**
98
+ * Global stream options.
99
+ */
100
+ global?: GlobalStreamOptions;
101
+ }
102
+ /**
103
+ * Represents a filter configuration for the Document Grounding Service.
104
+ */
105
+ export type DocumentGroundingServiceFilter = Omit<DocumentGroundingFilter, 'data_repository_type'> & {
106
+ /**
107
+ * Defines the type of data repository.
108
+ * If not set, the default value is 'vector'.
109
+ */
110
+ data_repository_type?: DataRepositoryType;
111
+ };
112
+ /**
113
+ * Represents the configuration for the Document Grounding Service.
114
+ */
115
+ export interface DocumentGroundingServiceConfig {
116
+ /**
117
+ * Defines the filters to apply during the grounding process.
118
+ */
119
+ filters?: DocumentGroundingServiceFilter[];
120
+ /**
121
+ * Contains the input parameters used for grounding input questions.
122
+ */
123
+ input_params: string[];
124
+ /**
125
+ * Parameter name used for grounding output.
126
+ * @example "groundingOutput"
127
+ */
128
+ output_param: string;
129
+ }
60
130
  //# sourceMappingURL=orchestration-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"orchestration-types.d.ts","sourceRoot":"","sources":["../src/orchestration-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EACV,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,IAAI,uBAAuB,EAC1C,sBAAsB,EACvB,MAAM,8BAA8B,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,eAAe,CAAC,EAAE,YAAY,CAAC;IAE/B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,uBAAuB,GAAG;IACtD,MAAM;IACN,UAAU,EAAE,SAAS,CAAC;IACtB,YAAY,CAAC,EAAE,cAAc,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,UAAU,EAAE,sBAAsB,CAAC;IACnC;;OAEG;IACH,GAAG,EAAE,eAAe,CAAC;IACrB;;OAEG;IACH,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC;;OAEG;IACH,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B;;OAEG;IACH,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC"}
1
+ {"version":3,"file":"orchestration-types.d.ts","sourceRoot":"","sources":["../src/orchestration-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,IAAI,uBAAuB,EAC1C,sBAAsB,EACvB,MAAM,8BAA8B,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,eAAe,CAAC,EAAE,YAAY,CAAC;IAE/B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED;;G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AAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,IAAI,CAC/C,uBAAuB,EACvB,sBAAsB,CACvB,GAAG;IACF;;;OAGG;IACH,oBAAoB,CAAC,EAAE,kBAAkB,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,OAAO,CAAC,EAAE,8BAA8B,EAAE,CAAC;IAC3C;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB"}
@@ -1,8 +1,35 @@
1
- import type { AzureContentSafety, InputFilteringConfig, OutputFilteringConfig } from './client/api/schema/index.js';
1
+ import type { DocumentGroundingServiceConfig, Prompt, StreamOptions, LlmModuleConfig, OrchestrationModuleConfig } from './orchestration-types.js';
2
+ import type { AzureContentSafety, GroundingModuleConfig, InputFilteringConfig, CompletionPostRequest, FilteringStreamOptions, ModuleConfigs, OrchestrationConfig, OutputFilteringConfig } from './client/api/schema/index.js';
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare function constructCompletionPostRequestFromJsonModuleConfig(config: Record<string, any>, prompt?: Prompt, stream?: boolean): Record<string, any>;
7
+ /**
8
+ * @internal
9
+ */
10
+ export declare function addStreamOptionsToLlmModuleConfig(llmModuleConfig: LlmModuleConfig, streamOptions?: StreamOptions): LlmModuleConfig;
11
+ /**
12
+ * @internal
13
+ */
14
+ export declare function addStreamOptionsToOutputFilteringConfig(outputFilteringConfig: OutputFilteringConfig, filteringStreamOptions: FilteringStreamOptions): OutputFilteringConfig;
15
+ /**
16
+ * @internal
17
+ */
18
+ export declare function addStreamOptions(moduleConfigs: ModuleConfigs, streamOptions?: StreamOptions): OrchestrationConfig;
19
+ /**
20
+ * @internal
21
+ */
22
+ export declare function constructCompletionPostRequest(config: OrchestrationModuleConfig, prompt?: Prompt, stream?: boolean, streamOptions?: StreamOptions): CompletionPostRequest;
2
23
  /**
3
24
  * Convenience function to create Azure content filters.
4
25
  * @param filter - Filtering configuration for Azure filter. If skipped, the default Azure content filter configuration is used.
5
26
  * @returns An object with the Azure filtering configuration.
6
27
  */
7
28
  export declare function buildAzureContentFilter(filter?: AzureContentSafety): InputFilteringConfig | OutputFilteringConfig;
29
+ /**
30
+ * Convenience function to create Document Grounding configuration.
31
+ * @param groundingConfig - Configuration for the document grounding service.
32
+ * @returns An object with the full grounding configuration.
33
+ */
34
+ export declare function buildDocumentGroundingConfig(groundingConfig: DocumentGroundingServiceConfig): GroundingModuleConfig;
8
35
  //# sourceMappingURL=orchestration-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"orchestration-utils.d.ts","sourceRoot":"","sources":["../src/orchestration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,8BAA8B,CAAC;AAEtC;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,CAAC,EAAE,kBAAkB,GAC1B,oBAAoB,GAAG,qBAAqB,CAY9C"}
1
+ {"version":3,"file":"orchestration-utils.d.ts","sourceRoot":"","sources":["../src/orchestration-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,8BAA8B,EAC9B,MAAM,EACN,aAAa,EACb,eAAe,EACf,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,8BAA8B,CAAC;AAOtC;;GAEG;AACH,wBAAgB,kDAAkD,CAChE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,OAAO,GACf,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAarB;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAC/C,eAAe,EAAE,eAAe,EAChC,aAAa,CAAC,EAAE,aAAa,GAC5B,eAAe,CAiBjB;AAED;;GAEG;AACH,wBAAgB,uCAAuC,CACrD,qBAAqB,EAAE,qBAAqB,EAC5C,sBAAsB,EAAE,sBAAsB,GAC7C,qBAAqB,CAQvB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,aAAa,EAC5B,aAAa,CAAC,EAAE,aAAa,GAC5B,mBAAmB,CAgCrB;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,yBAAyB,EACjC,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,OAAO,EAChB,aAAa,CAAC,EAAE,aAAa,GAC5B,qBAAqB,CA6BvB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,CAAC,EAAE,kBAAkB,GAC1B,oBAAoB,GAAG,qBAAqB,CAY9C;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,eAAe,EAAE,8BAA8B,GAC9C,qBAAqB,CAcvB"}
@@ -1,3 +1,116 @@
1
+ import { createLogger } from '@sap-cloud-sdk/util';
2
+ const logger = createLogger({
3
+ package: 'orchestration',
4
+ messageContext: 'orchestration-utils'
5
+ });
6
+ /**
7
+ * @internal
8
+ */
9
+ export function constructCompletionPostRequestFromJsonModuleConfig(config, prompt, stream) {
10
+ const orchestration_config = { ...config };
11
+ if (stream) {
12
+ orchestration_config.stream = true;
13
+ }
14
+ else {
15
+ delete orchestration_config.stream;
16
+ }
17
+ return {
18
+ messages_history: prompt?.messagesHistory || [],
19
+ input_params: prompt?.inputParams || {},
20
+ orchestration_config
21
+ };
22
+ }
23
+ /**
24
+ * @internal
25
+ */
26
+ export function addStreamOptionsToLlmModuleConfig(llmModuleConfig, streamOptions) {
27
+ if (streamOptions?.llm === null) {
28
+ return llmModuleConfig;
29
+ }
30
+ return {
31
+ ...llmModuleConfig,
32
+ model_params: {
33
+ ...llmModuleConfig.model_params,
34
+ ...(streamOptions?.llm !== null && {
35
+ stream_options: {
36
+ include_usage: true,
37
+ ...(llmModuleConfig.model_params?.stream_options || {}),
38
+ ...(streamOptions?.llm || {})
39
+ }
40
+ })
41
+ }
42
+ };
43
+ }
44
+ /**
45
+ * @internal
46
+ */
47
+ export function addStreamOptionsToOutputFilteringConfig(outputFilteringConfig, filteringStreamOptions) {
48
+ return {
49
+ ...outputFilteringConfig,
50
+ stream_options: {
51
+ ...(outputFilteringConfig.stream_options || {}),
52
+ ...filteringStreamOptions
53
+ }
54
+ };
55
+ }
56
+ /**
57
+ * @internal
58
+ */
59
+ export function addStreamOptions(moduleConfigs, streamOptions) {
60
+ const { llm_module_config, filtering_module_config } = moduleConfigs;
61
+ const outputFiltering = streamOptions?.outputFiltering;
62
+ const globalOptions = streamOptions?.global;
63
+ if (!moduleConfigs?.filtering_module_config?.output && outputFiltering) {
64
+ logger.warn('Output filter stream options are not applied because filtering module is not configured.');
65
+ }
66
+ return {
67
+ stream: true,
68
+ ...(globalOptions && { stream_options: globalOptions }),
69
+ module_configurations: {
70
+ ...moduleConfigs,
71
+ llm_module_config: addStreamOptionsToLlmModuleConfig(llm_module_config, streamOptions),
72
+ ...(outputFiltering &&
73
+ filtering_module_config?.output && {
74
+ filtering_module_config: {
75
+ ...filtering_module_config,
76
+ output: addStreamOptionsToOutputFilteringConfig(filtering_module_config.output, outputFiltering)
77
+ }
78
+ })
79
+ }
80
+ };
81
+ }
82
+ /**
83
+ * @internal
84
+ */
85
+ export function constructCompletionPostRequest(config, prompt, stream, streamOptions) {
86
+ const moduleConfigurations = {
87
+ templating_module_config: config.templating,
88
+ llm_module_config: config.llm,
89
+ ...(config?.filtering &&
90
+ Object.keys(config.filtering).length && {
91
+ filtering_module_config: config.filtering
92
+ }),
93
+ ...(config?.masking &&
94
+ Object.keys(config.masking).length && {
95
+ masking_module_config: config.masking
96
+ }),
97
+ ...(config?.grounding &&
98
+ Object.keys(config.grounding).length && {
99
+ grounding_module_config: config.grounding
100
+ })
101
+ };
102
+ return {
103
+ orchestration_config: stream
104
+ ? addStreamOptions(moduleConfigurations, streamOptions)
105
+ : { module_configurations: moduleConfigurations },
106
+ ...(prompt?.inputParams && {
107
+ input_params: prompt.inputParams
108
+ }),
109
+ ...(prompt?.messagesHistory && {
110
+ messages_history: prompt.messagesHistory
111
+ })
112
+ };
113
+ }
1
114
  /**
2
115
  * Convenience function to create Azure content filters.
3
116
  * @param filter - Filtering configuration for Azure filter. If skipped, the default Azure content filter configuration is used.
@@ -16,4 +129,24 @@ export function buildAzureContentFilter(filter) {
16
129
  ]
17
130
  };
18
131
  }
132
+ /**
133
+ * Convenience function to create Document Grounding configuration.
134
+ * @param groundingConfig - Configuration for the document grounding service.
135
+ * @returns An object with the full grounding configuration.
136
+ */
137
+ export function buildDocumentGroundingConfig(groundingConfig) {
138
+ return {
139
+ type: 'document_grounding_service',
140
+ config: {
141
+ input_params: groundingConfig.input_params,
142
+ output_param: groundingConfig.output_param,
143
+ ...(groundingConfig.filters && {
144
+ filters: groundingConfig.filters?.map(filter => ({
145
+ data_repository_type: 'vector',
146
+ ...filter
147
+ }))
148
+ })
149
+ }
150
+ };
151
+ }
19
152
  //# sourceMappingURL=orchestration-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"orchestration-utils.js","sourceRoot":"","sources":["../src/orchestration-utils.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAA2B;IAE3B,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,sBAAsB;gBAC5B,GAAG,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,MAAM,EA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,OAAO;QACL,IAAI,EAAE,4BAA4B;QAClC,MAAM,EAAE;YACN,YAAY,EAAE,eAAe,CAAC,YAAY;YAC1C,YAAY,EAAE,eAAe,CAAC,YAAY;YAC1C,GAAG,CAAC,eAAe,CAAC,OAAO,IAAI;gBAC7B,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;oBAC/C,oBAAoB,EAAE,QAAQ;oBAC9B,GAAG,MAAM;iBACV,CAAC,CAAC;aACJ,CAAC;SACH;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ai-sdk/orchestration",
3
- "version": "1.5.1-20250113013141.0",
3
+ "version": "1.6.0",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -20,10 +20,13 @@
20
20
  "internal.d.ts"
21
21
  ],
22
22
  "dependencies": {
23
+ "@sap-cloud-sdk/util": "^3.25.0",
24
+ "@sap-ai-sdk/core": "^1.6.0",
25
+ "@sap-ai-sdk/ai-api": "^1.6.0"
26
+ },
27
+ "devDependencies": {
23
28
  "@sap-cloud-sdk/http-client": "^3.25.0",
24
- "@sap-cloud-sdk/connectivity": "^3.25.0",
25
- "@sap-ai-sdk/core": "^1.5.1-20250113013141.0",
26
- "@sap-ai-sdk/ai-api": "^1.5.1-20250113013141.0"
29
+ "@sap-cloud-sdk/connectivity": "^3.25.0"
27
30
  },
28
31
  "scripts": {
29
32
  "compile": "tsc",