Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/core/src/events/AgenticaResponseEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export interface AgenticaResponseEvent extends AgenticaEventBase<"response"> {
body: OpenAI.ChatCompletionCreateParamsStreaming;
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body property is typed as OpenAI.ChatCompletionCreateParamsStreaming, but it should support both streaming and non-streaming requests to match the actual usage in the code. When a non-streaming response is created (when config.stream === false), the body will have stream: false and should be typed as OpenAI.ChatCompletionCreateParamsNonStreaming. Consider changing this to OpenAI.ChatCompletionCreateParamsStreaming | OpenAI.ChatCompletionCreateParamsNonStreaming to match the AgenticaRequestEvent.body type and accurately represent both streaming and non-streaming scenarios.

Suggested change
body: OpenAI.ChatCompletionCreateParamsStreaming;
body:
| OpenAI.ChatCompletionCreateParamsStreaming
| OpenAI.ChatCompletionCreateParamsNonStreaming;

Copilot uses AI. Check for mistakes.

/**
* The text content stream.
* The response data.
*/
stream: AsyncGenerator<OpenAI.ChatCompletionChunk, undefined, undefined>;
response: AgenticaResponseEvent.Response;

/**
* Options for the request.
Expand All @@ -31,3 +31,14 @@ export interface AgenticaResponseEvent extends AgenticaEventBase<"response"> {
*/
join: () => Promise<OpenAI.ChatCompletion>;
}
export namespace AgenticaResponseEvent {
export type Response = StreamResponse | NonStreamResponse;
export interface StreamResponse {
stream: true;
data: AsyncGenerator<OpenAI.ChatCompletionChunk, undefined, undefined>;
}
export interface NonStreamResponse {
stream: false;
data: OpenAI.ChatCompletion;
}
}
4 changes: 2 additions & 2 deletions packages/core/src/factory/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export function createResponseEvent(props: {
source: AgenticaEventSource;
body: OpenAI.ChatCompletionCreateParamsStreaming;
options?: OpenAI.RequestOptions | undefined;
stream: AsyncGenerator<OpenAI.ChatCompletionChunk, undefined, undefined>;
response: AgenticaResponseEvent.Response;
join: () => Promise<OpenAI.ChatCompletion>;
}): AgenticaResponseEvent {
const id: string = v4();
Expand All @@ -343,7 +343,7 @@ export function createResponseEvent(props: {
source: props.source,
body: props.body,
options: props.options,
stream: props.stream,
response: props.response,
join: props.join,
};
}
26 changes: 25 additions & 1 deletion packages/core/src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ export function getChatCompletionFunction(props: {
})();

if ("toReadableStream" in completion === false) {
if (completion.usage != null) {
AgenticaTokenUsageAggregator.aggregate({
kind: source,
completionUsage: completion.usage,
usage: props.usage,
});
}
void props.dispatch({
id: v4(),
type: "response",
request_id: event.id,
source,
response: {
stream: false,
data: completion,
},
body: event.body as OpenAI.ChatCompletionCreateParamsStreaming,
options: event.options,
join: async () => completion,
created_at: new Date().toISOString(),
}).catch(() => {});
return {
type: "none-stream",
value: completion,
Expand Down Expand Up @@ -101,7 +122,10 @@ export function getChatCompletionFunction(props: {
type: "response",
request_id: event.id,
source,
stream: streamDefaultReaderToAsyncGenerator(streamForStream.getReader(), props.abortSignal),
response: {
stream: true,
data: streamDefaultReaderToAsyncGenerator(streamForStream.getReader(), props.abortSignal),
},
body: event.body as OpenAI.ChatCompletionCreateParamsStreaming,
options: event.options,
join: async () => {
Expand Down
86 changes: 43 additions & 43 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ catalogs:
typescript: ~5.9.3
typia:
"@ryoppippi/unplugin-typia": ^2.6.4
"@samchon/openapi": ^6.0.0
typia: ^11.0.0
"@samchon/openapi": ^6.0.1
typia: ^11.0.3
vite:
vitest: ^3.0.9
onlyBuiltDependencies:
Expand Down
Loading
Loading