@langchain/core 0.3.13 → 0.3.14

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.
package/dist/memory.cjs CHANGED
@@ -41,7 +41,7 @@ exports.getInputValue = getInputValue;
41
41
  */
42
42
  const getOutputValue = (outputValues, outputKey) => {
43
43
  const value = getValue(outputValues, outputKey);
44
- if (!value) {
44
+ if (!value && value !== "") {
45
45
  const keys = Object.keys(outputValues);
46
46
  throw new Error(`output values have ${keys.length} keys, you must specify an output key or pass only 1 key as output`);
47
47
  }
package/dist/memory.js CHANGED
@@ -36,7 +36,7 @@ export const getInputValue = (inputValues, inputKey) => {
36
36
  */
37
37
  export const getOutputValue = (outputValues, outputKey) => {
38
38
  const value = getValue(outputValues, outputKey);
39
- if (!value) {
39
+ if (!value && value !== "") {
40
40
  const keys = Object.keys(outputValues);
41
41
  throw new Error(`output values have ${keys.length} keys, you must specify an output key or pass only 1 key as output`);
42
42
  }
@@ -1118,6 +1118,12 @@ class RunnableSequence extends Runnable {
1118
1118
  writable: true,
1119
1119
  value: void 0
1120
1120
  });
1121
+ Object.defineProperty(this, "omitSequenceTags", {
1122
+ enumerable: true,
1123
+ configurable: true,
1124
+ writable: true,
1125
+ value: false
1126
+ });
1121
1127
  Object.defineProperty(this, "lc_serializable", {
1122
1128
  enumerable: true,
1123
1129
  configurable: true,
@@ -1134,6 +1140,7 @@ class RunnableSequence extends Runnable {
1134
1140
  this.middle = fields.middle ?? this.middle;
1135
1141
  this.last = fields.last;
1136
1142
  this.name = fields.name;
1143
+ this.omitSequenceTags = fields.omitSequenceTags ?? this.omitSequenceTags;
1137
1144
  }
1138
1145
  get steps() {
1139
1146
  return [this.first, ...this.middle, this.last];
@@ -1150,7 +1157,7 @@ class RunnableSequence extends Runnable {
1150
1157
  for (let i = 0; i < initialSteps.length; i += 1) {
1151
1158
  const step = initialSteps[i];
1152
1159
  const promise = step.invoke(nextStepInput, (0, config_js_1.patchConfig)(config, {
1153
- callbacks: runManager?.getChild(`seq:step:${i + 1}`),
1160
+ callbacks: runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:${i + 1}`),
1154
1161
  }));
1155
1162
  nextStepInput = await (0, signal_js_1.raceWithSignal)(promise, options?.signal);
1156
1163
  }
@@ -1159,7 +1166,7 @@ class RunnableSequence extends Runnable {
1159
1166
  throw new Error("Aborted");
1160
1167
  }
1161
1168
  finalOutput = await this.last.invoke(nextStepInput, (0, config_js_1.patchConfig)(config, {
1162
- callbacks: runManager?.getChild(`seq:step:${this.steps.length}`),
1169
+ callbacks: runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:${this.steps.length}`),
1163
1170
  }));
1164
1171
  }
1165
1172
  catch (e) {
@@ -1183,7 +1190,7 @@ class RunnableSequence extends Runnable {
1183
1190
  for (let i = 0; i < this.steps.length; i += 1) {
1184
1191
  const step = this.steps[i];
1185
1192
  const promise = step.batch(nextStepInputs, runManagers.map((runManager, j) => {
1186
- const childRunManager = runManager?.getChild(`seq:step:${i + 1}`);
1193
+ const childRunManager = runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:${i + 1}`);
1187
1194
  return (0, config_js_1.patchConfig)(configList[j], { callbacks: childRunManager });
1188
1195
  }), batchOptions);
1189
1196
  nextStepInputs = await (0, signal_js_1.raceWithSignal)(promise, configList[0]?.signal);
@@ -1208,12 +1215,12 @@ class RunnableSequence extends Runnable {
1208
1215
  }
1209
1216
  try {
1210
1217
  let finalGenerator = steps[0].transform(inputGenerator(), (0, config_js_1.patchConfig)(otherOptions, {
1211
- callbacks: runManager?.getChild(`seq:step:1`),
1218
+ callbacks: runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:1`),
1212
1219
  }));
1213
1220
  for (let i = 1; i < steps.length; i += 1) {
1214
1221
  const step = steps[i];
1215
1222
  finalGenerator = await step.transform(finalGenerator, (0, config_js_1.patchConfig)(otherOptions, {
1216
- callbacks: runManager?.getChild(`seq:step:${i + 1}`),
1223
+ callbacks: runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:${i + 1}`),
1217
1224
  }));
1218
1225
  }
1219
1226
  for await (const chunk of finalGenerator) {
@@ -1293,12 +1300,19 @@ class RunnableSequence extends Runnable {
1293
1300
  return Array.isArray(thing.middle) && Runnable.isRunnable(thing);
1294
1301
  }
1295
1302
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1296
- static from([first, ...runnables], name) {
1303
+ static from([first, ...runnables], nameOrFields) {
1304
+ let extra = {};
1305
+ if (typeof nameOrFields === "string") {
1306
+ extra.name = nameOrFields;
1307
+ }
1308
+ else if (nameOrFields !== undefined) {
1309
+ extra = nameOrFields;
1310
+ }
1297
1311
  return new RunnableSequence({
1312
+ ...extra,
1298
1313
  first: _coerceToRunnable(first),
1299
1314
  middle: runnables.slice(0, -1).map(_coerceToRunnable),
1300
1315
  last: _coerceToRunnable(runnables[runnables.length - 1]),
1301
- name,
1302
1316
  });
1303
1317
  }
1304
1318
  }
@@ -455,6 +455,13 @@ export declare class RunnableRetry<RunInput = any, RunOutput = any, CallOptions
455
455
  }): Promise<(RunOutput | Error)[]>;
456
456
  batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
457
457
  }
458
+ export type RunnableSequenceFields<RunInput, RunOutput> = {
459
+ first: Runnable<RunInput>;
460
+ middle?: Runnable[];
461
+ last: Runnable<any, RunOutput>;
462
+ name?: string;
463
+ omitSequenceTags?: boolean;
464
+ };
458
465
  /**
459
466
  * A sequence of runnables, where the output of each is the input of the next.
460
467
  * @example
@@ -471,14 +478,10 @@ export declare class RunnableSequence<RunInput = any, RunOutput = any> extends R
471
478
  protected first: Runnable<RunInput>;
472
479
  protected middle: Runnable[];
473
480
  protected last: Runnable<any, RunOutput>;
481
+ omitSequenceTags: boolean;
474
482
  lc_serializable: boolean;
475
483
  lc_namespace: string[];
476
- constructor(fields: {
477
- first: Runnable<RunInput>;
478
- middle?: Runnable[];
479
- last: Runnable<any, RunOutput>;
480
- name?: string;
481
- });
484
+ constructor(fields: RunnableSequenceFields<RunInput, RunOutput>);
482
485
  get steps(): Runnable<any, any, RunnableConfig<Record<string, any>>>[];
483
486
  invoke(input: RunInput, options?: RunnableConfig): Promise<RunOutput>;
484
487
  batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
@@ -496,7 +499,7 @@ export declare class RunnableSequence<RunInput = any, RunOutput = any> extends R
496
499
  RunnableLike<RunInput>,
497
500
  ...RunnableLike[],
498
501
  RunnableLike<any, RunOutput>
499
- ], name?: string): RunnableSequence<RunInput, Exclude<RunOutput, Error>>;
502
+ ], nameOrFields?: string | Omit<RunnableSequenceFields<RunInput, RunOutput>, "first" | "middle" | "last">): RunnableSequence<RunInput, Exclude<RunOutput, Error>>;
500
503
  }
501
504
  /**
502
505
  * A runnable that runs a mapping of runnables in parallel,
@@ -1107,6 +1107,12 @@ export class RunnableSequence extends Runnable {
1107
1107
  writable: true,
1108
1108
  value: void 0
1109
1109
  });
1110
+ Object.defineProperty(this, "omitSequenceTags", {
1111
+ enumerable: true,
1112
+ configurable: true,
1113
+ writable: true,
1114
+ value: false
1115
+ });
1110
1116
  Object.defineProperty(this, "lc_serializable", {
1111
1117
  enumerable: true,
1112
1118
  configurable: true,
@@ -1123,6 +1129,7 @@ export class RunnableSequence extends Runnable {
1123
1129
  this.middle = fields.middle ?? this.middle;
1124
1130
  this.last = fields.last;
1125
1131
  this.name = fields.name;
1132
+ this.omitSequenceTags = fields.omitSequenceTags ?? this.omitSequenceTags;
1126
1133
  }
1127
1134
  get steps() {
1128
1135
  return [this.first, ...this.middle, this.last];
@@ -1139,7 +1146,7 @@ export class RunnableSequence extends Runnable {
1139
1146
  for (let i = 0; i < initialSteps.length; i += 1) {
1140
1147
  const step = initialSteps[i];
1141
1148
  const promise = step.invoke(nextStepInput, patchConfig(config, {
1142
- callbacks: runManager?.getChild(`seq:step:${i + 1}`),
1149
+ callbacks: runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:${i + 1}`),
1143
1150
  }));
1144
1151
  nextStepInput = await raceWithSignal(promise, options?.signal);
1145
1152
  }
@@ -1148,7 +1155,7 @@ export class RunnableSequence extends Runnable {
1148
1155
  throw new Error("Aborted");
1149
1156
  }
1150
1157
  finalOutput = await this.last.invoke(nextStepInput, patchConfig(config, {
1151
- callbacks: runManager?.getChild(`seq:step:${this.steps.length}`),
1158
+ callbacks: runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:${this.steps.length}`),
1152
1159
  }));
1153
1160
  }
1154
1161
  catch (e) {
@@ -1172,7 +1179,7 @@ export class RunnableSequence extends Runnable {
1172
1179
  for (let i = 0; i < this.steps.length; i += 1) {
1173
1180
  const step = this.steps[i];
1174
1181
  const promise = step.batch(nextStepInputs, runManagers.map((runManager, j) => {
1175
- const childRunManager = runManager?.getChild(`seq:step:${i + 1}`);
1182
+ const childRunManager = runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:${i + 1}`);
1176
1183
  return patchConfig(configList[j], { callbacks: childRunManager });
1177
1184
  }), batchOptions);
1178
1185
  nextStepInputs = await raceWithSignal(promise, configList[0]?.signal);
@@ -1197,12 +1204,12 @@ export class RunnableSequence extends Runnable {
1197
1204
  }
1198
1205
  try {
1199
1206
  let finalGenerator = steps[0].transform(inputGenerator(), patchConfig(otherOptions, {
1200
- callbacks: runManager?.getChild(`seq:step:1`),
1207
+ callbacks: runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:1`),
1201
1208
  }));
1202
1209
  for (let i = 1; i < steps.length; i += 1) {
1203
1210
  const step = steps[i];
1204
1211
  finalGenerator = await step.transform(finalGenerator, patchConfig(otherOptions, {
1205
- callbacks: runManager?.getChild(`seq:step:${i + 1}`),
1212
+ callbacks: runManager?.getChild(this.omitSequenceTags ? undefined : `seq:step:${i + 1}`),
1206
1213
  }));
1207
1214
  }
1208
1215
  for await (const chunk of finalGenerator) {
@@ -1282,12 +1289,19 @@ export class RunnableSequence extends Runnable {
1282
1289
  return Array.isArray(thing.middle) && Runnable.isRunnable(thing);
1283
1290
  }
1284
1291
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1285
- static from([first, ...runnables], name) {
1292
+ static from([first, ...runnables], nameOrFields) {
1293
+ let extra = {};
1294
+ if (typeof nameOrFields === "string") {
1295
+ extra.name = nameOrFields;
1296
+ }
1297
+ else if (nameOrFields !== undefined) {
1298
+ extra = nameOrFields;
1299
+ }
1286
1300
  return new RunnableSequence({
1301
+ ...extra,
1287
1302
  first: _coerceToRunnable(first),
1288
1303
  middle: runnables.slice(0, -1).map(_coerceToRunnable),
1289
1304
  last: _coerceToRunnable(runnables[runnables.length - 1]),
1290
- name,
1291
1305
  });
1292
1306
  }
1293
1307
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {