@langchain/core 0.1.50 → 0.1.52

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.
@@ -2,6 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StructuredPrompt = void 0;
4
4
  const chat_js_1 = require("./chat.cjs");
5
+ function isWithStructuredOutput(x
6
+ // eslint-disable-next-line @typescript-eslint/ban-types
7
+ ) {
8
+ return (typeof x === "object" &&
9
+ x != null &&
10
+ "withStructuredOutput" in x &&
11
+ typeof x.withStructuredOutput === "function");
12
+ }
13
+ function isRunnableBinding(x) {
14
+ return (typeof x === "object" &&
15
+ x != null &&
16
+ "lc_id" in x &&
17
+ Array.isArray(x.lc_id) &&
18
+ x.lc_id.join("/") === "langchain_core/runnables/RunnableBinding");
19
+ }
5
20
  class StructuredPrompt extends chat_js_1.ChatPromptTemplate {
6
21
  get lc_aliases() {
7
22
  return {
@@ -18,17 +33,26 @@ class StructuredPrompt extends chat_js_1.ChatPromptTemplate {
18
33
  writable: true,
19
34
  value: void 0
20
35
  });
36
+ Object.defineProperty(this, "lc_namespace", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: ["langchain_core", "prompts", "structured"]
41
+ });
21
42
  this.schema = input.schema;
22
43
  }
23
44
  pipe(coerceable) {
24
- if (typeof coerceable === "object" &&
25
- "withStructuredOutput" in coerceable &&
26
- typeof coerceable.withStructuredOutput === "function") {
45
+ if (isWithStructuredOutput(coerceable)) {
27
46
  return super.pipe(coerceable.withStructuredOutput(this.schema));
28
47
  }
29
- else {
30
- throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
48
+ if (isRunnableBinding(coerceable) &&
49
+ isWithStructuredOutput(coerceable.bound)) {
50
+ return super.pipe(coerceable.bound
51
+ .withStructuredOutput(this.schema)
52
+ .bind(coerceable.kwargs ?? {})
53
+ .withConfig(coerceable.config));
31
54
  }
55
+ throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
32
56
  }
33
57
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
58
  static fromMessagesAndSchema(promptMessages, schema
@@ -11,6 +11,7 @@ export interface StructuredPromptInput<RunInput extends InputValues = any, Parti
11
11
  }
12
12
  export declare class StructuredPrompt<RunInput extends InputValues = any, PartialVariableName extends string = any> extends ChatPromptTemplate<RunInput, PartialVariableName> implements StructuredPromptInput<RunInput, PartialVariableName> {
13
13
  schema: Record<string, any>;
14
+ lc_namespace: string[];
14
15
  get lc_aliases(): Record<string, string>;
15
16
  constructor(input: StructuredPromptInput<RunInput, PartialVariableName>);
16
17
  pipe<NewRunOutput>(coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>): Runnable<RunInput, Exclude<NewRunOutput, Error>, RunnableConfig>;
@@ -1,4 +1,19 @@
1
1
  import { ChatPromptTemplate, } from "./chat.js";
2
+ function isWithStructuredOutput(x
3
+ // eslint-disable-next-line @typescript-eslint/ban-types
4
+ ) {
5
+ return (typeof x === "object" &&
6
+ x != null &&
7
+ "withStructuredOutput" in x &&
8
+ typeof x.withStructuredOutput === "function");
9
+ }
10
+ function isRunnableBinding(x) {
11
+ return (typeof x === "object" &&
12
+ x != null &&
13
+ "lc_id" in x &&
14
+ Array.isArray(x.lc_id) &&
15
+ x.lc_id.join("/") === "langchain_core/runnables/RunnableBinding");
16
+ }
2
17
  export class StructuredPrompt extends ChatPromptTemplate {
3
18
  get lc_aliases() {
4
19
  return {
@@ -15,17 +30,26 @@ export class StructuredPrompt extends ChatPromptTemplate {
15
30
  writable: true,
16
31
  value: void 0
17
32
  });
33
+ Object.defineProperty(this, "lc_namespace", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: ["langchain_core", "prompts", "structured"]
38
+ });
18
39
  this.schema = input.schema;
19
40
  }
20
41
  pipe(coerceable) {
21
- if (typeof coerceable === "object" &&
22
- "withStructuredOutput" in coerceable &&
23
- typeof coerceable.withStructuredOutput === "function") {
42
+ if (isWithStructuredOutput(coerceable)) {
24
43
  return super.pipe(coerceable.withStructuredOutput(this.schema));
25
44
  }
26
- else {
27
- throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
45
+ if (isRunnableBinding(coerceable) &&
46
+ isWithStructuredOutput(coerceable.bound)) {
47
+ return super.pipe(coerceable.bound
48
+ .withStructuredOutput(this.schema)
49
+ .bind(coerceable.kwargs ?? {})
50
+ .withConfig(coerceable.config));
28
51
  }
52
+ throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
29
53
  }
30
54
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
55
  static fromMessagesAndSchema(promptMessages, schema
@@ -165,16 +165,22 @@ class Runnable extends serializable_js_1.Serializable {
165
165
  await wrappedGenerator.setup;
166
166
  return stream_js_1.IterableReadableStream.fromAsyncGenerator(wrappedGenerator);
167
167
  }
168
- _separateRunnableConfigFromCallOptions(options = {}) {
169
- const runnableConfig = (0, config_js_1.ensureConfig)({
170
- callbacks: options.callbacks,
171
- tags: options.tags,
172
- metadata: options.metadata,
173
- runName: options.runName,
174
- configurable: options.configurable,
175
- recursionLimit: options.recursionLimit,
176
- maxConcurrency: options.maxConcurrency,
177
- });
168
+ _separateRunnableConfigFromCallOptions(options) {
169
+ let runnableConfig;
170
+ if (options === undefined) {
171
+ runnableConfig = (0, config_js_1.ensureConfig)(options);
172
+ }
173
+ else {
174
+ runnableConfig = (0, config_js_1.ensureConfig)({
175
+ callbacks: options.callbacks,
176
+ tags: options.tags,
177
+ metadata: options.metadata,
178
+ runName: options.runName,
179
+ configurable: options.configurable,
180
+ recursionLimit: options.recursionLimit,
181
+ maxConcurrency: options.maxConcurrency,
182
+ });
183
+ }
178
184
  const callOptions = { ...options };
179
185
  delete callOptions.callbacks;
180
186
  delete callOptions.tags;
@@ -232,7 +232,7 @@ export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends Ru
232
232
  lc_serializable: boolean;
233
233
  bound: Runnable<RunInput, RunOutput, CallOptions>;
234
234
  config: RunnableConfig;
235
- protected kwargs?: Partial<CallOptions>;
235
+ kwargs?: Partial<CallOptions>;
236
236
  configFactories?: Array<(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig>>;
237
237
  constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions>);
238
238
  getName(suffix?: string | undefined): string;
@@ -158,16 +158,22 @@ export class Runnable extends Serializable {
158
158
  await wrappedGenerator.setup;
159
159
  return IterableReadableStream.fromAsyncGenerator(wrappedGenerator);
160
160
  }
161
- _separateRunnableConfigFromCallOptions(options = {}) {
162
- const runnableConfig = ensureConfig({
163
- callbacks: options.callbacks,
164
- tags: options.tags,
165
- metadata: options.metadata,
166
- runName: options.runName,
167
- configurable: options.configurable,
168
- recursionLimit: options.recursionLimit,
169
- maxConcurrency: options.maxConcurrency,
170
- });
161
+ _separateRunnableConfigFromCallOptions(options) {
162
+ let runnableConfig;
163
+ if (options === undefined) {
164
+ runnableConfig = ensureConfig(options);
165
+ }
166
+ else {
167
+ runnableConfig = ensureConfig({
168
+ callbacks: options.callbacks,
169
+ tags: options.tags,
170
+ metadata: options.metadata,
171
+ runName: options.runName,
172
+ configurable: options.configurable,
173
+ recursionLimit: options.recursionLimit,
174
+ maxConcurrency: options.maxConcurrency,
175
+ });
176
+ }
171
177
  const callOptions = { ...options };
172
178
  delete callOptions.callbacks;
173
179
  delete callOptions.tags;
@@ -84,6 +84,9 @@ exports.mergeConfigs = mergeConfigs;
84
84
  const PRIMITIVES = new Set(["string", "number", "boolean"]);
85
85
  /**
86
86
  * Ensure that a passed config is an object with all required keys present.
87
+ *
88
+ * Note: To make sure async local storage loading works correctly, this
89
+ * should not be called with a default or prepopulated config argument.
87
90
  */
88
91
  function ensureConfig(config) {
89
92
  const loadedConfig = config ?? index_js_1.AsyncLocalStorageProviderSingleton.getInstance().getStore();
@@ -17,6 +17,9 @@ export declare function getCallbackManagerForConfig(config?: RunnableConfig): Pr
17
17
  export declare function mergeConfigs<CallOptions extends RunnableConfig>(...configs: (CallOptions | RunnableConfig | undefined | null)[]): Partial<CallOptions>;
18
18
  /**
19
19
  * Ensure that a passed config is an object with all required keys present.
20
+ *
21
+ * Note: To make sure async local storage loading works correctly, this
22
+ * should not be called with a default or prepopulated config argument.
20
23
  */
21
24
  export declare function ensureConfig<CallOptions extends RunnableConfig>(config?: CallOptions): CallOptions;
22
25
  /**
@@ -79,6 +79,9 @@ export function mergeConfigs(...configs) {
79
79
  const PRIMITIVES = new Set(["string", "number", "boolean"]);
80
80
  /**
81
81
  * Ensure that a passed config is an object with all required keys present.
82
+ *
83
+ * Note: To make sure async local storage loading works correctly, this
84
+ * should not be called with a default or prepopulated config argument.
82
85
  */
83
86
  export function ensureConfig(config) {
84
87
  const loadedConfig = config ?? AsyncLocalStorageProviderSingleton.getInstance().getStore();
@@ -410,7 +410,7 @@ class RemoteRunnable extends base_js_1.Runnable {
410
410
  yield {
411
411
  event: chunk.event,
412
412
  name: chunk.name,
413
- run_id: chunk.id,
413
+ run_id: chunk.run_id,
414
414
  tags: chunk.tags,
415
415
  metadata: chunk.metadata,
416
416
  data: chunk.data,
@@ -407,7 +407,7 @@ export class RemoteRunnable extends Runnable {
407
407
  yield {
408
408
  event: chunk.event,
409
409
  name: chunk.name,
410
- run_id: chunk.id,
410
+ run_id: chunk.run_id,
411
411
  tags: chunk.tags,
412
412
  metadata: chunk.metadata,
413
413
  data: chunk.data,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.1.50",
3
+ "version": "0.1.52",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {