@langchain/core 1.3.7 → 1.4.0

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.
@@ -0,0 +1,368 @@
1
+ import { BaseMessage } from "../messages/base.js";
2
+ import { UsageMetadata } from "../messages/metadata.js";
3
+ import * as z$1 from "zod/v4";
4
+ declare const jsonValueSchema: z$1.ZodJSONSchema;
5
+ /** Any value expressible in JSON. */
6
+ export type JsonValue = z$1.infer<typeof jsonValueSchema>;
7
+ declare const contentSchema: z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodRecord<z$1.ZodString, z$1.ZodJSONSchema>, z$1.ZodArray<z$1.ZodJSONSchema>]>;
8
+ /**
9
+ * Text, a JSON object, or a JSON array used in question instructions.
10
+ *
11
+ * As in `State`, LangChain standard media blocks may appear anywhere in
12
+ * instructions and criteria. Providers send them as media, or throw an error
13
+ * if their API does not accept that media in questions.
14
+ */
15
+ export type Content = z$1.infer<typeof contentSchema>;
16
+ /** A value allowed below the root of `State`. */
17
+ export type StateValue = string | number | boolean | null | BaseMessage | StateValue[] | {
18
+ [key: string]: StateValue;
19
+ };
20
+ /**
21
+ * Root state accepted by decision models.
22
+ *
23
+ * State is a string, JSON object, or JSON array. LangChain `BaseMessage` objects
24
+ * and message arrays can appear at the root or at any depth inside objects and
25
+ * arrays.
26
+ *
27
+ * LangChain standard media blocks (for example `{ type: "image", data: ...,
28
+ * mimeType: ... }`) may appear anywhere in the state. Each provider documents
29
+ * which media it supports and how it sends state its API cannot accept natively.
30
+ */
31
+ export type State = string | BaseMessage | StateValue[] | {
32
+ [key: string]: StateValue;
33
+ };
34
+ declare const noulCriteriaSchema: z$1.ZodObject<{
35
+ true: z$1.ZodOptional<z$1.ZodJSONSchema>;
36
+ false: z$1.ZodOptional<z$1.ZodJSONSchema>;
37
+ }, z$1.core.$strict>;
38
+ declare const noulSchema: z$1.ZodObject<{
39
+ type: z$1.ZodLiteral<"noul">;
40
+ instructions: z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodRecord<z$1.ZodString, z$1.ZodJSONSchema>, z$1.ZodArray<z$1.ZodJSONSchema>]>;
41
+ criteria: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodObject<{
42
+ true: z$1.ZodOptional<z$1.ZodJSONSchema>;
43
+ false: z$1.ZodOptional<z$1.ZodJSONSchema>;
44
+ }, z$1.core.$strict>>>;
45
+ }, z$1.core.$strict>;
46
+ declare const choiceSchema: z$1.ZodObject<{
47
+ type: z$1.ZodLiteral<"choice">;
48
+ criteria: z$1.ZodPipe<z$1.ZodCustom<Record<string, unknown>, Record<string, unknown>>, z$1.ZodTransform<Record<string, z$1.JSONType>, Record<string, unknown>>>;
49
+ instructions: z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodRecord<z$1.ZodString, z$1.ZodJSONSchema>, z$1.ZodArray<z$1.ZodJSONSchema>]>;
50
+ }, z$1.core.$strict>;
51
+ declare const scoreSchema: z$1.ZodObject<{
52
+ type: z$1.ZodLiteral<"score">;
53
+ criteria: z$1.ZodArray<z$1.ZodJSONSchema>;
54
+ instructions: z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodRecord<z$1.ZodString, z$1.ZodJSONSchema>, z$1.ZodArray<z$1.ZodJSONSchema>]>;
55
+ }, z$1.core.$strict>;
56
+ declare const boxSchema: z$1.ZodObject<{
57
+ type: z$1.ZodLiteral<"box">;
58
+ instructions: z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodRecord<z$1.ZodString, z$1.ZodJSONSchema>, z$1.ZodArray<z$1.ZodJSONSchema>]>;
59
+ }, z$1.core.$strict>;
60
+ declare const questionSchema: z$1.ZodDiscriminatedUnion<[z$1.ZodObject<{
61
+ type: z$1.ZodLiteral<"noul">;
62
+ instructions: z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodRecord<z$1.ZodString, z$1.ZodJSONSchema>, z$1.ZodArray<z$1.ZodJSONSchema>]>;
63
+ criteria: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodObject<{
64
+ true: z$1.ZodOptional<z$1.ZodJSONSchema>;
65
+ false: z$1.ZodOptional<z$1.ZodJSONSchema>;
66
+ }, z$1.core.$strict>>>;
67
+ }, z$1.core.$strict>, z$1.ZodObject<{
68
+ type: z$1.ZodLiteral<"choice">;
69
+ criteria: z$1.ZodPipe<z$1.ZodCustom<Record<string, unknown>, Record<string, unknown>>, z$1.ZodTransform<Record<string, z$1.JSONType>, Record<string, unknown>>>;
70
+ instructions: z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodRecord<z$1.ZodString, z$1.ZodJSONSchema>, z$1.ZodArray<z$1.ZodJSONSchema>]>;
71
+ }, z$1.core.$strict>, z$1.ZodObject<{
72
+ type: z$1.ZodLiteral<"score">;
73
+ criteria: z$1.ZodArray<z$1.ZodJSONSchema>;
74
+ instructions: z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodRecord<z$1.ZodString, z$1.ZodJSONSchema>, z$1.ZodArray<z$1.ZodJSONSchema>]>;
75
+ }, z$1.core.$strict>, z$1.ZodObject<{
76
+ type: z$1.ZodLiteral<"box">;
77
+ instructions: z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodRecord<z$1.ZodString, z$1.ZodJSONSchema>, z$1.ZodArray<z$1.ZodJSONSchema>]>;
78
+ }, z$1.core.$strict>], "type">;
79
+ /**
80
+ * Optional descriptions for the two outcomes of a `Noul` question.
81
+ *
82
+ * Criteria clarify what should count as yes and no when the instructions alone
83
+ * leave room for interpretation. Both values accept any JSON value, so callers
84
+ * can provide a short description or structured examples. The keys are
85
+ * literally `true` and `false`.
86
+ */
87
+ export type NoulCriteria = z$1.infer<typeof noulCriteriaSchema>;
88
+ /**
89
+ * Ask a binary question and receive the probability that its answer is yes.
90
+ *
91
+ * Use `Noul` when the probability itself is useful to application code, such as
92
+ * deciding whether a message reports a bug or requests a refund. A value near
93
+ * `1` indicates strong support for yes, near `0` strong support for no, and
94
+ * near `0.5` uncertainty. Noul answers have no separate confidence.
95
+ *
96
+ * Write the complete judgment in `instructions`, even when the question ID
97
+ * seems self-explanatory. Optional `criteria` define the yes and no outcomes.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * const response = await model.invoke({
102
+ * state: "Production is down. Please help immediately.",
103
+ * questions: {
104
+ * urgent: {
105
+ * type: "noul",
106
+ * instructions: "Does this message require an urgent response?",
107
+ * },
108
+ * },
109
+ * });
110
+ * if (response.nouls.urgent.noul >= 0.8) pageOnCallEngineer();
111
+ * ```
112
+ */
113
+ export type Noul = z$1.infer<typeof noulSchema>;
114
+ /**
115
+ * Select one label from a fixed set of alternatives.
116
+ *
117
+ * Use `Choice` for categorical decisions with no inherent ordering, such as
118
+ * routing a support request, detecting a document type, or selecting an
119
+ * intent. The answer includes the selected label, a probability for every
120
+ * supplied label, and a confidence value.
121
+ *
122
+ * `criteria` maps each label to its description, which may be text, JSON, or
123
+ * `null`. Include an `other` or `none_of_the_above` label when the alternatives
124
+ * may not cover every input.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * const response = await model.invoke({
129
+ * state: "Stripe fails whenever I connect my account.",
130
+ * questions: {
131
+ * department: {
132
+ * type: "choice",
133
+ * instructions: "Which team should handle this request?",
134
+ * criteria: {
135
+ * billing: "Payment, invoice, or subscription issues.",
136
+ * technical: "Product bugs or integration failures.",
137
+ * sales: "Pricing or purchasing questions.",
138
+ * },
139
+ * },
140
+ * },
141
+ * });
142
+ * const department = response.choices.department;
143
+ *
144
+ * if (department.confidence >= 0.7) {
145
+ * routeTo(department.choice);
146
+ * } else {
147
+ * routeToHumanTriage();
148
+ * }
149
+ * ```
150
+ */
151
+ export type Choice = z$1.infer<typeof choiceSchema>;
152
+ /**
153
+ * Evaluate state against an ordered rubric.
154
+ *
155
+ * Use `Score` when the answer lies on a spectrum whose levels can be described,
156
+ * such as severity, urgency, or customer frustration. `criteria` lists two or
157
+ * more levels, numbered from zero in their supplied order. The returned score
158
+ * is an expected value and may fall between integer levels; the full
159
+ * probability distribution remains available for custom decision logic.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * const response = await model.invoke({
164
+ * state: "This has failed three times. Fix it now.",
165
+ * questions: {
166
+ * frustration: {
167
+ * type: "score",
168
+ * instructions: "How frustrated does the customer appear?",
169
+ * criteria: [
170
+ * "Calm and neutral.",
171
+ * "Concerned but civil.",
172
+ * "Very angry or using strong language.",
173
+ * ],
174
+ * },
175
+ * },
176
+ * });
177
+ * const frustration = response.scores.frustration;
178
+ *
179
+ * frustration.score; // May be fractional, for example 1.35.
180
+ * frustration.legend; // The original zero-based rubric.
181
+ * frustration.probabilities; // Probability for each rubric level.
182
+ * ```
183
+ */
184
+ export type Score = z$1.infer<typeof scoreSchema>;
185
+ /**
186
+ * Locate what the instructions describe in an image in the state.
187
+ *
188
+ * The answer gives the edges of a box as fractions of the image height and
189
+ * width.
190
+ */
191
+ export type Box = z$1.infer<typeof boxSchema>;
192
+ /** A discriminated union of question types accepted by decision models. */
193
+ export type Question = z$1.infer<typeof questionSchema>;
194
+ /**
195
+ * Complete input for one decision model invocation.
196
+ *
197
+ * Keeping the state and questions in the runnable input ensures both values
198
+ * participate in composition, batching, and tracing.
199
+ */
200
+ export interface ClassifierRequest<Q extends Record<string, Question> = Record<string, Question>> {
201
+ /** Text, structured JSON, or LangChain messages to classify. */
202
+ state: State;
203
+ /** Non-empty map of answer IDs to typed classification questions. */
204
+ questions: Q;
205
+ }
206
+ declare const noulAnswerSchema: z$1.ZodObject<{
207
+ type: z$1.ZodLiteral<"noul">;
208
+ noul: z$1.ZodNumber;
209
+ }, z$1.core.$strip>;
210
+ declare const scoreAnswerSchema: z$1.ZodObject<{
211
+ type: z$1.ZodLiteral<"score">;
212
+ score: z$1.ZodNumber;
213
+ legend: z$1.ZodPipe<z$1.ZodCustom<Record<string, unknown>, Record<string, unknown>>, z$1.ZodTransform<Record<string, z$1.JSONType>, Record<string, unknown>>>;
214
+ probabilities: z$1.ZodPipe<z$1.ZodCustom<Record<string, unknown>, Record<string, unknown>>, z$1.ZodTransform<Record<string, number>, Record<string, unknown>>>;
215
+ confidence: z$1.ZodNumber;
216
+ }, z$1.core.$strip>;
217
+ declare const boxCoordinatesSchema: z$1.ZodObject<{
218
+ top: z$1.ZodNumber;
219
+ bottom: z$1.ZodNumber;
220
+ left: z$1.ZodNumber;
221
+ right: z$1.ZodNumber;
222
+ }, z$1.core.$strip>;
223
+ declare const boxAnswerSchema: z$1.ZodObject<{
224
+ type: z$1.ZodLiteral<"box">;
225
+ box: z$1.ZodObject<{
226
+ top: z$1.ZodNumber;
227
+ bottom: z$1.ZodNumber;
228
+ left: z$1.ZodNumber;
229
+ right: z$1.ZodNumber;
230
+ }, z$1.core.$strip>;
231
+ confidence: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>, z$1.ZodTransform<number | undefined, number | null | undefined>>;
232
+ }, z$1.core.$strip>;
233
+ /** Probability, from `0` to `1`, that a `Noul` question's answer is yes. */
234
+ export type NoulAnswer = z$1.infer<typeof noulAnswerSchema>;
235
+ /**
236
+ * Selected `Choice` label with its probability distribution and confidence.
237
+ *
238
+ * `choice` is one of the labels supplied in `Choice.criteria`. `probabilities`
239
+ * keeps the complete distribution, keyed by label, so applications can use a
240
+ * confidence measure or risk policy different from the provider's.
241
+ * `confidence` is the certainty from `0` to `1` in the selected label. Each
242
+ * provider documents how it derives it; choose thresholds according to the
243
+ * consequences of an incorrect automated decision.
244
+ */
245
+ export type ChoiceAnswer<K extends string = string> = {
246
+ type: "choice";
247
+ choice: K;
248
+ probabilities: Record<K, number>;
249
+ confidence: number;
250
+ };
251
+ /**
252
+ * Expected `Score` value with its rubric, distribution, and confidence.
253
+ *
254
+ * `score` is the expected position on the rubric and may be fractional, because
255
+ * it summarizes the distribution rather than selecting one level. `legend`
256
+ * holds the original rubric descriptions and `probabilities` the distribution,
257
+ * both keyed by zero-based level. `confidence`, from `0` to `1`, is derived
258
+ * from the level distribution.
259
+ *
260
+ * `legend` and `probabilities` are typed `Record<string, ...>` because JSON
261
+ * keys are strings; `legend[0]` still works.
262
+ */
263
+ export type ScoreAnswer = z$1.infer<typeof scoreAnswerSchema>;
264
+ /**
265
+ * Edges of a box as fractions of the image height and width, from `0` to `1`.
266
+ *
267
+ * `top` and `bottom` are measured from the top of the image, `left` and
268
+ * `right` from the left.
269
+ */
270
+ export type BoxCoordinates = z$1.infer<typeof boxCoordinatesSchema>;
271
+ /**
272
+ * Location of what a `Box` question describes.
273
+ *
274
+ * `confidence` is the certainty from `0` to `1`, or `undefined` when the
275
+ * provider does not report it.
276
+ */
277
+ export type BoxAnswer = z$1.infer<typeof boxAnswerSchema>;
278
+ /** A discriminated union of answers returned by decision models. */
279
+ export type Answer = NoulAnswer | ChoiceAnswer | ScoreAnswer | BoxAnswer;
280
+ /**
281
+ * The answer type a question produces. A `Choice` answer's `choice` is typed
282
+ * as one of the question's labels.
283
+ */
284
+ export type AnswerFor<T extends Question> = T extends {
285
+ type: "noul";
286
+ } ? NoulAnswer : T extends {
287
+ type: "choice";
288
+ criteria: infer C;
289
+ } ? ChoiceAnswer<Extract<keyof C, string>> : T extends {
290
+ type: "score";
291
+ } ? ScoreAnswer : T extends {
292
+ type: "box";
293
+ } ? BoxAnswer : never;
294
+ /** Answers keyed by question ID, typed from the questions that were asked. */
295
+ export type Answers<Q extends Record<string, Question>> = { -readonly [K in keyof Q]: AnswerFor<Q[K]>; };
296
+ type AnswersOfType<Q extends Record<string, Question>, T extends Question["type"]> = string extends keyof Q ? Record<string, AnswerFor<Extract<Question, {
297
+ type: T;
298
+ }>>> : { -readonly [K in keyof Q as Q[K] extends {
299
+ type: T;
300
+ } ? K : never]: AnswerFor<Q[K]>; };
301
+ /** Fields a provider supplies to build a `ClassifierResponse`. */
302
+ export interface ClassifierResponseFields {
303
+ /** Model that answered the request. */
304
+ model: string;
305
+ /** All answers keyed by their original question IDs. */
306
+ answers: Record<string, unknown>;
307
+ /**
308
+ * Token usage, or omitted when not reported. A missing count is treated as
309
+ * `0`, and `total_tokens` defaults to their sum.
310
+ */
311
+ usage_metadata?: Partial<UsageMetadata> | null;
312
+ /** Provider request ID, useful when diagnosing a request with provider support. */
313
+ requestId?: string | null;
314
+ }
315
+ /**
316
+ * Typed answers and metadata returned from one classification request.
317
+ *
318
+ * Read every answer from `answers`, or use `nouls`, `choices`, `scores`, and
319
+ * `boxes` for views filtered by answer type. Each map preserves the question
320
+ * IDs supplied in `ClassifierRequest.questions`. The views are non-enumerable
321
+ * so they are not duplicated into traces or `JSON.stringify` output.
322
+ *
323
+ * `Q` is the questions map that was asked. When it is known, answers and views
324
+ * are typed per question ID, and a `Choice` answer's `choice` is one of its
325
+ * labels.
326
+ */
327
+ export interface ClassifierResponse<Q extends Record<string, Question> = Record<string, Question>> {
328
+ /** Model that answered the request. */
329
+ model: string;
330
+ /** All answers keyed by their original question IDs. */
331
+ answers: Answers<Q>;
332
+ /**
333
+ * Token usage reported for the request, if any. A missing count is treated
334
+ * as `0`, and `total_tokens` defaults to their sum.
335
+ */
336
+ usage_metadata?: UsageMetadata;
337
+ /** Provider request ID, useful when diagnosing a request with provider support. */
338
+ requestId?: string;
339
+ /** Binary answers keyed by their original question IDs. */
340
+ readonly nouls: AnswersOfType<Q, "noul">;
341
+ /** Categorical answers keyed by their original question IDs. */
342
+ readonly choices: AnswersOfType<Q, "choice">;
343
+ /** Ordinal answers keyed by their original question IDs. */
344
+ readonly scores: AnswersOfType<Q, "score">;
345
+ /** Localization answers keyed by their original question IDs. */
346
+ readonly boxes: AnswersOfType<Q, "box">;
347
+ }
348
+ /**
349
+ * Validates a questions map.
350
+ *
351
+ * Every question must match its type's schema, including required
352
+ * `instructions` and each type's minimum number of options, and unknown keys
353
+ * are rejected. The map itself is returned unchanged.
354
+ *
355
+ * @throws Error naming the invalid question ID.
356
+ */
357
+ export declare function parseQuestions(questions: Record<string, Question>): Record<string, Question>;
358
+ /**
359
+ * Validates a provider's response and returns a `ClassifierResponse`.
360
+ *
361
+ * Unknown answer types are rejected; unknown fields are dropped. Partial usage
362
+ * is completed with zero counts and a summed `total_tokens`.
363
+ *
364
+ * @throws Error if the response does not match the expected shape.
365
+ */
366
+ export declare function parseClassifierResponse(fields: ClassifierResponseFields): ClassifierResponse;
367
+ export {};
368
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":["z"],"sources":["../../src/decisions/types.ts"],"mappings":";;;cAKM,iBAAeA,IAAA;;YAGT,YAAYA,IAAE,aAAa;cAEjC,eAAaA,IAAA,mBAAAA,IAAA,WAAAA,IAAA,UAAAA,IAAA,WAAAA,IAAA,gBAAAA,IAAA,SAAAA,IAAA;;;;;;;;YAaP,UAAUA,IAAE,aAAa;;YAGzB,gDAKR,cACA;GACG,cAAc;;;;;;;;;;;;;YAaT,iBAER,cACA;GACG,cAAc;;cA+Bf,oBAAkBA,IAAA;;;GAGtBA,IAAA,KAAA;cAEI,YAAUA,IAAA;;;;;;;GAIdA,IAAA,KAAA;cAEI,cAAYA,IAAA;;;;GAOhBA,IAAA,KAAA;cAEI,aAAWA,IAAA;;;;GAMfA,IAAA,KAAA;cAEI,WAASA,IAAA;;;GAGbA,IAAA,KAAA;cAEI,gBAAcA,IAAA,uBAAAA,IAAA;;;;;;;;;;;;;;;;;;GAKlBA,IAAA,KAAA;;;;;;;;;YAUU,eAAeA,IAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;YA2B9B,OAAOA,IAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAuCtB,SAASA,IAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAkCxB,QAAQA,IAAE,aAAa;;;;;;;YAQvB,MAAMA,IAAE,aAAa;;YAGrB,WAAWA,IAAE,aAAa;;;;;;;iBAQrB,kBACf,UAAU,eAAe,YAAY,eAAe;;EAGpD,OAAO;;EAEP,WAAW;;cAKP,kBAAgBA,IAAA;;;GAGpBA,IAAA,KAAA;cASI,mBAAiBA,IAAA;;;;;;GAMrBA,IAAA,KAAA;cAEI,sBAAoBA,IAAA;;;;;GAKxBA,IAAA,KAAA;cAEI,iBAAeA,IAAA;;;;;;;;;GAMnBA,IAAA,KAAA;;YAUU,aAAaA,IAAE,aAAa;;;;;;;;;;;YAY5B,aAAa;EACvB;EACA,QAAQ;EACR,eAAe,OAAO;EACtB;;;;;;;;;;;;;;YAeU,cAAcA,IAAE,aAAa;;;;;;;YAQ7B,iBAAiBA,IAAE,aAAa;;;;;;;YAQhC,YAAYA,IAAE,aAAa;;YAG3B,SAAS,aAAa,eAAe,cAAc;;;;;YAMnD,UAAU,UAAU,YAAY;EAAY;IACpD,aACA;EAAY;EAAgB,gBAAgB;IAC1C,aAAa,cAAc,cAC3B;EAAY;IACV,cACA;EAAY;IACV;;YAIE,QAAQ,UAAU,eAAe,0BAChC,WAAW,IAAI,UAAU,EAAE;KAGnC,cACH,UAAU,eAAe,WACzB,UAAU,yCACa,IACrB,eAAe,UAAU,QAAQ;EAAY,MAAM;oBAG/C,WAAW,KAAK,EAAE;EAAa,MAAM;IAAM,YAC1C,UAAU,EAAE;;iBAiCJ;;EAEf;;EAEA,SAAS;;;;;EAKT,iBAAiB,QAAQ;;EAEzB;;;;;;;;;;;;;;iBAee,mBACf,UAAU,eAAe,YAAY,eAAe;;EAGpD;;EAEA,SAAS,QAAQ;;;;;EAKjB,iBAAiB;;EAEjB;;WAES,OAAO,cAAc;;WAErB,SAAS,cAAc;;WAEvB,QAAQ,cAAc;;WAEtB,OAAO,cAAc;;;;;;;;;;;wBA4ChB,eACd,WAAW,eAAe,YACzB,eAAe;;;;;;;;;wBAmCF,wBACd,QAAQ,2BACP"}
@@ -0,0 +1,173 @@
1
+ import * as z$1 from "zod/v4";
2
+ // src/decisions/types.ts
3
+ const jsonValueSchema = z$1.json();
4
+ const contentSchema = z$1.union([
5
+ z$1.string(),
6
+ z$1.record(z$1.string(), jsonValueSchema),
7
+ z$1.array(jsonValueSchema)
8
+ ]);
9
+ const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
10
+ function recordOf(valueSchema) {
11
+ return z$1.custom(isPlainObject, "Expected an object.").transform((record, ctx) => {
12
+ const entries = [];
13
+ for (const [key, value] of Object.entries(record)) {
14
+ const result = valueSchema.safeParse(value);
15
+ if (result.success) entries.push([key, result.data]);
16
+ else for (const issue of result.error.issues) ctx.issues.push({
17
+ code: "custom",
18
+ message: issue.message,
19
+ input: value,
20
+ path: [key, ...issue.path]
21
+ });
22
+ }
23
+ return Object.fromEntries(entries);
24
+ });
25
+ }
26
+ const noulCriteriaSchema = z$1.strictObject({
27
+ true: jsonValueSchema.optional(),
28
+ false: jsonValueSchema.optional()
29
+ });
30
+ const noulSchema = z$1.strictObject({
31
+ type: z$1.literal("noul"),
32
+ instructions: contentSchema,
33
+ criteria: noulCriteriaSchema.nullish()
34
+ });
35
+ const choiceSchema = z$1.strictObject({
36
+ type: z$1.literal("choice"),
37
+ criteria: recordOf(jsonValueSchema).refine((criteria) => Object.keys(criteria).length >= 1, "Choice question must have at least 1 option."),
38
+ instructions: contentSchema
39
+ });
40
+ const scoreSchema = z$1.strictObject({
41
+ type: z$1.literal("score"),
42
+ criteria: z$1.array(jsonValueSchema).min(2, "Score question must have at least 2 ordered levels."),
43
+ instructions: contentSchema
44
+ });
45
+ const boxSchema = z$1.strictObject({
46
+ type: z$1.literal("box"),
47
+ instructions: contentSchema
48
+ });
49
+ const questionSchema = z$1.discriminatedUnion("type", [
50
+ noulSchema,
51
+ choiceSchema,
52
+ scoreSchema,
53
+ boxSchema
54
+ ]);
55
+ const probabilitySchema = z$1.number().min(0).max(1);
56
+ const noulAnswerSchema = z$1.object({
57
+ type: z$1.literal("noul"),
58
+ noul: probabilitySchema
59
+ });
60
+ const choiceAnswerSchema = z$1.object({
61
+ type: z$1.literal("choice"),
62
+ choice: z$1.string(),
63
+ probabilities: recordOf(z$1.number()),
64
+ confidence: probabilitySchema
65
+ });
66
+ const scoreAnswerSchema = z$1.object({
67
+ type: z$1.literal("score"),
68
+ score: z$1.number(),
69
+ legend: recordOf(jsonValueSchema),
70
+ probabilities: recordOf(z$1.number()),
71
+ confidence: probabilitySchema
72
+ });
73
+ const boxCoordinatesSchema = z$1.object({
74
+ top: z$1.number(),
75
+ bottom: z$1.number(),
76
+ left: z$1.number(),
77
+ right: z$1.number()
78
+ });
79
+ const boxAnswerSchema = z$1.object({
80
+ type: z$1.literal("box"),
81
+ box: boxCoordinatesSchema,
82
+ confidence: probabilitySchema.nullish().transform((value) => value ?? void 0)
83
+ });
84
+ const answerSchema = z$1.discriminatedUnion("type", [
85
+ noulAnswerSchema,
86
+ choiceAnswerSchema,
87
+ scoreAnswerSchema,
88
+ boxAnswerSchema
89
+ ]);
90
+ const usageSchema = z$1.looseObject({
91
+ input_tokens: z$1.number().nullish(),
92
+ output_tokens: z$1.number().nullish(),
93
+ total_tokens: z$1.number().nullish()
94
+ }).transform((usage) => {
95
+ const input_tokens = usage.input_tokens ?? 0;
96
+ const output_tokens = usage.output_tokens ?? 0;
97
+ return {
98
+ ...usage,
99
+ input_tokens,
100
+ output_tokens,
101
+ total_tokens: usage.total_tokens || input_tokens + output_tokens
102
+ };
103
+ });
104
+ const responseSchema = z$1.object({
105
+ model: z$1.string(),
106
+ answers: recordOf(answerSchema),
107
+ usage_metadata: usageSchema.nullish().transform((value) => value ?? void 0),
108
+ requestId: z$1.string().nullish().transform((value) => value ?? void 0)
109
+ });
110
+ function withAnswerViews(response) {
111
+ const define = (name, type) => {
112
+ Object.defineProperty(response, name, {
113
+ enumerable: false,
114
+ configurable: true,
115
+ get() {
116
+ return Object.fromEntries(Object.entries(response.answers).filter(([, answer]) => answer.type === type));
117
+ }
118
+ });
119
+ };
120
+ define("nouls", "noul");
121
+ define("choices", "choice");
122
+ define("scores", "score");
123
+ define("boxes", "box");
124
+ return response;
125
+ }
126
+ function describeIssue(issue) {
127
+ const path = issue.path.map(String).join(".");
128
+ const message = issue.code === "unrecognized_keys" ? "Unrecognized key." : issue.message;
129
+ return path ? `${path}: ${message}` : message;
130
+ }
131
+ /**
132
+ * Validates a questions map.
133
+ *
134
+ * Every question must match its type's schema, including required
135
+ * `instructions` and each type's minimum number of options, and unknown keys
136
+ * are rejected. The map itself is returned unchanged.
137
+ *
138
+ * @throws Error naming the invalid question ID.
139
+ */
140
+ function parseQuestions(questions) {
141
+ if (typeof questions !== "object" || questions === null || Array.isArray(questions) || Object.keys(questions).length === 0) throw new Error("Decision models require at least one question.");
142
+ for (const [id, question] of Object.entries(questions)) {
143
+ let result;
144
+ try {
145
+ result = questionSchema.safeParse(question);
146
+ } catch {
147
+ throw new Error(`Invalid question "${id}": content is too deeply nested or circular.`);
148
+ }
149
+ if (!result.success) throw new Error(`Invalid question "${id}": ${describeIssue(result.error.issues[0])}`);
150
+ }
151
+ return questions;
152
+ }
153
+ /**
154
+ * Validates a provider's response and returns a `ClassifierResponse`.
155
+ *
156
+ * Unknown answer types are rejected; unknown fields are dropped. Partial usage
157
+ * is completed with zero counts and a summed `total_tokens`.
158
+ *
159
+ * @throws Error if the response does not match the expected shape.
160
+ */
161
+ function parseClassifierResponse(fields) {
162
+ const result = responseSchema.safeParse(fields);
163
+ if (!result.success) throw new Error(`Invalid decision model response: ${describeIssue(result.error.issues[0])}`);
164
+ const { usage_metadata, requestId, ...rest } = result.data;
165
+ return withAnswerViews({
166
+ ...rest,
167
+ ...usage_metadata === void 0 ? {} : { usage_metadata },
168
+ ...requestId === void 0 ? {} : { requestId }
169
+ });
170
+ }
171
+ export { parseClassifierResponse, parseQuestions };
172
+
173
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":["z"],"sources":["../../src/decisions/types.ts"],"sourcesContent":["import * as z from \"zod/v4\";\n\nimport type { BaseMessage } from \"../messages/base.js\";\nimport type { UsageMetadata } from \"../messages/metadata.js\";\n\nconst jsonValueSchema = z.json();\n\n/** Any value expressible in JSON. */\nexport type JsonValue = z.infer<typeof jsonValueSchema>;\n\nconst contentSchema = z.union([\n z.string(),\n z.record(z.string(), jsonValueSchema),\n z.array(jsonValueSchema),\n]);\n\n/**\n * Text, a JSON object, or a JSON array used in question instructions.\n *\n * As in `State`, LangChain standard media blocks may appear anywhere in\n * instructions and criteria. Providers send them as media, or throw an error\n * if their API does not accept that media in questions.\n */\nexport type Content = z.infer<typeof contentSchema>;\n\n/** A value allowed below the root of `State`. */\nexport type StateValue =\n | string\n | number\n | boolean\n | null\n | BaseMessage\n | StateValue[]\n | { [key: string]: StateValue };\n\n/**\n * Root state accepted by decision models.\n *\n * State is a string, JSON object, or JSON array. LangChain `BaseMessage` objects\n * and message arrays can appear at the root or at any depth inside objects and\n * arrays.\n *\n * LangChain standard media blocks (for example `{ type: \"image\", data: ...,\n * mimeType: ... }`) may appear anywhere in the state. Each provider documents\n * which media it supports and how it sends state its API cannot accept natively.\n */\nexport type State =\n | string\n | BaseMessage\n | StateValue[]\n | { [key: string]: StateValue };\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n// Unlike `z.record`, keeps an own `__proto__` key, which can be a valid label\n// or question ID.\nfunction recordOf<T extends z.ZodType>(valueSchema: T) {\n return z\n .custom<Record<string, unknown>>(isPlainObject, \"Expected an object.\")\n .transform((record, ctx) => {\n const entries: [string, z.output<T>][] = [];\n for (const [key, value] of Object.entries(record)) {\n const result = valueSchema.safeParse(value);\n if (result.success) {\n entries.push([key, result.data]);\n } else {\n for (const issue of result.error.issues) {\n ctx.issues.push({\n code: \"custom\",\n message: issue.message,\n input: value,\n path: [key, ...issue.path],\n });\n }\n }\n }\n return Object.fromEntries(entries) as Record<string, z.output<T>>;\n });\n}\n\nconst noulCriteriaSchema = z.strictObject({\n true: jsonValueSchema.optional(),\n false: jsonValueSchema.optional(),\n});\n\nconst noulSchema = z.strictObject({\n type: z.literal(\"noul\"),\n instructions: contentSchema,\n criteria: noulCriteriaSchema.nullish(),\n});\n\nconst choiceSchema = z.strictObject({\n type: z.literal(\"choice\"),\n criteria: recordOf(jsonValueSchema).refine(\n (criteria) => Object.keys(criteria).length >= 1,\n \"Choice question must have at least 1 option.\"\n ),\n instructions: contentSchema,\n});\n\nconst scoreSchema = z.strictObject({\n type: z.literal(\"score\"),\n criteria: z\n .array(jsonValueSchema)\n .min(2, \"Score question must have at least 2 ordered levels.\"),\n instructions: contentSchema,\n});\n\nconst boxSchema = z.strictObject({\n type: z.literal(\"box\"),\n instructions: contentSchema,\n});\n\nconst questionSchema = z.discriminatedUnion(\"type\", [\n noulSchema,\n choiceSchema,\n scoreSchema,\n boxSchema,\n]);\n\n/**\n * Optional descriptions for the two outcomes of a `Noul` question.\n *\n * Criteria clarify what should count as yes and no when the instructions alone\n * leave room for interpretation. Both values accept any JSON value, so callers\n * can provide a short description or structured examples. The keys are\n * literally `true` and `false`.\n */\nexport type NoulCriteria = z.infer<typeof noulCriteriaSchema>;\n\n/**\n * Ask a binary question and receive the probability that its answer is yes.\n *\n * Use `Noul` when the probability itself is useful to application code, such as\n * deciding whether a message reports a bug or requests a refund. A value near\n * `1` indicates strong support for yes, near `0` strong support for no, and\n * near `0.5` uncertainty. Noul answers have no separate confidence.\n *\n * Write the complete judgment in `instructions`, even when the question ID\n * seems self-explanatory. Optional `criteria` define the yes and no outcomes.\n *\n * @example\n * ```ts\n * const response = await model.invoke({\n * state: \"Production is down. Please help immediately.\",\n * questions: {\n * urgent: {\n * type: \"noul\",\n * instructions: \"Does this message require an urgent response?\",\n * },\n * },\n * });\n * if (response.nouls.urgent.noul >= 0.8) pageOnCallEngineer();\n * ```\n */\nexport type Noul = z.infer<typeof noulSchema>;\n\n/**\n * Select one label from a fixed set of alternatives.\n *\n * Use `Choice` for categorical decisions with no inherent ordering, such as\n * routing a support request, detecting a document type, or selecting an\n * intent. The answer includes the selected label, a probability for every\n * supplied label, and a confidence value.\n *\n * `criteria` maps each label to its description, which may be text, JSON, or\n * `null`. Include an `other` or `none_of_the_above` label when the alternatives\n * may not cover every input.\n *\n * @example\n * ```ts\n * const response = await model.invoke({\n * state: \"Stripe fails whenever I connect my account.\",\n * questions: {\n * department: {\n * type: \"choice\",\n * instructions: \"Which team should handle this request?\",\n * criteria: {\n * billing: \"Payment, invoice, or subscription issues.\",\n * technical: \"Product bugs or integration failures.\",\n * sales: \"Pricing or purchasing questions.\",\n * },\n * },\n * },\n * });\n * const department = response.choices.department;\n *\n * if (department.confidence >= 0.7) {\n * routeTo(department.choice);\n * } else {\n * routeToHumanTriage();\n * }\n * ```\n */\nexport type Choice = z.infer<typeof choiceSchema>;\n\n/**\n * Evaluate state against an ordered rubric.\n *\n * Use `Score` when the answer lies on a spectrum whose levels can be described,\n * such as severity, urgency, or customer frustration. `criteria` lists two or\n * more levels, numbered from zero in their supplied order. The returned score\n * is an expected value and may fall between integer levels; the full\n * probability distribution remains available for custom decision logic.\n *\n * @example\n * ```ts\n * const response = await model.invoke({\n * state: \"This has failed three times. Fix it now.\",\n * questions: {\n * frustration: {\n * type: \"score\",\n * instructions: \"How frustrated does the customer appear?\",\n * criteria: [\n * \"Calm and neutral.\",\n * \"Concerned but civil.\",\n * \"Very angry or using strong language.\",\n * ],\n * },\n * },\n * });\n * const frustration = response.scores.frustration;\n *\n * frustration.score; // May be fractional, for example 1.35.\n * frustration.legend; // The original zero-based rubric.\n * frustration.probabilities; // Probability for each rubric level.\n * ```\n */\nexport type Score = z.infer<typeof scoreSchema>;\n\n/**\n * Locate what the instructions describe in an image in the state.\n *\n * The answer gives the edges of a box as fractions of the image height and\n * width.\n */\nexport type Box = z.infer<typeof boxSchema>;\n\n/** A discriminated union of question types accepted by decision models. */\nexport type Question = z.infer<typeof questionSchema>;\n\n/**\n * Complete input for one decision model invocation.\n *\n * Keeping the state and questions in the runnable input ensures both values\n * participate in composition, batching, and tracing.\n */\nexport interface ClassifierRequest<\n Q extends Record<string, Question> = Record<string, Question>,\n> {\n /** Text, structured JSON, or LangChain messages to classify. */\n state: State;\n /** Non-empty map of answer IDs to typed classification questions. */\n questions: Q;\n}\n\nconst probabilitySchema = z.number().min(0).max(1);\n\nconst noulAnswerSchema = z.object({\n type: z.literal(\"noul\"),\n noul: probabilitySchema,\n});\n\nconst choiceAnswerSchema = z.object({\n type: z.literal(\"choice\"),\n choice: z.string(),\n probabilities: recordOf(z.number()),\n confidence: probabilitySchema,\n});\n\nconst scoreAnswerSchema = z.object({\n type: z.literal(\"score\"),\n score: z.number(),\n legend: recordOf(jsonValueSchema),\n probabilities: recordOf(z.number()),\n confidence: probabilitySchema,\n});\n\nconst boxCoordinatesSchema = z.object({\n top: z.number(),\n bottom: z.number(),\n left: z.number(),\n right: z.number(),\n});\n\nconst boxAnswerSchema = z.object({\n type: z.literal(\"box\"),\n box: boxCoordinatesSchema,\n confidence: probabilitySchema\n .nullish()\n .transform((value) => value ?? undefined),\n});\n\nconst answerSchema = z.discriminatedUnion(\"type\", [\n noulAnswerSchema,\n choiceAnswerSchema,\n scoreAnswerSchema,\n boxAnswerSchema,\n]);\n\n/** Probability, from `0` to `1`, that a `Noul` question's answer is yes. */\nexport type NoulAnswer = z.infer<typeof noulAnswerSchema>;\n\n/**\n * Selected `Choice` label with its probability distribution and confidence.\n *\n * `choice` is one of the labels supplied in `Choice.criteria`. `probabilities`\n * keeps the complete distribution, keyed by label, so applications can use a\n * confidence measure or risk policy different from the provider's.\n * `confidence` is the certainty from `0` to `1` in the selected label. Each\n * provider documents how it derives it; choose thresholds according to the\n * consequences of an incorrect automated decision.\n */\nexport type ChoiceAnswer<K extends string = string> = {\n type: \"choice\";\n choice: K;\n probabilities: Record<K, number>;\n confidence: number;\n};\n\n/**\n * Expected `Score` value with its rubric, distribution, and confidence.\n *\n * `score` is the expected position on the rubric and may be fractional, because\n * it summarizes the distribution rather than selecting one level. `legend`\n * holds the original rubric descriptions and `probabilities` the distribution,\n * both keyed by zero-based level. `confidence`, from `0` to `1`, is derived\n * from the level distribution.\n *\n * `legend` and `probabilities` are typed `Record<string, ...>` because JSON\n * keys are strings; `legend[0]` still works.\n */\nexport type ScoreAnswer = z.infer<typeof scoreAnswerSchema>;\n\n/**\n * Edges of a box as fractions of the image height and width, from `0` to `1`.\n *\n * `top` and `bottom` are measured from the top of the image, `left` and\n * `right` from the left.\n */\nexport type BoxCoordinates = z.infer<typeof boxCoordinatesSchema>;\n\n/**\n * Location of what a `Box` question describes.\n *\n * `confidence` is the certainty from `0` to `1`, or `undefined` when the\n * provider does not report it.\n */\nexport type BoxAnswer = z.infer<typeof boxAnswerSchema>;\n\n/** A discriminated union of answers returned by decision models. */\nexport type Answer = NoulAnswer | ChoiceAnswer | ScoreAnswer | BoxAnswer;\n\n/**\n * The answer type a question produces. A `Choice` answer's `choice` is typed\n * as one of the question's labels.\n */\nexport type AnswerFor<T extends Question> = T extends { type: \"noul\" }\n ? NoulAnswer\n : T extends { type: \"choice\"; criteria: infer C }\n ? ChoiceAnswer<Extract<keyof C, string>>\n : T extends { type: \"score\" }\n ? ScoreAnswer\n : T extends { type: \"box\" }\n ? BoxAnswer\n : never;\n\n/** Answers keyed by question ID, typed from the questions that were asked. */\nexport type Answers<Q extends Record<string, Question>> = {\n -readonly [K in keyof Q]: AnswerFor<Q[K]>;\n};\n\ntype AnswersOfType<\n Q extends Record<string, Question>,\n T extends Question[\"type\"],\n> = string extends keyof Q\n ? Record<string, AnswerFor<Extract<Question, { type: T }>>>\n : {\n -readonly [\n K in keyof Q as Q[K] extends { type: T } ? K : never\n ]: AnswerFor<Q[K]>;\n };\n\nconst usageSchema = z\n .looseObject({\n input_tokens: z.number().nullish(),\n output_tokens: z.number().nullish(),\n total_tokens: z.number().nullish(),\n })\n .transform((usage) => {\n const input_tokens = usage.input_tokens ?? 0;\n const output_tokens = usage.output_tokens ?? 0;\n return {\n ...usage,\n input_tokens,\n output_tokens,\n total_tokens: usage.total_tokens || input_tokens + output_tokens,\n } as UsageMetadata;\n });\n\nconst responseSchema = z.object({\n model: z.string(),\n answers: recordOf(answerSchema),\n usage_metadata: usageSchema\n .nullish()\n .transform((value) => value ?? undefined),\n requestId: z\n .string()\n .nullish()\n .transform((value) => value ?? undefined),\n});\n\n/** Fields a provider supplies to build a `ClassifierResponse`. */\nexport interface ClassifierResponseFields {\n /** Model that answered the request. */\n model: string;\n /** All answers keyed by their original question IDs. */\n answers: Record<string, unknown>;\n /**\n * Token usage, or omitted when not reported. A missing count is treated as\n * `0`, and `total_tokens` defaults to their sum.\n */\n usage_metadata?: Partial<UsageMetadata> | null;\n /** Provider request ID, useful when diagnosing a request with provider support. */\n requestId?: string | null;\n}\n\n/**\n * Typed answers and metadata returned from one classification request.\n *\n * Read every answer from `answers`, or use `nouls`, `choices`, `scores`, and\n * `boxes` for views filtered by answer type. Each map preserves the question\n * IDs supplied in `ClassifierRequest.questions`. The views are non-enumerable\n * so they are not duplicated into traces or `JSON.stringify` output.\n *\n * `Q` is the questions map that was asked. When it is known, answers and views\n * are typed per question ID, and a `Choice` answer's `choice` is one of its\n * labels.\n */\nexport interface ClassifierResponse<\n Q extends Record<string, Question> = Record<string, Question>,\n> {\n /** Model that answered the request. */\n model: string;\n /** All answers keyed by their original question IDs. */\n answers: Answers<Q>;\n /**\n * Token usage reported for the request, if any. A missing count is treated\n * as `0`, and `total_tokens` defaults to their sum.\n */\n usage_metadata?: UsageMetadata;\n /** Provider request ID, useful when diagnosing a request with provider support. */\n requestId?: string;\n /** Binary answers keyed by their original question IDs. */\n readonly nouls: AnswersOfType<Q, \"noul\">;\n /** Categorical answers keyed by their original question IDs. */\n readonly choices: AnswersOfType<Q, \"choice\">;\n /** Ordinal answers keyed by their original question IDs. */\n readonly scores: AnswersOfType<Q, \"score\">;\n /** Localization answers keyed by their original question IDs. */\n readonly boxes: AnswersOfType<Q, \"box\">;\n}\n\nfunction withAnswerViews(\n response: Omit<ClassifierResponse, \"nouls\" | \"choices\" | \"scores\" | \"boxes\">\n): ClassifierResponse {\n const define = (name: string, type: Answer[\"type\"]) => {\n Object.defineProperty(response, name, {\n enumerable: false,\n configurable: true,\n get() {\n return Object.fromEntries(\n Object.entries(response.answers).filter(\n ([, answer]) => answer.type === type\n )\n );\n },\n });\n };\n define(\"nouls\", \"noul\");\n define(\"choices\", \"choice\");\n define(\"scores\", \"score\");\n define(\"boxes\", \"box\");\n return response as ClassifierResponse;\n}\n\n// Names the field path and the kind of problem, never the caller's values or\n// unknown key names, so the message is safe to log.\nfunction describeIssue(issue: z.core.$ZodIssue): string {\n const path = issue.path.map(String).join(\".\");\n const message =\n issue.code === \"unrecognized_keys\" ? \"Unrecognized key.\" : issue.message;\n return path ? `${path}: ${message}` : message;\n}\n\n/**\n * Validates a questions map.\n *\n * Every question must match its type's schema, including required\n * `instructions` and each type's minimum number of options, and unknown keys\n * are rejected. The map itself is returned unchanged.\n *\n * @throws Error naming the invalid question ID.\n */\nexport function parseQuestions(\n questions: Record<string, Question>\n): Record<string, Question> {\n if (\n typeof questions !== \"object\" ||\n questions === null ||\n Array.isArray(questions) ||\n Object.keys(questions).length === 0\n ) {\n throw new Error(\"Decision models require at least one question.\");\n }\n for (const [id, question] of Object.entries(questions)) {\n let result: ReturnType<typeof questionSchema.safeParse>;\n try {\n result = questionSchema.safeParse(question);\n } catch {\n throw new Error(\n `Invalid question \"${id}\": content is too deeply nested or circular.`\n );\n }\n if (!result.success) {\n throw new Error(\n `Invalid question \"${id}\": ${describeIssue(result.error.issues[0])}`\n );\n }\n }\n return questions;\n}\n\n/**\n * Validates a provider's response and returns a `ClassifierResponse`.\n *\n * Unknown answer types are rejected; unknown fields are dropped. Partial usage\n * is completed with zero counts and a summed `total_tokens`.\n *\n * @throws Error if the response does not match the expected shape.\n */\nexport function parseClassifierResponse(\n fields: ClassifierResponseFields\n): ClassifierResponse {\n const result = responseSchema.safeParse(fields);\n if (!result.success) {\n throw new Error(\n `Invalid decision model response: ${describeIssue(result.error.issues[0])}`\n );\n }\n const { usage_metadata, requestId, ...rest } = result.data;\n return withAnswerViews({\n ...rest,\n ...(usage_metadata === undefined ? {} : { usage_metadata }),\n ...(requestId === undefined ? {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AK,MAAM,CAAC,IAAI,aAAa,OAAO,QAAQ,SAAS,GAAG;EACtD,IAAI;EACJ,IAAI;GACF,SAAS,eAAe,UAAU,QAAQ;EAC5C,QAAQ;GACN,MAAM,IAAI,MACR,qBAAqB,GAAG,6CAC1B;EACF;EACA,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,MACR,qBAAqB,GAAG,KAAK,cAAc,OAAO,MAAM,OAAO,EAAE,GACnE;CAEJ;CACA,OAAO;AACT;;;;;;;;;AAUA,SAAgB,wBACd,QACoB;CACpB,MAAM,SAAS,eAAe,UAAU,MAAM;CAC9C,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,MACR,oCAAoC,cAAc,OAAO,MAAM,OAAO,EAAE,GAC1E;CAEF,MAAM,EAAE,gBAAgB,WAAW,GAAG,SAAS,OAAO;CACtD,OAAO,gBAAgB;EACrB,GAAG;EACH,GAAI,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe;EACzD,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU;CACjD,CAAC;AACH"}
@@ -139,7 +139,7 @@ var BaseLangChain = class extends require_base.Runnable {
139
139
  this.callbacks = params.callbacks;
140
140
  this.tags = params.tags ?? [];
141
141
  this.metadata = params.metadata ?? {};
142
- this._addVersion("@langchain/core", "1.3.7");
142
+ this._addVersion("@langchain/core", "1.4.0");
143
143
  }
144
144
  _addVersion(pkg, version) {
145
145
  const existing = this.metadata?.versions;
@@ -138,7 +138,7 @@ var BaseLangChain = class extends Runnable {
138
138
  this.callbacks = params.callbacks;
139
139
  this.tags = params.tags ?? [];
140
140
  this.metadata = params.metadata ?? {};
141
- this._addVersion("@langchain/core", "1.3.7");
141
+ this._addVersion("@langchain/core", "1.4.0");
142
142
  }
143
143
  _addVersion(pkg, version) {
144
144
  const existing = this.metadata?.versions;
@@ -5,6 +5,7 @@ const require_callbacks_base = require("../callbacks/base.cjs");
5
5
  const require_callbacks_manager = require("../callbacks/manager.cjs");
6
6
  const require_callbacks_promises = require("../callbacks/promises.cjs");
7
7
  const require_chat_history = require("../chat_history.cjs");
8
+ const require_decisions_index = require("../decisions/index.cjs");
8
9
  const require_document_loaders_base = require("../document_loaders/base.cjs");
9
10
  const require_document_loaders_langsmith = require("../document_loaders/langsmith.cjs");
10
11
  const require_documents_index = require("../documents/index.cjs");
@@ -75,6 +76,7 @@ var import_map_exports = /* @__PURE__ */ require_runtime.__exportAll({
75
76
  callbacks__manager: () => require_callbacks_manager.manager_exports,
76
77
  callbacks__promises: () => require_callbacks_promises.promises_exports,
77
78
  chat_history: () => require_chat_history.chat_history_exports,
79
+ decisions: () => require_decisions_index.decisions_exports,
78
80
  document_loaders__base: () => require_document_loaders_base.base_exports,
79
81
  document_loaders__langsmith: () => require_document_loaders_langsmith.langsmith_exports,
80
82
  documents: () => require_documents_index.documents_exports,
@@ -174,6 +176,12 @@ Object.defineProperty(exports, "chat_history", {
174
176
  return require_chat_history.chat_history_exports;
175
177
  }
176
178
  });
179
+ Object.defineProperty(exports, "decisions", {
180
+ enumerable: true,
181
+ get: function() {
182
+ return require_decisions_index.decisions_exports;
183
+ }
184
+ });
177
185
  Object.defineProperty(exports, "document_loaders__base", {
178
186
  enumerable: true,
179
187
  get: function() {