n8n/packages/@n8n/nodes-langchain/utils/aws/ResponseLimitedNodeHttpHandler.ts
n8n-assistant[bot] 191a22e759
chore: Bundle/2.x (#39935)
Co-authored-by: Matsu <matias.huhta@n8n.io>
2026-09-30 07:44:10 +03:00

18 lines
666 B
TypeScript

import { limitAiResponseStream } from '@n8n/ai-utilities/http-proxy-agent';
import { NodeHttpHandler } from '@smithy/node-http-handler';
import { Readable } from 'node:stream';
/** Preserve the SDK handler's keepalive and timeout settings while limiting its response. */
export class ResponseLimitedNodeHttpHandler extends NodeHttpHandler {
override async handle(
...args: Parameters<NodeHttpHandler['handle']>
): ReturnType<NodeHttpHandler['handle']> {
const result = await super.handle(...args);
const body: unknown = result.response.body;
if (body instanceof Readable) {
result.response.body = limitAiResponseStream(body);
}
return result;
}
}