UNPKG

@langchain/core

Version:
96 lines 3.94 kB
//#region src/utils/testing/stream.d.ts /** * The `this` context that Vitest provides to custom matchers via `expect.extend`. * @see https://vitest.dev/guide/extending-matchers.html */ interface ExpectExtendThis { isNot?: boolean; equals(a: unknown, b: unknown): boolean; utils: { matcherHint(name: string, received?: string, expected?: string, options?: { isNot?: boolean; }): string; printReceived(value: unknown): string; printExpected(value: unknown): string; }; } interface ExpectationResult { pass: boolean; message: () => string; actual?: unknown; expected?: unknown; } declare function toHaveStreamText(this: ExpectExtendThis, received: unknown, expected: string): Promise<ExpectationResult>; declare function toHaveStreamReasoning(this: ExpectExtendThis, received: unknown, expected: string): Promise<ExpectationResult>; type StreamToolCallExpectation = { name: string; args: Record<string, unknown>; }; type StreamUsageExpectation = { input_tokens?: number; output_tokens?: number; total_tokens?: number; input_token_details?: Record<string, unknown>; output_token_details?: Record<string, unknown>; }; type StreamOutputExpectation = { id?: string; text?: string; toolCalls?: StreamToolCallExpectation[]; usage?: StreamUsageExpectation; responseMetadata?: Record<string, unknown>; }; declare function toHaveStreamToolCalls(this: ExpectExtendThis, received: unknown, expected: StreamToolCallExpectation[]): Promise<ExpectationResult>; declare function toHaveStreamUsage(this: ExpectExtendThis, received: unknown, expected: StreamUsageExpectation): Promise<ExpectationResult>; declare function toHaveStreamOutput(this: ExpectExtendThis, received: unknown, expected: StreamOutputExpectation): Promise<ExpectationResult>; /** Stream matchers for `expect.extend()`. */ declare const streamMatchers: { toHaveStreamText: typeof toHaveStreamText; toHaveStreamReasoning: typeof toHaveStreamReasoning; toHaveStreamToolCalls: typeof toHaveStreamToolCalls; toHaveStreamUsage: typeof toHaveStreamUsage; toHaveStreamOutput: typeof toHaveStreamOutput; }; /** * Custom assertion helpers for values returned by `BaseChatModel.streamEvents()`. * * These matchers consume the stream lazily through the corresponding * `ChatModelStream` promise-backed properties. * * @typeParam R - The assertion return type provided by the test framework. */ interface StreamMatchers<R = unknown> { /** * Asserts that the stream resolves to the expected concatenated text. * * @param expected - The exact text expected from `ChatModelStream.text`. */ toHaveStreamText(expected: string): R; /** * Asserts that the stream resolves to the expected concatenated reasoning text. * * @param expected - The exact reasoning text expected from `ChatModelStream.reasoning`. */ toHaveStreamReasoning(expected: string): R; /** * Asserts that the stream resolves to the expected ordered tool calls. * * @param expected - Tool call names and arguments expected from `ChatModelStream.toolCalls`. */ toHaveStreamToolCalls(expected: StreamToolCallExpectation[]): R; /** * Asserts that the stream resolves to usage metadata matching the expected fields. * * @param expected - A partial usage metadata object expected from `ChatModelStream.usage`. */ toHaveStreamUsage(expected: StreamUsageExpectation): R; /** * Asserts that the final streamed output message matches the expected fields. * * @param expected - A partial output expectation checked against `ChatModelStream.output`. */ toHaveStreamOutput(expected: StreamOutputExpectation): R; } //#endregion export { StreamMatchers, StreamOutputExpectation, StreamToolCallExpectation, StreamUsageExpectation, streamMatchers, toHaveStreamOutput, toHaveStreamReasoning, toHaveStreamText, toHaveStreamToolCalls, toHaveStreamUsage }; //# sourceMappingURL=stream.d.cts.map