@langchain/core 1.1.30 → 1.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/language_models/base.cjs +1 -1
  3. package/dist/language_models/base.js +1 -1
  4. package/dist/load/import_map.cjs +2 -0
  5. package/dist/load/import_map.cjs.map +1 -1
  6. package/dist/load/import_map.js +4 -2
  7. package/dist/load/import_map.js.map +1 -1
  8. package/dist/runnables/base.cjs +1 -1
  9. package/dist/runnables/base.cjs.map +1 -1
  10. package/dist/runnables/base.js +2 -2
  11. package/dist/runnables/base.js.map +1 -1
  12. package/dist/{utils/testing → testing}/fake_model_builder.cjs +6 -6
  13. package/dist/testing/fake_model_builder.cjs.map +1 -0
  14. package/dist/{utils/testing → testing}/fake_model_builder.d.cts +12 -12
  15. package/dist/testing/fake_model_builder.d.cts.map +1 -0
  16. package/dist/{utils/testing → testing}/fake_model_builder.d.ts +13 -13
  17. package/dist/{utils/testing/fake_model_builder.d.cts.map → testing/fake_model_builder.d.ts.map} +1 -1
  18. package/dist/{utils/testing → testing}/fake_model_builder.js +6 -6
  19. package/dist/testing/fake_model_builder.js.map +1 -0
  20. package/dist/testing/index.cjs +41 -0
  21. package/dist/testing/index.cjs.map +1 -0
  22. package/dist/testing/index.d.cts +3 -0
  23. package/dist/testing/index.d.ts +3 -0
  24. package/dist/testing/index.js +23 -0
  25. package/dist/testing/index.js.map +1 -0
  26. package/dist/testing/matchers.cjs +213 -0
  27. package/dist/testing/matchers.cjs.map +1 -0
  28. package/dist/testing/matchers.d.cts +94 -0
  29. package/dist/testing/matchers.d.cts.map +1 -0
  30. package/dist/testing/matchers.d.ts +94 -0
  31. package/dist/testing/matchers.d.ts.map +1 -0
  32. package/dist/testing/matchers.js +203 -0
  33. package/dist/testing/matchers.js.map +1 -0
  34. package/dist/utils/testing/index.cjs +1 -4
  35. package/dist/utils/testing/index.cjs.map +1 -1
  36. package/dist/utils/testing/index.d.cts +1 -2
  37. package/dist/utils/testing/index.d.ts +1 -2
  38. package/dist/utils/testing/index.js +2 -4
  39. package/dist/utils/testing/index.js.map +1 -1
  40. package/package.json +15 -3
  41. package/dist/utils/testing/fake_model_builder.cjs.map +0 -1
  42. package/dist/utils/testing/fake_model_builder.d.ts.map +0 -1
  43. package/dist/utils/testing/fake_model_builder.js.map +0 -1
@@ -0,0 +1,94 @@
1
+ //#region src/testing/matchers.d.ts
2
+ /**
3
+ * The `this` context that Vitest and Jest provide to custom matchers
4
+ * via `expect.extend`.
5
+ *
6
+ * Compatible with both frameworks:
7
+ * - https://vitest.dev/guide/extending-matchers.html
8
+ * - https://jestjs.io/docs/expect#expectextendmatchers
9
+ */
10
+ interface ExpectExtendThis {
11
+ isNot?: boolean;
12
+ equals(a: unknown, b: unknown): boolean;
13
+ utils: {
14
+ matcherHint(name: string, received?: string, expected?: string): string;
15
+ printReceived(value: unknown): string;
16
+ printExpected(value: unknown): string;
17
+ };
18
+ }
19
+ interface ExpectationResult {
20
+ pass: boolean;
21
+ message: () => string;
22
+ actual?: unknown;
23
+ expected?: unknown;
24
+ }
25
+ declare const toBeHumanMessage: (this: ExpectExtendThis, received: unknown, expected?: string | Record<string, unknown> | undefined) => ExpectationResult;
26
+ declare const toBeAIMessage: (this: ExpectExtendThis, received: unknown, expected?: string | Record<string, unknown> | undefined) => ExpectationResult;
27
+ declare const toBeSystemMessage: (this: ExpectExtendThis, received: unknown, expected?: string | Record<string, unknown> | undefined) => ExpectationResult;
28
+ declare const toBeToolMessage: (this: ExpectExtendThis, received: unknown, expected?: string | Record<string, unknown> | undefined) => ExpectationResult;
29
+ declare function toHaveToolCalls(this: ExpectExtendThis, received: unknown, expected: Array<Record<string, unknown>>): ExpectationResult;
30
+ declare function toHaveToolCallCount(this: ExpectExtendThis, received: unknown, expected: number): ExpectationResult;
31
+ declare function toContainToolCall(this: ExpectExtendThis, received: unknown, expected: Record<string, unknown>): ExpectationResult;
32
+ declare function toHaveToolMessages(this: ExpectExtendThis, received: unknown, expected: Array<Record<string, unknown>>): ExpectationResult;
33
+ declare function toHaveBeenInterrupted(this: ExpectExtendThis, received: unknown, expectedValue?: unknown): ExpectationResult;
34
+ declare function toHaveStructuredResponse(this: ExpectExtendThis, received: unknown, expected?: Record<string, unknown>): ExpectationResult;
35
+ /**
36
+ * All matcher functions bundled for convenient use with `expect.extend()`.
37
+ */
38
+ declare const langchainMatchers: {
39
+ toBeHumanMessage: (this: ExpectExtendThis, received: unknown, expected?: string | Record<string, unknown> | undefined) => ExpectationResult;
40
+ toBeAIMessage: (this: ExpectExtendThis, received: unknown, expected?: string | Record<string, unknown> | undefined) => ExpectationResult;
41
+ toBeSystemMessage: (this: ExpectExtendThis, received: unknown, expected?: string | Record<string, unknown> | undefined) => ExpectationResult;
42
+ toBeToolMessage: (this: ExpectExtendThis, received: unknown, expected?: string | Record<string, unknown> | undefined) => ExpectationResult;
43
+ toHaveToolCalls: typeof toHaveToolCalls;
44
+ toHaveToolCallCount: typeof toHaveToolCallCount;
45
+ toContainToolCall: typeof toContainToolCall;
46
+ toHaveToolMessages: typeof toHaveToolMessages;
47
+ toHaveBeenInterrupted: typeof toHaveBeenInterrupted;
48
+ toHaveStructuredResponse: typeof toHaveStructuredResponse;
49
+ };
50
+ interface LangChainMatchers<R = unknown> {
51
+ toBeHumanMessage(expected?: string | {
52
+ content?: string;
53
+ id?: string;
54
+ }): R;
55
+ toBeAIMessage(expected?: string | {
56
+ content?: string;
57
+ name?: string;
58
+ }): R;
59
+ toBeSystemMessage(expected?: string | {
60
+ content?: string;
61
+ additional_kwargs?: object;
62
+ }): R;
63
+ toBeToolMessage(expected?: string | {
64
+ content?: string;
65
+ name?: string;
66
+ status?: string;
67
+ tool_call_id?: string;
68
+ }): R;
69
+ toHaveToolCalls(expected: Array<{
70
+ name?: string;
71
+ id?: string;
72
+ args?: Record<string, unknown>;
73
+ }>): R;
74
+ toHaveToolCallCount(expected: number): R;
75
+ toContainToolCall(expected: {
76
+ name?: string;
77
+ id?: string;
78
+ args?: Record<string, unknown>;
79
+ }): R;
80
+ toHaveToolMessages(expected: Array<{
81
+ content?: string;
82
+ name?: string;
83
+ status?: string;
84
+ tool_call_id?: string;
85
+ }>): R;
86
+ toHaveBeenInterrupted(expectedValue?: unknown): R;
87
+ toHaveStructuredResponse(expected?: Record<string, unknown>): R;
88
+ }
89
+ declare module "vitest" {
90
+ interface Matchers<T = any> extends LangChainMatchers<T> {}
91
+ }
92
+ //#endregion
93
+ export { LangChainMatchers, langchainMatchers, toBeAIMessage, toBeHumanMessage, toBeSystemMessage, toBeToolMessage, toContainToolCall, toHaveBeenInterrupted, toHaveStructuredResponse, toHaveToolCallCount, toHaveToolCalls, toHaveToolMessages };
94
+ //# sourceMappingURL=matchers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchers.d.ts","names":[],"sources":["../../src/testing/matchers.ts"],"mappings":";;;;;;;;;UAeU,gBAAA;EACR,KAAA;EACA,MAAA,CAAO,CAAA,WAAY,CAAA;EACnB,KAAA;IACE,WAAA,CAAY,IAAA,UAAc,QAAA,WAAmB,QAAA;IAC7C,aAAA,CAAc,KAAA;IACd,aAAA,CAAc,KAAA;EAAA;AAAA;AAAA,UAIR,iBAAA;EACR,IAAA;EACA,OAAA;EACA,MAAA;EACA,QAAA;AAAA;AAAA,cAoFW,gBAAA,GAAgB,IAAA,EAAA,gBAAA,EAAA,QAAA,WAAA,QAAA,YAAA,MAAA,kCAAA,iBAAA;AAAA,cAKhB,aAAA,GAAa,IAAA,EAAA,gBAAA,EAAA,QAAA,WAAA,QAAA,YAAA,MAAA,kCAAA,iBAAA;AAAA,cAKb,iBAAA,GAAiB,IAAA,EAAA,gBAAA,EAAA,QAAA,WAAA,QAAA,YAAA,MAAA,kCAAA,iBAAA;AAAA,cAKjB,eAAA,GAAe,IAAA,EAAA,gBAAA,EAAA,QAAA,WAAA,QAAA,YAAA,MAAA,kCAAA,iBAAA;AAAA,iB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A0B,CAAA;EAChD,wBAAA,CAAyB,QAAA,GAAW,MAAA,oBAA0B,CAAA;AAAA;AAAA;EAAA,UAKpD,QAAA,kBAA0B,iBAAA,CAAkB,CAAA;AAAA"}
@@ -0,0 +1,203 @@
1
+ import { BaseMessage } from "../messages/base.js";
2
+ import { ToolMessage } from "../messages/tool.js";
3
+ import { AIMessage } from "../messages/ai.js";
4
+ import { HumanMessage } from "../messages/human.js";
5
+ import { SystemMessage } from "../messages/system.js";
6
+ import "../messages/index.js";
7
+
8
+ //#region src/testing/matchers.ts
9
+ function getMessageTypeName(msg) {
10
+ if (!BaseMessage.isInstance(msg)) return typeof msg;
11
+ return msg.constructor.name || msg.type;
12
+ }
13
+ function makeMessageTypeMatcher(typeName, isInstance) {
14
+ return function(received, expected) {
15
+ const { isNot, utils } = this;
16
+ if (!isInstance(received)) return {
17
+ pass: false,
18
+ message: () => `${utils.matcherHint(`toBe${typeName}`, void 0, void 0)}\n\nExpected: ${isNot ? "not " : ""}${typeName}\nReceived: ${getMessageTypeName(received)}`,
19
+ actual: getMessageTypeName(received),
20
+ expected: typeName
21
+ };
22
+ if (expected === void 0) return {
23
+ pass: true,
24
+ message: () => `${utils.matcherHint(`toBe${typeName}`, void 0, void 0)}\n\nExpected: not ${typeName}\nReceived: ${typeName}`
25
+ };
26
+ const msg = received;
27
+ if (typeof expected === "string") return {
28
+ pass: msg.content === expected,
29
+ message: () => `${utils.matcherHint(`toBe${typeName}`, void 0, void 0)}\n\nExpected: ${typeName} with content ${utils.printExpected(expected)}\nReceived: ${typeName} with content ${utils.printReceived(msg.content)}`,
30
+ actual: msg.content,
31
+ expected
32
+ };
33
+ return {
34
+ pass: Object.entries(expected).every(([key, value]) => this.equals(msg[key], value)),
35
+ message: () => {
36
+ const receivedFields = {};
37
+ for (const key of Object.keys(expected)) receivedFields[key] = msg[key];
38
+ return `${utils.matcherHint(`toBe${typeName}`, void 0, void 0)}\n\nExpected: ${typeName} matching ${utils.printExpected(expected)}\nReceived: ${typeName} with ${utils.printReceived(receivedFields)}`;
39
+ },
40
+ actual: (() => {
41
+ const receivedFields = {};
42
+ for (const key of Object.keys(expected)) receivedFields[key] = msg[key];
43
+ return receivedFields;
44
+ })(),
45
+ expected
46
+ };
47
+ };
48
+ }
49
+ const toBeHumanMessage = makeMessageTypeMatcher("HumanMessage", HumanMessage.isInstance);
50
+ const toBeAIMessage = makeMessageTypeMatcher("AIMessage", AIMessage.isInstance);
51
+ const toBeSystemMessage = makeMessageTypeMatcher("SystemMessage", SystemMessage.isInstance);
52
+ const toBeToolMessage = makeMessageTypeMatcher("ToolMessage", ToolMessage.isInstance);
53
+ function toHaveToolCalls(received, expected) {
54
+ const { isNot, utils } = this;
55
+ if (!AIMessage.isInstance(received)) return {
56
+ pass: false,
57
+ message: () => `${utils.matcherHint("toHaveToolCalls")}\n\nExpected: AIMessage\nReceived: ${getMessageTypeName(received)}`
58
+ };
59
+ const actual = received.tool_calls ?? [];
60
+ if (actual.length !== expected.length) return {
61
+ pass: false,
62
+ message: () => `${utils.matcherHint("toHaveToolCalls")}\n\nExpected ${isNot ? "not " : ""}${expected.length} tool call(s), received ${actual.length}`,
63
+ actual: actual.length,
64
+ expected: expected.length
65
+ };
66
+ const unmatched = expected.filter((exp) => !actual.some((tc) => Object.entries(exp).every(([key, value]) => this.equals(tc[key], value))));
67
+ if (unmatched.length > 0) return {
68
+ pass: false,
69
+ message: () => `${utils.matcherHint("toHaveToolCalls")}\n\nCould not find matching tool call(s) for:\n${utils.printExpected(unmatched)}\nReceived tool calls: ${utils.printReceived(actual.map((tc) => ({
70
+ name: tc.name,
71
+ id: tc.id,
72
+ args: tc.args
73
+ })))}`,
74
+ actual: actual.map((tc) => ({
75
+ name: tc.name,
76
+ id: tc.id,
77
+ args: tc.args
78
+ })),
79
+ expected
80
+ };
81
+ return {
82
+ pass: true,
83
+ message: () => `${utils.matcherHint("toHaveToolCalls")}\n\nExpected AIMessage not to have matching tool calls`
84
+ };
85
+ }
86
+ function toHaveToolCallCount(received, expected) {
87
+ const { isNot, utils } = this;
88
+ if (!AIMessage.isInstance(received)) return {
89
+ pass: false,
90
+ message: () => `${utils.matcherHint("toHaveToolCallCount")}\n\nExpected: AIMessage\nReceived: ${getMessageTypeName(received)}`
91
+ };
92
+ const actual = received.tool_calls?.length ?? 0;
93
+ return {
94
+ pass: actual === expected,
95
+ message: () => `${utils.matcherHint("toHaveToolCallCount")}\n\nExpected ${isNot ? "not " : ""}${expected} tool call(s)\nReceived: ${actual}`,
96
+ actual,
97
+ expected
98
+ };
99
+ }
100
+ function toContainToolCall(received, expected) {
101
+ const { isNot, utils } = this;
102
+ if (!AIMessage.isInstance(received)) return {
103
+ pass: false,
104
+ message: () => `${utils.matcherHint("toContainToolCall")}\n\nExpected: AIMessage\nReceived: ${getMessageTypeName(received)}`
105
+ };
106
+ const actual = received.tool_calls ?? [];
107
+ return {
108
+ pass: actual.some((tc) => Object.entries(expected).every(([key, value]) => this.equals(tc[key], value))),
109
+ message: () => `${utils.matcherHint("toContainToolCall")}\n\nExpected AIMessage ${isNot ? "not " : ""}to contain a tool call matching ${utils.printExpected(expected)}\nReceived tool calls: ${utils.printReceived(actual.map((tc) => ({
110
+ name: tc.name,
111
+ id: tc.id
112
+ })))}`,
113
+ actual: actual.map((tc) => ({
114
+ name: tc.name,
115
+ id: tc.id
116
+ })),
117
+ expected
118
+ };
119
+ }
120
+ function toHaveToolMessages(received, expected) {
121
+ const { isNot, utils } = this;
122
+ if (!Array.isArray(received)) return {
123
+ pass: false,
124
+ message: () => `${utils.matcherHint("toHaveToolMessages")}\n\nExpected an array of messages\nReceived: ${typeof received}`
125
+ };
126
+ const toolMessages = received.filter(ToolMessage.isInstance);
127
+ if (toolMessages.length !== expected.length) return {
128
+ pass: false,
129
+ message: () => `${utils.matcherHint("toHaveToolMessages")}\n\nExpected ${isNot ? "not " : ""}${expected.length} tool message(s), found ${toolMessages.length}`,
130
+ actual: toolMessages.length,
131
+ expected: expected.length
132
+ };
133
+ for (let i = 0; i < expected.length; i++) if (!Object.entries(expected[i]).every(([key, value]) => this.equals(toolMessages[i][key], value))) return {
134
+ pass: false,
135
+ message: () => {
136
+ const receivedFields = {};
137
+ for (const key of Object.keys(expected[i])) receivedFields[key] = toolMessages[i][key];
138
+ return `${utils.matcherHint("toHaveToolMessages")}\n\nTool message at index ${i} did not match:\nExpected: ${utils.printExpected(expected[i])}\nReceived: ${utils.printReceived(receivedFields)}`;
139
+ },
140
+ actual: toolMessages[i],
141
+ expected: expected[i]
142
+ };
143
+ return {
144
+ pass: true,
145
+ message: () => `${utils.matcherHint("toHaveToolMessages")}\n\nExpected messages not to contain matching tool messages`
146
+ };
147
+ }
148
+ function toHaveBeenInterrupted(received, expectedValue) {
149
+ const { isNot, utils } = this;
150
+ const interrupts = received?.__interrupt__;
151
+ if (!(Array.isArray(interrupts) && interrupts.length > 0)) return {
152
+ pass: false,
153
+ message: () => `${utils.matcherHint("toHaveBeenInterrupted")}\n\nExpected result ${isNot ? "not " : ""}to have been interrupted\nReceived __interrupt__: ${utils.printReceived(interrupts)}`
154
+ };
155
+ if (expectedValue === void 0) return {
156
+ pass: true,
157
+ message: () => `${utils.matcherHint("toHaveBeenInterrupted")}\n\nExpected result not to have been interrupted\nReceived ${interrupts.length} interrupt(s)`
158
+ };
159
+ const actualValue = interrupts[0]?.value;
160
+ return {
161
+ pass: this.equals(actualValue, expectedValue),
162
+ message: () => `${utils.matcherHint("toHaveBeenInterrupted")}\n\nExpected interrupt value: ${utils.printExpected(expectedValue)}\nReceived interrupt value: ${utils.printReceived(actualValue)}`,
163
+ actual: actualValue,
164
+ expected: expectedValue
165
+ };
166
+ }
167
+ function toHaveStructuredResponse(received, expected) {
168
+ const { isNot, utils } = this;
169
+ const structuredResponse = received?.structuredResponse;
170
+ if (!(structuredResponse !== void 0)) return {
171
+ pass: false,
172
+ message: () => `${utils.matcherHint("toHaveStructuredResponse")}\n\nExpected result ${isNot ? "not " : ""}to have a structured response\nReceived structuredResponse: undefined`
173
+ };
174
+ if (expected === void 0) return {
175
+ pass: true,
176
+ message: () => `${utils.matcherHint("toHaveStructuredResponse")}\n\nExpected result not to have a structured response`
177
+ };
178
+ return {
179
+ pass: Object.entries(expected).every(([key, value]) => this.equals(structuredResponse[key], value)),
180
+ message: () => `${utils.matcherHint("toHaveStructuredResponse")}\n\nExpected structured response: ${utils.printExpected(expected)}\nReceived structured response: ${utils.printReceived(structuredResponse)}`,
181
+ actual: structuredResponse,
182
+ expected
183
+ };
184
+ }
185
+ /**
186
+ * All matcher functions bundled for convenient use with `expect.extend()`.
187
+ */
188
+ const langchainMatchers = {
189
+ toBeHumanMessage,
190
+ toBeAIMessage,
191
+ toBeSystemMessage,
192
+ toBeToolMessage,
193
+ toHaveToolCalls,
194
+ toHaveToolCallCount,
195
+ toContainToolCall,
196
+ toHaveToolMessages,
197
+ toHaveBeenInterrupted,
198
+ toHaveStructuredResponse
199
+ };
200
+
201
+ //#endregion
202
+ export { langchainMatchers, toBeAIMessage, toBeHumanMessage, toBeSystemMessage, toBeToolMessage, toContainToolCall, toHaveBeenInterrupted, toHaveStructuredResponse, toHaveToolCallCount, toHaveToolCalls, toHaveToolMessages };
203
+ //# sourceMappingURL=matchers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchers.js","names":[],"sources":["../../src/testing/matchers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { BaseMessage } from \"../messages/index.js\";\nimport { HumanMessage } from \"../messages/index.js\";\nimport { AIMessage } from \"../messages/index.js\";\nimport { SystemMessage } from \"../messages/index.js\";\nimport { ToolMessage } from \"../messages/index.js\";\n\n/**\n * The `this` context that Vitest and Jest provide to custom matchers\n * via `expect.extend`.\n *\n * Compatible with both frameworks:\n * - https://vitest.dev/guide/extending-matchers.html\n * - https://jestjs.io/docs/expect#expectextendmatchers\n */\ninterface ExpectExtendThis {\n isNot?: boolean;\n equals(a: unknown, b: unknown): boolean;\n utils: {\n matcherHint(name: string, received?: string, expected?: string): string;\n printReceived(value: unknown): string;\n printExpected(value: unknown): string;\n };\n}\n\ninterface ExpectationResult {\n pass: boolean;\n message: () => string;\n actual?: unknown;\n expected?: unknown;\n}\n\nfunction getMessageTypeName(msg: unknown): string {\n if (!BaseMessage.isInstance(msg)) return typeof msg;\n return msg.constructor.name || msg.type;\n}\n\nfunction makeMessageTypeMatcher(\n typeName: string,\n isInstance: (obj: unknown) => boolean\n) {\n return function (\n this: ExpectExtendThis,\n received: unknown,\n expected?: string | Record<string, unknown>\n ): ExpectationResult {\n const { isNot, utils } = this;\n\n const instancePass = isInstance(received);\n if (!instancePass) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(`toBe${typeName}`, undefined, undefined)}\\n\\n` +\n `Expected: ${isNot ? \"not \" : \"\"}${typeName}\\n` +\n `Received: ${getMessageTypeName(received)}`,\n actual: getMessageTypeName(received),\n expected: typeName,\n };\n }\n\n if (expected === undefined) {\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(`toBe${typeName}`, undefined, undefined)}\\n\\n` +\n `Expected: not ${typeName}\\n` +\n `Received: ${typeName}`,\n };\n }\n\n const msg = received as BaseMessage;\n if (typeof expected === \"string\") {\n const contentPass = msg.content === expected;\n return {\n pass: contentPass,\n message: () =>\n `${utils.matcherHint(`toBe${typeName}`, undefined, undefined)}\\n\\n` +\n `Expected: ${typeName} with content ${utils.printExpected(expected)}\\n` +\n `Received: ${typeName} with content ${utils.printReceived(msg.content)}`,\n actual: msg.content,\n expected,\n };\n }\n\n const fieldsPass = Object.entries(expected).every(([key, value]) =>\n this.equals((msg as any)[key], value)\n );\n return {\n pass: fieldsPass,\n message: () => {\n const receivedFields: Record<string, unknown> = {};\n for (const key of Object.keys(expected)) {\n receivedFields[key] = (msg as any)[key];\n }\n return (\n `${utils.matcherHint(`toBe${typeName}`, undefined, undefined)}\\n\\n` +\n `Expected: ${typeName} matching ${utils.printExpected(expected)}\\n` +\n `Received: ${typeName} with ${utils.printReceived(receivedFields)}`\n );\n },\n actual: (() => {\n const receivedFields: Record<string, unknown> = {};\n for (const key of Object.keys(expected)) {\n receivedFields[key] = (msg as any)[key];\n }\n return receivedFields;\n })(),\n expected,\n };\n };\n}\n\nexport const toBeHumanMessage = makeMessageTypeMatcher(\n \"HumanMessage\",\n HumanMessage.isInstance\n);\n\nexport const toBeAIMessage = makeMessageTypeMatcher(\n \"AIMessage\",\n AIMessage.isInstance\n);\n\nexport const toBeSystemMessage = makeMessageTypeMatcher(\n \"SystemMessage\",\n SystemMessage.isInstance\n);\n\nexport const toBeToolMessage = makeMessageTypeMatcher(\n \"ToolMessage\",\n ToolMessage.isInstance\n);\n\nexport function toHaveToolCalls(\n this: ExpectExtendThis,\n received: unknown,\n expected: Array<Record<string, unknown>>\n): ExpectationResult {\n const { isNot, utils } = this;\n\n if (!AIMessage.isInstance(received)) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCalls\")}\\n\\n` +\n `Expected: AIMessage\\n` +\n `Received: ${getMessageTypeName(received)}`,\n };\n }\n\n const actual = received.tool_calls ?? [];\n\n if (actual.length !== expected.length) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCalls\")}\\n\\n` +\n `Expected ${isNot ? \"not \" : \"\"}${expected.length} tool call(s), received ${actual.length}`,\n actual: actual.length,\n expected: expected.length,\n };\n }\n\n const unmatched = expected.filter(\n (exp) =>\n !actual.some((tc) =>\n Object.entries(exp).every(([key, value]) =>\n this.equals((tc as any)[key], value)\n )\n )\n );\n\n if (unmatched.length > 0) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCalls\")}\\n\\n` +\n `Could not find matching tool call(s) for:\\n` +\n `${utils.printExpected(unmatched)}\\n` +\n `Received tool calls: ${utils.printReceived(actual.map((tc) => ({ name: tc.name, id: tc.id, args: tc.args })))}`,\n actual: actual.map((tc) => ({ name: tc.name, id: tc.id, args: tc.args })),\n expected,\n };\n }\n\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCalls\")}\\n\\n` +\n `Expected AIMessage not to have matching tool calls`,\n };\n}\n\nexport function toHaveToolCallCount(\n this: ExpectExtendThis,\n received: unknown,\n expected: number\n): ExpectationResult {\n const { isNot, utils } = this;\n\n if (!AIMessage.isInstance(received)) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCallCount\")}\\n\\n` +\n `Expected: AIMessage\\n` +\n `Received: ${getMessageTypeName(received)}`,\n };\n }\n\n const actual = received.tool_calls?.length ?? 0;\n const pass = actual === expected;\n\n return {\n pass,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCallCount\")}\\n\\n` +\n `Expected ${isNot ? \"not \" : \"\"}${expected} tool call(s)\\n` +\n `Received: ${actual}`,\n actual,\n expected,\n };\n}\n\nexport function toContainToolCall(\n this: ExpectExtendThis,\n received: unknown,\n expected: Record<string, unknown>\n): ExpectationResult {\n const { isNot, utils } = this;\n\n if (!AIMessage.isInstance(received)) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toContainToolCall\")}\\n\\n` +\n `Expected: AIMessage\\n` +\n `Received: ${getMessageTypeName(received)}`,\n };\n }\n\n const actual = received.tool_calls ?? [];\n const found = actual.some((tc) =>\n Object.entries(expected).every(([key, value]) =>\n this.equals((tc as any)[key], value)\n )\n );\n\n return {\n pass: found,\n message: () =>\n `${utils.matcherHint(\"toContainToolCall\")}\\n\\n` +\n `Expected AIMessage ${isNot ? \"not \" : \"\"}to contain a tool call matching ${utils.printExpected(expected)}\\n` +\n `Received tool calls: ${utils.printReceived(actual.map((tc) => ({ name: tc.name, id: tc.id })))}`,\n actual: actual.map((tc) => ({ name: tc.name, id: tc.id })),\n expected,\n };\n}\n\nexport function toHaveToolMessages(\n this: ExpectExtendThis,\n received: unknown,\n expected: Array<Record<string, unknown>>\n): ExpectationResult {\n const { isNot, utils } = this;\n\n if (!Array.isArray(received)) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolMessages\")}\\n\\n` +\n `Expected an array of messages\\n` +\n `Received: ${typeof received}`,\n };\n }\n\n const toolMessages = (received as BaseMessage[]).filter(\n ToolMessage.isInstance\n );\n\n if (toolMessages.length !== expected.length) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolMessages\")}\\n\\n` +\n `Expected ${isNot ? \"not \" : \"\"}${expected.length} tool message(s), found ${toolMessages.length}`,\n actual: toolMessages.length,\n expected: expected.length,\n };\n }\n\n for (let i = 0; i < expected.length; i++) {\n const match = Object.entries(expected[i]).every(([key, value]) =>\n this.equals((toolMessages[i] as any)[key], value)\n );\n if (!match) {\n return {\n pass: false,\n message: () => {\n const receivedFields: Record<string, unknown> = {};\n for (const key of Object.keys(expected[i])) {\n receivedFields[key] = (toolMessages[i] as any)[key];\n }\n return (\n `${utils.matcherHint(\"toHaveToolMessages\")}\\n\\n` +\n `Tool message at index ${i} did not match:\\n` +\n `Expected: ${utils.printExpected(expected[i])}\\n` +\n `Received: ${utils.printReceived(receivedFields)}`\n );\n },\n actual: toolMessages[i],\n expected: expected[i],\n };\n }\n }\n\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(\"toHaveToolMessages\")}\\n\\n` +\n `Expected messages not to contain matching tool messages`,\n };\n}\n\nexport function toHaveBeenInterrupted(\n this: ExpectExtendThis,\n received: unknown,\n expectedValue?: unknown\n): ExpectationResult {\n const { isNot, utils } = this;\n\n const result = received as Record<string, any>;\n const interrupts = result?.__interrupt__;\n const hasInterrupt = Array.isArray(interrupts) && interrupts.length > 0;\n\n if (!hasInterrupt) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveBeenInterrupted\")}\\n\\n` +\n `Expected result ${isNot ? \"not \" : \"\"}to have been interrupted\\n` +\n `Received __interrupt__: ${utils.printReceived(interrupts)}`,\n };\n }\n\n if (expectedValue === undefined) {\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(\"toHaveBeenInterrupted\")}\\n\\n` +\n `Expected result not to have been interrupted\\n` +\n `Received ${interrupts.length} interrupt(s)`,\n };\n }\n\n const actualValue = interrupts[0]?.value;\n const valuePass = this.equals(actualValue, expectedValue);\n\n return {\n pass: valuePass,\n message: () =>\n `${utils.matcherHint(\"toHaveBeenInterrupted\")}\\n\\n` +\n `Expected interrupt value: ${utils.printExpected(expectedValue)}\\n` +\n `Received interrupt value: ${utils.printReceived(actualValue)}`,\n actual: actualValue,\n expected: expectedValue,\n };\n}\n\nexport function toHaveStructuredResponse(\n this: ExpectExtendThis,\n received: unknown,\n expected?: Record<string, unknown>\n): ExpectationResult {\n const { isNot, utils } = this;\n\n const result = received as Record<string, any>;\n const structuredResponse = result?.structuredResponse;\n const isDefined = structuredResponse !== undefined;\n\n if (!isDefined) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveStructuredResponse\")}\\n\\n` +\n `Expected result ${isNot ? \"not \" : \"\"}to have a structured response\\n` +\n `Received structuredResponse: undefined`,\n };\n }\n\n if (expected === undefined) {\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(\"toHaveStructuredResponse\")}\\n\\n` +\n `Expected result not to have a structured response`,\n };\n }\n\n const fieldsPass = Object.entries(expected).every(([key, value]) =>\n this.equals(structuredResponse[key], value)\n );\n\n return {\n pass: fieldsPass,\n message: () =>\n `${utils.matcherHint(\"toHaveStructuredResponse\")}\\n\\n` +\n `Expected structured response: ${utils.printExpected(expected)}\\n` +\n `Received structured response: ${utils.printReceived(structuredResponse)}`,\n actual: structuredResponse,\n expected,\n };\n}\n\n/**\n * All matcher functions bundled for convenient use with `expect.extend()`.\n */\nexport const langchainMatchers = {\n toBeHumanMessage,\n toBeAIMessage,\n toBeSystemMessage,\n toBeToolMessage,\n toHaveToolCalls,\n toHaveToolCallCount,\n toContainToolCall,\n toHaveToolMessages,\n toHaveBeenInterrupted,\n toHaveStructuredResponse,\n};\n\nexport interface LangChainMatchers<R = unknown> {\n toBeHumanMessage(expected?: string | { content?: string; id?: string }): R;\n toBeAIMessage(expected?: string | { content?: string; name?: string }): R;\n toBeSystemMessage(\n expected?: string | { content?: string; additional_kwargs?: object }\n ): R;\n toBeToolMessage(\n expected?:\n | string\n | {\n content?: string;\n name?: string;\n status?: string;\n tool_call_id?: string;\n }\n ): R;\n toHaveToolCalls(\n expected: Array<{\n name?: string;\n id?: string;\n args?: Record<string, unknown>;\n }>\n ): R;\n toHaveToolCallCount(expected: number): R;\n toContainToolCall(expected: {\n name?: string;\n id?: string;\n args?: Record<string, unknown>;\n }): R;\n toHaveToolMessages(\n expected: Array<{\n content?: string;\n name?: string;\n status?: string;\n tool_call_id?: string;\n }>\n ): R;\n toHaveBeenInterrupted(expectedValue?: unknown): R;\n toHaveStructuredResponse(expected?: Record<string, unknown>): R;\n}\n\ndeclare module \"vitest\" {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n interface Matchers<T = any> extends LangChainMatchers<T> {}\n}\n"],"mappings":";;;;;;;;AAgCA,SAAS,mBAAmB,KAAsB;AAChD,KAAI,CAAC,YAAY,WAAW,IAAI,CAAE,QAAO,OAAO;AAChD,QAAO,IAAI,YAAY,QAAQ,IAAI;;AAGrC,SAAS,uBACP,UACA,YACA;AACA,QAAO,SAEL,UACA,UACmB;EACnB,MAAM,EAAE,OAAO,UAAU;AAGzB,MAAI,CADiB,WAAW,SAAS,CAEvC,QAAO;GACL,MAAM;GACN,eACE,GAAG,MAAM,YAAY,OAAO,YAAY,QAAW,OAAU,CAAC,gBACjD,QAAQ,SAAS,KAAK,SAAS,cAC/B,mBAAmB,SAAS;GAC3C,QAAQ,mBAAmB,SAAS;GACpC,UAAU;GACX;AAGH,MAAI,aAAa,OACf,QAAO;GACL,MAAM;GACN,eACE,GAAG,MAAM,YAAY,OAAO,YAAY,QAAW,OAAU,CAAC,oBAC7C,SAAS,cACb;GAChB;EAGH,MAAM,MAAM;AACZ,MAAI,OAAO,aAAa,SAEtB,QAAO;GACL,MAFkB,IAAI,YAAY;GAGlC,eACE,GAAG,MAAM,YAA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;AAMH,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
@@ -10,7 +10,6 @@ const require_runnables = require('./runnables.cjs');
10
10
  const require_tools = require('./tools.cjs');
11
11
  const require_tracers = require('./tracers.cjs');
12
12
  const require_vectorstores = require('./vectorstores.cjs');
13
- const require_fake_model_builder = require('./fake_model_builder.cjs');
14
13
 
15
14
  //#region src/utils/testing/index.ts
16
15
  var testing_exports = /* @__PURE__ */ require_runtime.__exportAll({
@@ -29,8 +28,7 @@ var testing_exports = /* @__PURE__ */ require_runtime.__exportAll({
29
28
  FakeTracer: () => require_message_history.FakeTracer,
30
29
  FakeVectorStore: () => require_vectorstores.FakeVectorStore,
31
30
  SingleRunExtractor: () => require_tracers.SingleRunExtractor,
32
- SyntheticEmbeddings: () => require_embeddings.SyntheticEmbeddings,
33
- fakeModel: () => require_fake_model_builder.fakeModel
31
+ SyntheticEmbeddings: () => require_embeddings.SyntheticEmbeddings
34
32
  });
35
33
 
36
34
  //#endregion
@@ -50,7 +48,6 @@ exports.FakeTracer = require_message_history.FakeTracer;
50
48
  exports.FakeVectorStore = require_vectorstores.FakeVectorStore;
51
49
  exports.SingleRunExtractor = require_tracers.SingleRunExtractor;
52
50
  exports.SyntheticEmbeddings = require_embeddings.SyntheticEmbeddings;
53
- exports.fakeModel = require_fake_model_builder.fakeModel;
54
51
  Object.defineProperty(exports, 'testing_exports', {
55
52
  enumerable: true,
56
53
  get: function () {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/utils/testing/index.ts"],"sourcesContent":["export * from \"./chat_models.js\";\nexport * from \"./embeddings.js\";\nexport * from \"./llms.js\";\nexport * from \"./message_history.js\";\nexport * from \"./output_parsers.js\";\nexport * from \"./retrievers.js\";\nexport * from \"./runnables.js\";\nexport * from \"./tools.js\";\nexport * from \"./tracers.js\";\nexport * from \"./vectorstores.js\";\nexport { fakeModel } from \"./fake_model_builder.js\";\n"],"mappings":""}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/utils/testing/index.ts"],"sourcesContent":["export * from \"./chat_models.js\";\nexport * from \"./embeddings.js\";\nexport * from \"./llms.js\";\nexport * from \"./message_history.js\";\nexport * from \"./output_parsers.js\";\nexport * from \"./retrievers.js\";\nexport * from \"./runnables.js\";\nexport * from \"./tools.js\";\nexport * from \"./tracers.js\";\nexport * from \"./vectorstores.js\";\n"],"mappings":""}
@@ -8,5 +8,4 @@ import { FakeRunnable } from "./runnables.cjs";
8
8
  import { FakeTool, FakeToolParams } from "./tools.cjs";
9
9
  import { SingleRunExtractor } from "./tracers.cjs";
10
10
  import { FakeVectorStore, FakeVectorStoreArgs } from "./vectorstores.cjs";
11
- import { fakeModel } from "./fake_model_builder.cjs";
12
- export { FakeChatInput, FakeChatMessageHistory, FakeChatModel, FakeEmbeddings, FakeLLM, FakeListChatMessageHistory, FakeListChatModel, FakeListChatModelCallOptions, FakeRetriever, FakeRunnable, FakeSplitIntoListParser, FakeStreamingChatModel, FakeStreamingChatModelCallOptions, FakeStreamingChatModelFields, FakeStreamingLLM, FakeTool, FakeToolParams, FakeTracer, FakeVectorStore, FakeVectorStoreArgs, SingleRunExtractor, SyntheticEmbeddings, ToolSpec, fakeModel };
11
+ export { FakeChatInput, FakeChatMessageHistory, FakeChatModel, FakeEmbeddings, FakeLLM, FakeListChatMessageHistory, FakeListChatModel, FakeListChatModelCallOptions, FakeRetriever, FakeRunnable, FakeSplitIntoListParser, FakeStreamingChatModel, FakeStreamingChatModelCallOptions, FakeStreamingChatModelFields, FakeStreamingLLM, FakeTool, FakeToolParams, FakeTracer, FakeVectorStore, FakeVectorStoreArgs, SingleRunExtractor, SyntheticEmbeddings, ToolSpec };
@@ -8,5 +8,4 @@ import { FakeRunnable } from "./runnables.js";
8
8
  import { FakeTool, FakeToolParams } from "./tools.js";
9
9
  import { SingleRunExtractor } from "./tracers.js";
10
10
  import { FakeVectorStore, FakeVectorStoreArgs } from "./vectorstores.js";
11
- import { fakeModel } from "./fake_model_builder.js";
12
- export { FakeChatInput, FakeChatMessageHistory, FakeChatModel, FakeEmbeddings, FakeLLM, FakeListChatMessageHistory, FakeListChatModel, FakeListChatModelCallOptions, FakeRetriever, FakeRunnable, FakeSplitIntoListParser, FakeStreamingChatModel, FakeStreamingChatModelCallOptions, FakeStreamingChatModelFields, FakeStreamingLLM, FakeTool, FakeToolParams, FakeTracer, FakeVectorStore, FakeVectorStoreArgs, SingleRunExtractor, SyntheticEmbeddings, ToolSpec, fakeModel };
11
+ export { FakeChatInput, FakeChatMessageHistory, FakeChatModel, FakeEmbeddings, FakeLLM, FakeListChatMessageHistory, FakeListChatModel, FakeListChatModelCallOptions, FakeRetriever, FakeRunnable, FakeSplitIntoListParser, FakeStreamingChatModel, FakeStreamingChatModelCallOptions, FakeStreamingChatModelFields, FakeStreamingLLM, FakeTool, FakeToolParams, FakeTracer, FakeVectorStore, FakeVectorStoreArgs, SingleRunExtractor, SyntheticEmbeddings, ToolSpec };
@@ -9,7 +9,6 @@ import { FakeRunnable } from "./runnables.js";
9
9
  import { FakeTool } from "./tools.js";
10
10
  import { SingleRunExtractor } from "./tracers.js";
11
11
  import { FakeVectorStore } from "./vectorstores.js";
12
- import { fakeModel } from "./fake_model_builder.js";
13
12
 
14
13
  //#region src/utils/testing/index.ts
15
14
  var testing_exports = /* @__PURE__ */ __exportAll({
@@ -28,10 +27,9 @@ var testing_exports = /* @__PURE__ */ __exportAll({
28
27
  FakeTracer: () => FakeTracer,
29
28
  FakeVectorStore: () => FakeVectorStore,
30
29
  SingleRunExtractor: () => SingleRunExtractor,
31
- SyntheticEmbeddings: () => SyntheticEmbeddings,
32
- fakeModel: () => fakeModel
30
+ SyntheticEmbeddings: () => SyntheticEmbeddings
33
31
  });
34
32
 
35
33
  //#endregion
36
- export { FakeChatMessageHistory, FakeChatModel, FakeEmbeddings, FakeLLM, FakeListChatMessageHistory, FakeListChatModel, FakeRetriever, FakeRunnable, FakeSplitIntoListParser, FakeStreamingChatModel, FakeStreamingLLM, FakeTool, FakeTracer, FakeVectorStore, SingleRunExtractor, SyntheticEmbeddings, fakeModel, testing_exports };
34
+ export { FakeChatMessageHistory, FakeChatModel, FakeEmbeddings, FakeLLM, FakeListChatMessageHistory, FakeListChatModel, FakeRetriever, FakeRunnable, FakeSplitIntoListParser, FakeStreamingChatModel, FakeStreamingLLM, FakeTool, FakeTracer, FakeVectorStore, SingleRunExtractor, SyntheticEmbeddings, testing_exports };
37
35
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/testing/index.ts"],"sourcesContent":["export * from \"./chat_models.js\";\nexport * from \"./embeddings.js\";\nexport * from \"./llms.js\";\nexport * from \"./message_history.js\";\nexport * from \"./output_parsers.js\";\nexport * from \"./retrievers.js\";\nexport * from \"./runnables.js\";\nexport * from \"./tools.js\";\nexport * from \"./tracers.js\";\nexport * from \"./vectorstores.js\";\nexport { fakeModel } from \"./fake_model_builder.js\";\n"],"mappings":""}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/testing/index.ts"],"sourcesContent":["export * from \"./chat_models.js\";\nexport * from \"./embeddings.js\";\nexport * from \"./llms.js\";\nexport * from \"./message_history.js\";\nexport * from \"./output_parsers.js\";\nexport * from \"./retrievers.js\";\nexport * from \"./runnables.js\";\nexport * from \"./tools.js\";\nexport * from \"./tracers.js\";\nexport * from \"./vectorstores.js\";\n"],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "1.1.30",
3
+ "version": "1.1.31",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {
@@ -41,8 +41,8 @@
41
41
  "typescript": "~5.8.3",
42
42
  "vitest": "^3.2.4",
43
43
  "web-streams-polyfill": "^4.2.0",
44
- "@langchain/tsconfig": "0.0.1",
45
- "@langchain/eslint": "0.1.1"
44
+ "@langchain/eslint": "0.1.1",
45
+ "@langchain/tsconfig": "0.0.1"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public"
@@ -502,6 +502,17 @@
502
502
  "default": "./dist/structured_query/index.js"
503
503
  }
504
504
  },
505
+ "./testing": {
506
+ "input": "./src/testing/index.ts",
507
+ "require": {
508
+ "types": "./dist/testing/index.d.cts",
509
+ "default": "./dist/testing/index.cjs"
510
+ },
511
+ "import": {
512
+ "types": "./dist/testing/index.d.ts",
513
+ "default": "./dist/testing/index.js"
514
+ }
515
+ },
505
516
  "./tools": {
506
517
  "input": "./src/tools/index.ts",
507
518
  "require": {
@@ -862,6 +873,7 @@
862
873
  "runnables.cjs",
863
874
  "runnables.d.ts",
864
875
  "runnables.js",
876
+ "testing",
865
877
  "tools.d.cts",
866
878
  "tools.cjs",
867
879
  "tools.d.ts",
@@ -1 +0,0 @@
1
- {"version":3,"file":"fake_model_builder.cjs","names":["BaseChatModel","BaseMessage","RunnableLambda","AIMessage"],"sources":["../../../src/utils/testing/fake_model_builder.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { CallbackManagerForLLMRun } from \"../../callbacks/manager.js\";\nimport {\n BaseChatModel,\n BaseChatModelCallOptions,\n} from \"../../language_models/chat_models.js\";\nimport {\n BaseLanguageModelInput,\n StructuredOutputMethodOptions,\n StructuredOutputMethodParams,\n} from \"../../language_models/base.js\";\nimport { BaseMessage, AIMessage } from \"../../messages/index.js\";\nimport type { ToolCall } from \"../../messages/tool.js\";\nimport type { ChatResult } from \"../../outputs.js\";\nimport { Runnable, RunnableLambda } from \"../../runnables/base.js\";\nimport { StructuredTool } from \"../../tools/index.js\";\nimport type { InteropZodType } from \"../types/zod.js\";\nimport type { ToolSpec } from \"./chat_models.js\";\n\ntype ResponseFactory = (messages: BaseMessage[]) => BaseMessage | Error;\n\ntype QueueEntry =\n | { kind: \"message\"; message: BaseMessage }\n | { kind: \"toolCalls\"; toolCalls: ToolCall[] }\n | { kind: \"error\"; error: Error }\n | { kind: \"factory\"; factory: ResponseFactory };\n\ninterface FakeModelCall {\n messages: BaseMessage[];\n options: any;\n}\n\nfunction deriveContent(messages: BaseMessage[]): string {\n return messages\n .map((m) => m.text)\n .filter(Boolean)\n .join(\"-\");\n}\n\nlet idCounter = 0;\nfunction nextToolCallId(): string {\n idCounter += 1;\n return `fake_tc_${idCounter}`;\n}\n\n/**\n * A fake chat model for testing, created via {@link fakeModel}.\n *\n * Queue responses with `.respond()` and `.respondWithTools()`, then\n * pass the instance directly wherever a chat model is expected.\n *\n * Each builder method queues a model response consumed in order per `invoke()`:\n *\n * `.respond(entry)` — enqueue a `BaseMessage`, `Error`, or factory function.\n *\n * `.respondWithTools(toolCalls[])` — enqueue an `AIMessage` with the given\n * tool calls. Content is derived from the input messages automatically.\n *\n * Both can be mixed freely in one chain. When all queued responses are\n * consumed, further invocations throw.\n *\n * Additional configuration:\n * - `.alwaysThrow(error)` — every call throws (overrides the queue)\n * - `.structuredResponse(value)` — value returned by `withStructuredOutput()`\n *\n * The model records all invocations in `.calls` / `.callCount`.\n */\nclass FakeBuiltModel extends BaseChatModel {\n private queue: QueueEntry[] = [];\n\n private _alwaysThrowError: Error | undefined;\n\n private _structuredResponseValue: any;\n\n private _tools: (StructuredTool | ToolSpec)[] = [];\n\n private _callIndex = 0;\n\n private _calls: FakeModelCall[] = [];\n\n get calls(): FakeModelCall[] {\n return this._calls;\n }\n\n get callCount(): number {\n return this._calls.length;\n }\n\n constructor() {\n super({});\n }\n\n _llmType(): string {\n return \"fake-model-builder\";\n }\n\n _combineLLMOutput() {\n return [];\n }\n\n respond(entry: BaseMessage | Error | ResponseFactory): this {\n if (typeof entry === \"function\") {\n this.queue.push({ kind: \"factory\", factory: entry });\n } else if (BaseMessage.isInstance(entry)) {\n this.queue.push({ kind: \"message\", message: entry });\n } else {\n this.queue.push({ kind: \"error\", error: entry });\n }\n return this;\n }\n\n respondWithTools(\n toolCalls: Array<{ name: string; args: Record<string, any>; id?: string }>\n ): this {\n this.queue.push({\n kind: \"toolCalls\",\n toolCalls: toolCalls.map((tc) => ({\n name: tc.name,\n args: tc.args,\n id: tc.id ?? nextToolCallId(),\n type: \"tool_call\" as const,\n })),\n });\n return this;\n }\n\n alwaysThrow(error: Error): this {\n this._alwaysThrowError = error;\n return this;\n }\n\n structuredResponse(value: Record<string, any>): this {\n this._structuredResponseValue = value;\n return this;\n }\n\n bindTools(tools: (StructuredTool | ToolSpec)[]) {\n const merged = [...this._tools, ...tools];\n const next = new FakeBuiltModel();\n next.queue = this.queue;\n next._alwaysThrowError = this._alwaysThrowError;\n next._structuredResponseValue = this._structuredResponseValue;\n next._tools = merged;\n next._calls = this._calls;\n next._callIndex = this._callIndex;\n\n return next.withConfig({} as BaseChatModelCallOptions);\n }\n\n withStructuredOutput<\n RunOutput extends Record<string, any> = Record<string, any>,\n >(\n _params:\n | StructuredOutputMethodParams<RunOutput, boolean>\n | InteropZodType<RunOutput>\n | Record<string, any>,\n _config?: StructuredOutputMethodOptions<boolean>\n ):\n | Runnable<BaseLanguageModelInput, RunOutput>\n | Runnable<\n BaseLanguageModelInput,\n { raw: BaseMessage; parsed: RunOutput }\n > {\n const { _structuredResponseValue } = this;\n return RunnableLambda.from(async () => {\n return _structuredResponseValue as RunOutput;\n }) as Runnable;\n }\n\n async _generate(\n messages: BaseMessage[],\n options?: this[\"ParsedCallOptions\"],\n _runManager?: CallbackManagerForLLMRun\n ): Promise<ChatResult> {\n this._calls.push({ messages: [...messages], options });\n\n const currentCallIndex = this._callIndex;\n this._callIndex += 1;\n\n if (this._alwaysThrowError) {\n throw this._alwaysThrowError;\n }\n\n const entry = this.queue[currentCallIndex];\n if (!entry) {\n throw new Error(\n `FakeModel: no response queued for invocation ${currentCallIndex} (${this.queue.length} total queued).`\n );\n }\n\n if (entry.kind === \"error\") {\n throw entry.error;\n }\n\n if (entry.kind === \"factory\") {\n const result = entry.factory(messages);\n if (!BaseMessage.isInstance(result)) {\n throw result;\n }\n return {\n generations: [{ text: \"\", message: result }],\n };\n }\n\n if (entry.kind === \"message\") {\n return {\n generations: [{ text: \"\", message: entry.message }],\n };\n }\n\n const content = deriveContent(messages);\n const message = new AIMessage({\n content,\n id: currentCallIndex.toString(),\n tool_calls:\n entry.toolCalls.length > 0\n ? entry.toolCalls.map((tc) => ({\n ...tc,\n type: \"tool_call\" as const,\n }))\n : undefined,\n });\n\n return {\n generations: [{ text: content, message }],\n llmOutput: {},\n };\n }\n}\n\n/**\n * Creates a fake chat model for testing.\n *\n * @example\n * ```typescript\n * const model = fakeModel()\n * .respondWithTools([{ name: \"search\", args: { query: \"weather\" } }])\n * .respond(new AIMessage(\"Sunny and warm.\"));\n *\n * const r1 = await model.invoke([new HumanMessage(\"What's the weather?\")]);\n * // r1.tool_calls[0].name === \"search\"\n *\n * const r2 = await model.invoke([new HumanMessage(\"Thanks\")]);\n * // r2.content === \"Sunny and warm.\"\n * ```\n */\nexport function fakeModel(): FakeBuiltModel {\n return new FakeBuiltModel();\n}\n"],"mappings":";;;;;;;AAgCA,SAAS,cAAc,UAAiC;AACtD,QAAO,SACJ,KAAK,MAAM,EAAE,KAAK,CAClB,OAAO,QAAQ,CACf,KAAK,IAAI;;AAGd,IAAI,YAAY;AAChB,SAAS,iBAAyB;AAChC,cAAa;AACb,QAAO,WAAW;;;;;;;;;;;;;;;;;;;;;;;;AAyBpB,IAAM,iBAAN,MAAM,uBAAuBA,kDAAc;CACzC,AAAQ,QAAsB,EAAE;CAEhC,AAAQ;CAER,AAAQ;CAER,AAAQ,SAAwC,EAAE;CAElD,AAAQ,aAAa;CAErB,AAAQ,SAA0B,EAAE;CAEpC,IAAI,QAAyB;AAC3B,SAAO,KAAK;;CAGd,IAAI,YAAoB;AACtB,SAAO,KAAK,OAAO;;CAGrB,cAAc;AACZ,QAAM,EAAE,CAAC;;CAGX,WAAmB;AACjB,SAAO;;CAGT,oBAAoB;AAClB,SAAO,EAAE;;CAGX,QAAQ,OAAoD;AAC1D,MAAI,OAAO,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IA,OAAA,CAAQ,KAAA,EAAO,WAAA,GAAc,KAAA,GAAQ,eAAA;EAWrC,gBAAA,CACE,SAAA,EAAW,KAAA;IAAQ,IAAA;IAAc,IAAA,EAAM,MAAA;IAAqB,EAAA;EAAA;EAc9D,WAAA,CAAY,KAAA,EAAO,KAAA;EAKnB,kBAAA,CAAmB,KAAA,EAAO,MAAA;EAK1B,SAAA,CAAU,KAAA,GAAQ,cAAA,GAAiB,QAAA,MAAW,QAAA,CAAA,sBAAA,EAAA,cAAA,CAAA,gBAAA,CAAA,cAAA,IAAA,wBAAA;EAa9C,oBAAA,mBACoB,MAAA,gBAAsB,MAAA,cAAA,CAExC,OAAA,EACI,4BAAA,CAA6B,SAAA,aAC7B,cAAA,CAAe,SAAA,IACf,MAAA,eACJ,OAAA,GAAU,6BAAA,YAER,QAAA,CAAS,sBAAA,EAAwB,SAAA,IACjC,QAAA,CACE,sBAAA;IACE,GAAA,EAAK,WAAA;IAAa,MAAA,EAAQ,SAAA;EAAA;EAQ5B,SAAA,CACJ,QAAA,EAAU,WAAA,IACV,OAAA,8BACA,WAAA,GAAc,wBAAA,GACb,OAAA,CAAQ,UAAA;AAAA;;;;;;;;;;;;;;;;;iBAyEG,SAAA,CAAA,GAAa,cAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"fake_model_builder.js","names":[],"sources":["../../../src/utils/testing/fake_model_builder.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { CallbackManagerForLLMRun } from \"../../callbacks/manager.js\";\nimport {\n BaseChatModel,\n BaseChatModelCallOptions,\n} from \"../../language_models/chat_models.js\";\nimport {\n BaseLanguageModelInput,\n StructuredOutputMethodOptions,\n StructuredOutputMethodParams,\n} from \"../../language_models/base.js\";\nimport { BaseMessage, AIMessage } from \"../../messages/index.js\";\nimport type { ToolCall } from \"../../messages/tool.js\";\nimport type { ChatResult } from \"../../outputs.js\";\nimport { Runnable, RunnableLambda } from \"../../runnables/base.js\";\nimport { StructuredTool } from \"../../tools/index.js\";\nimport type { InteropZodType } from \"../types/zod.js\";\nimport type { ToolSpec } from \"./chat_models.js\";\n\ntype ResponseFactory = (messages: BaseMessage[]) => BaseMessage | Error;\n\ntype QueueEntry =\n | { kind: \"message\"; message: BaseMessage }\n | { kind: \"toolCalls\"; toolCalls: ToolCall[] }\n | { kind: \"error\"; error: Error }\n | { kind: \"factory\"; factory: ResponseFactory };\n\ninterface FakeModelCall {\n messages: BaseMessage[];\n options: any;\n}\n\nfunction deriveContent(messages: BaseMessage[]): string {\n return messages\n .map((m) => m.text)\n .filter(Boolean)\n .join(\"-\");\n}\n\nlet idCounter = 0;\nfunction nextToolCallId(): string {\n idCounter += 1;\n return `fake_tc_${idCounter}`;\n}\n\n/**\n * A fake chat model for testing, created via {@link fakeModel}.\n *\n * Queue responses with `.respond()` and `.respondWithTools()`, then\n * pass the instance directly wherever a chat model is expected.\n *\n * Each builder method queues a model response consumed in order per `invoke()`:\n *\n * `.respond(entry)` — enqueue a `BaseMessage`, `Error`, or factory function.\n *\n * `.respondWithTools(toolCalls[])` — enqueue an `AIMessage` with the given\n * tool calls. Content is derived from the input messages automatically.\n *\n * Both can be mixed freely in one chain. When all queued responses are\n * consumed, further invocations throw.\n *\n * Additional configuration:\n * - `.alwaysThrow(error)` — every call throws (overrides the queue)\n * - `.structuredResponse(value)` — value returned by `withStructuredOutput()`\n *\n * The model records all invocations in `.calls` / `.callCount`.\n */\nclass FakeBuiltModel extends BaseChatModel {\n private queue: QueueEntry[] = [];\n\n private _alwaysThrowError: Error | undefined;\n\n private _structuredResponseValue: any;\n\n private _tools: (StructuredTool | ToolSpec)[] = [];\n\n private _callIndex = 0;\n\n private _calls: FakeModelCall[] = [];\n\n get calls(): FakeModelCall[] {\n return this._calls;\n }\n\n get callCount(): number {\n return this._calls.length;\n }\n\n constructor() {\n super({});\n }\n\n _llmType(): string {\n return \"fake-model-builder\";\n }\n\n _combineLLMOutput() {\n return [];\n }\n\n respond(entry: BaseMessage | Error | ResponseFactory): this {\n if (typeof entry === \"function\") {\n this.queue.push({ kind: \"factory\", factory: entry });\n } else if (BaseMessage.isInstance(entry)) {\n this.queue.push({ kind: \"message\", message: entry });\n } else {\n this.queue.push({ kind: \"error\", error: entry });\n }\n return this;\n }\n\n respondWithTools(\n toolCalls: Array<{ name: string; args: Record<string, any>; id?: string }>\n ): this {\n this.queue.push({\n kind: \"toolCalls\",\n toolCalls: toolCalls.map((tc) => ({\n name: tc.name,\n args: tc.args,\n id: tc.id ?? nextToolCallId(),\n type: \"tool_call\" as const,\n })),\n });\n return this;\n }\n\n alwaysThrow(error: Error): this {\n this._alwaysThrowError = error;\n return this;\n }\n\n structuredResponse(value: Record<string, any>): this {\n this._structuredResponseValue = value;\n return this;\n }\n\n bindTools(tools: (StructuredTool | ToolSpec)[]) {\n const merged = [...this._tools, ...tools];\n const next = new FakeBuiltModel();\n next.queue = this.queue;\n next._alwaysThrowError = this._alwaysThrowError;\n next._structuredResponseValue = this._structuredResponseValue;\n next._tools = merged;\n next._calls = this._calls;\n next._callIndex = this._callIndex;\n\n return next.withConfig({} as BaseChatModelCallOptions);\n }\n\n withStructuredOutput<\n RunOutput extends Record<string, any> = Record<string, any>,\n >(\n _params:\n | StructuredOutputMethodParams<RunOutput, boolean>\n | InteropZodType<RunOutput>\n | Record<string, any>,\n _config?: StructuredOutputMethodOptions<boolean>\n ):\n | Runnable<BaseLanguageModelInput, RunOutput>\n | Runnable<\n BaseLanguageModelInput,\n { raw: BaseMessage; parsed: RunOutput }\n > {\n const { _structuredResponseValue } = this;\n return RunnableLambda.from(async () => {\n return _structuredResponseValue as RunOutput;\n }) as Runnable;\n }\n\n async _generate(\n messages: BaseMessage[],\n options?: this[\"ParsedCallOptions\"],\n _runManager?: CallbackManagerForLLMRun\n ): Promise<ChatResult> {\n this._calls.push({ messages: [...messages], options });\n\n const currentCallIndex = this._callIndex;\n this._callIndex += 1;\n\n if (this._alwaysThrowError) {\n throw this._alwaysThrowError;\n }\n\n const entry = this.queue[currentCallIndex];\n if (!entry) {\n throw new Error(\n `FakeModel: no response queued for invocation ${currentCallIndex} (${this.queue.length} total queued).`\n );\n }\n\n if (entry.kind === \"error\") {\n throw entry.error;\n }\n\n if (entry.kind === \"factory\") {\n const result = entry.factory(messages);\n if (!BaseMessage.isInstance(result)) {\n throw result;\n }\n return {\n generations: [{ text: \"\", message: result }],\n };\n }\n\n if (entry.kind === \"message\") {\n return {\n generations: [{ text: \"\", message: entry.message }],\n };\n }\n\n const content = deriveContent(messages);\n const message = new AIMessage({\n content,\n id: currentCallIndex.toString(),\n tool_calls:\n entry.toolCalls.length > 0\n ? entry.toolCalls.map((tc) => ({\n ...tc,\n type: \"tool_call\" as const,\n }))\n : undefined,\n });\n\n return {\n generations: [{ text: content, message }],\n llmOutput: {},\n };\n }\n}\n\n/**\n * Creates a fake chat model for testing.\n *\n * @example\n * ```typescript\n * const model = fakeModel()\n * .respondWithTools([{ name: \"search\", args: { query: \"weather\" } }])\n * .respond(new AIMessage(\"Sunny and warm.\"));\n *\n * const r1 = await model.invoke([new HumanMessage(\"What's the weather?\")]);\n * // r1.tool_calls[0].name === \"search\"\n *\n * const r2 = await model.invoke([new HumanMessage(\"Thanks\")]);\n * // r2.content === \"Sunny and warm.\"\n * ```\n */\nexport function fakeModel(): FakeBuiltModel {\n return new FakeBuiltModel();\n}\n"],"mappings":";;;;;;;AAgCA,SAAS,cAAc,UAAiC;AACtD,QAAO,SACJ,KAAK,MAAM,EAAE,KAAK,CAClB,OAAO,QAAQ,CACf,KAAK,IAAI;;AAGd,IAAI,YAAY;AAChB,SAAS,iBAAyB;AAChC,cAAa;AACb,QAAO,WAAW;;;;;;;;;;;;;;;;;;;;;;;;AAyBpB,IAAM,iBAAN,MAAM,uBAAuB,cAAc;CACzC,AAAQ,QAAsB,EAAE;CAEhC,AAAQ;CAER,AAAQ;CAER,AAAQ,SAAwC,EAAE;CAElD,AAAQ,aAAa;CAErB,AAAQ,SAA0B,EAAE;CAEpC,IAA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