| 11 | // event-stream binary fixtures (which require internal smithy modules |
| 12 | // that are deep transitive deps). |
| 13 | function makeMockSdk(handlers) { |
| 14 | let lastClientArgs = null; |
| 15 | let lastCommand = null; |
| 16 | |
| 17 | class MockBedrockRuntimeClient { |
| 18 | constructor(args) { lastClientArgs = args; } |
| 19 | async send(command) { |
| 20 | lastCommand = command; |
| 21 | const isStream = command instanceof MockInvokeModelWithResponseStreamCommand; |
| 22 | return isStream |
| 23 | ? handlers.stream(command.input) |
| 24 | : handlers.invoke(command.input); |
| 25 | } |
| 26 | } |
| 27 | class MockInvokeModelCommand { constructor(input) { this.input = input; } } |
| 28 | class MockInvokeModelWithResponseStreamCommand { constructor(input) { this.input = input; } } |
| 29 | |
| 30 | return { |
| 31 | sdk: { |
| 32 | BedrockRuntimeClient: MockBedrockRuntimeClient, |
| 33 | InvokeModelCommand: MockInvokeModelCommand, |
| 34 | InvokeModelWithResponseStreamCommand: MockInvokeModelWithResponseStreamCommand, |
| 35 | }, |
| 36 | inspect: () => ({ lastClientArgs, lastCommand }), |
| 37 | }; |
| 38 | } |
| 39 | |
| 40 | async function readSseStream(stream) { |
| 41 | const reader = stream.getReader(); |