Skip to content
Open
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
4 changes: 2 additions & 2 deletions js/core/src/reflection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class ReflectionServer {
response.write(JSON.stringify(chunk) + '\n');
};
const result = await action.run(input, {
context,
context: context || {},
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While this correctly fixes the issue, the same logic context || {} is duplicated for the non-streaming case on line 307. To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, you could define the default context before the if (stream === 'true') block and reuse it in both action.run calls.

For example:

const { key, input, context, telemetryLabels } = request.body;
const effectiveContext = context || {};
// ...
// in streaming case:
await action.run(input, {
  context: effectiveContext,
  // ...
});
// ...
// in non-streaming case:
await action.run(input, {
  context: effectiveContext,
  // ...
});

This would centralize the logic for handling the context.

onChunk: callback,
telemetryLabels,
onTraceStart: onTraceStartCallback,
Expand Down Expand Up @@ -304,7 +304,7 @@ export class ReflectionServer {
} else {
// Non-streaming: send JSON response
const result = await action.run(input, {
context,
context: context || {},
telemetryLabels,
onTraceStart: onTraceStartCallback,
abortSignal: abortController.signal,
Expand Down
Loading