typia 12.0.0-dev.20260307 → 12.0.0-dev.20260309

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,2 @@
1
+ import { ILlmSchema } from "@typia/interface";
2
+ export declare const _coerceLlmArguments: <T>(value: unknown, parameters: ILlmSchema.IParameters) => T;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._coerceLlmArguments = void 0;
4
+ const utils_1 = require("@typia/utils");
5
+ const _coerceLlmArguments = (value, parameters) => utils_1.LlmJson.coerce(value, parameters);
6
+ exports._coerceLlmArguments = _coerceLlmArguments;
7
+ //# sourceMappingURL=_coerceLlmArguments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_coerceLlmArguments.js","sourceRoot":"","sources":["../../src/internal/_coerceLlmArguments.ts"],"names":[],"mappings":";;;AACA,wCAAuC;AAEhC,MAAM,mBAAmB,GAAG,CACjC,KAAc,EACd,UAAkC,EAC/B,EAAE,CAAC,eAAO,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AAH7B,QAAA,mBAAmB,uBAGU"}
@@ -0,0 +1,6 @@
1
+ import { LlmJson } from '@typia/utils';
2
+
3
+ const _coerceLlmArguments = (value, parameters) => LlmJson.coerce(value, parameters);
4
+
5
+ export { _coerceLlmArguments };
6
+ //# sourceMappingURL=_coerceLlmArguments.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_coerceLlmArguments.mjs","sources":["../../src/internal/_coerceLlmArguments.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGO,MAAM,mBAAmB,GAAG,CACjC,KAAc,EACd,UAAkC,KAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU;;;;"}
@@ -6,7 +6,7 @@ const _llmApplicationFinalize = (app, config) => {
6
6
  var _a;
7
7
  return (Object.assign(Object.assign({}, app), { config: Object.assign(Object.assign({}, utils_1.LlmSchemaConverter.getConfig()), { validate: (_a = config === null || config === void 0 ? void 0 : config.validate) !== null && _a !== void 0 ? _a : null }), functions: app.functions.map((func) => {
8
8
  var _a, _b;
9
- return (Object.assign(Object.assign({}, func), { parse: (input) => utils_1.LlmJson.parse(input, func.parameters), validate: (_b = (_a = config === null || config === void 0 ? void 0 : config.validate) === null || _a === void 0 ? void 0 : _a[func.name]) !== null && _b !== void 0 ? _b : func.validate }));
9
+ return (Object.assign(Object.assign({}, func), { parse: (input) => utils_1.LlmJson.parse(input, func.parameters), coerce: (input) => utils_1.LlmJson.coerce(input, func.parameters), validate: (_b = (_a = config === null || config === void 0 ? void 0 : config.validate) === null || _a === void 0 ? void 0 : _a[func.name]) !== null && _b !== void 0 ? _b : func.validate }));
10
10
  }) }));
11
11
  };
12
12
  exports._llmApplicationFinalize = _llmApplicationFinalize;
@@ -1 +1 @@
1
- {"version":3,"file":"_llmApplicationFinalize.js","sourceRoot":"","sources":["../../src/internal/_llmApplicationFinalize.ts"],"names":[],"mappings":";;;AACA,wCAA2D;AAEpD,MAAM,uBAAuB,GAAG,CACrC,GAAwC,EACxC,MAIC,EACuB,EAAE;;IAAC,OAAA,iCACxB,GAAG,KACN,MAAM,kCACD,0BAAkB,CAAC,SAAS,EAAE,KACjC,QAAQ,EAAE,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,mCAAI,IAAI,KAEpC,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;;YAAC,OAAA,iCAClC,IAAI,KACP,KAAK,EAAE,CAAC,KAAa,EAA6B,EAAE,CAClD,eAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EACvC,QAAQ,EAAE,MAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,0CAAG,IAAI,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC,QAAQ,IACxD,CAAA;SAAA,CAAC,IACH,CAAA;CAAA,CAAC;AAnBU,QAAA,uBAAuB,2BAmBjC"}
1
+ {"version":3,"file":"_llmApplicationFinalize.js","sourceRoot":"","sources":["../../src/internal/_llmApplicationFinalize.ts"],"names":[],"mappings":";;;AACA,wCAA2D;AAEpD,MAAM,uBAAuB,GAAG,CACrC,GAAwC,EACxC,MAIC,EACuB,EAAE;;IAAC,OAAA,iCACxB,GAAG,KACN,MAAM,kCACD,0BAAkB,CAAC,SAAS,EAAE,KACjC,QAAQ,EAAE,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,mCAAI,IAAI,KAEpC,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;;YAAC,OAAA,iCAClC,IAAI,KACP,KAAK,EAAE,CAAC,KAAa,EAA6B,EAAE,CAClD,eAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EACvC,MAAM,EAAE,CAAC,KAAc,EAAW,EAAE,CAAC,eAAO,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EAC3E,QAAQ,EAAE,MAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,0CAAG,IAAI,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC,QAAQ,IACxD,CAAA;SAAA,CAAC,IACH,CAAA;CAAA,CAAC;AApBU,QAAA,uBAAuB,2BAoBjC"}
@@ -9,6 +9,7 @@ const _llmApplicationFinalize = (app, config) => ({
9
9
  functions: app.functions.map((func) => ({
10
10
  ...func,
11
11
  parse: (input) => LlmJson.parse(input, func.parameters),
12
+ coerce: (input) => LlmJson.coerce(input, func.parameters),
12
13
  validate: config?.validate?.[func.name] ?? func.validate,
13
14
  })),
14
15
  });
@@ -1 +1 @@
1
- {"version":3,"file":"_llmApplicationFinalize.mjs","sources":["../../src/internal/_llmApplicationFinalize.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGO,MAAM,uBAAuB,GAAG,CACrC,GAAwC,EACxC,MAIC,MAC2B;AAC5B,IAAA,GAAG,GAAG;AACN,IAAA,MAAM,EAAE;QACN,GAAG,kBAAkB,CAAC,SAAS,EAAE;AACjC,QAAA,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,IAAI;AACnC,KAAA;AACD,IAAA,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,MAAM;AACtC,QAAA,GAAG,IAAI;AACP,QAAA,KAAK,EAAE,CAAC,KAAa,KACnB,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC;AACvC,QAAA,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ;AACzD,KAAA,CAAC,CAAC;AACJ,CAAA;;;;"}
1
+ {"version":3,"file":"_llmApplicationFinalize.mjs","sources":["../../src/internal/_llmApplicationFinalize.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGO,MAAM,uBAAuB,GAAG,CACrC,GAAwC,EACxC,MAIC,MAC2B;AAC5B,IAAA,GAAG,GAAG;AACN,IAAA,MAAM,EAAE;QACN,GAAG,kBAAkB,CAAC,SAAS,EAAE;AACjC,QAAA,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,IAAI;AACnC,KAAA;AACD,IAAA,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,MAAM;AACtC,QAAA,GAAG,IAAI;AACP,QAAA,KAAK,EAAE,CAAC,KAAa,KACnB,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC;AACvC,QAAA,MAAM,EAAE,CAAC,KAAc,KAAc,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC;AAC3E,QAAA,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ;AACzD,KAAA,CAAC,CAAC;AACJ,CAAA;;;;"}
@@ -0,0 +1,2 @@
1
+ import { IJsonParseResult, ILlmSchema } from "@typia/interface";
2
+ export declare const _parseLlmArguments: <T>(input: string, parameters: ILlmSchema.IParameters) => IJsonParseResult<T>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._parseLlmArguments = void 0;
4
+ const utils_1 = require("@typia/utils");
5
+ const _parseLlmArguments = (input, parameters) => utils_1.LlmJson.parse(input, parameters);
6
+ exports._parseLlmArguments = _parseLlmArguments;
7
+ //# sourceMappingURL=_parseLlmArguments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_parseLlmArguments.js","sourceRoot":"","sources":["../../src/internal/_parseLlmArguments.ts"],"names":[],"mappings":";;;AACA,wCAAuC;AAEhC,MAAM,kBAAkB,GAAG,CAChC,KAAa,EACb,UAAkC,EACb,EAAE,CAAC,eAAO,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AAH9C,QAAA,kBAAkB,sBAG4B"}
@@ -0,0 +1,6 @@
1
+ import { LlmJson } from '@typia/utils';
2
+
3
+ const _parseLlmArguments = (input, parameters) => LlmJson.parse(input, parameters);
4
+
5
+ export { _parseLlmArguments };
6
+ //# sourceMappingURL=_parseLlmArguments.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_parseLlmArguments.mjs","sources":["../../src/internal/_parseLlmArguments.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGO,MAAM,kBAAkB,GAAG,CAChC,KAAa,EACb,UAAkC,KACV,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU;;;;"}
package/lib/llm.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILlmApplication, ILlmController, ILlmSchema } from "@typia/interface";
1
+ import { IJsonParseResult, ILlmApplication, ILlmController, ILlmSchema } from "@typia/interface";
2
2
  /**
3
3
  * Creates LLM function calling controller.
4
4
  *
@@ -152,3 +152,156 @@ export declare function schema(): never;
152
152
  * @returns LLM type schema
153
153
  */
154
154
  export declare function schema<T, Config extends Partial<ILlmSchema.IConfig> = {}>($defs: Record<string, ILlmSchema>): ILlmSchema;
155
+ /**
156
+ * Parse LLM response JSON with type coercion.
157
+ *
158
+ * @danger You must configure the generic argument `Parameters`
159
+ */
160
+ export declare function parse(input: string): never;
161
+ /**
162
+ * Parse lenient JSON with schema-based type coercion.
163
+ *
164
+ * Handles incomplete or malformed JSON commonly produced by LLMs:
165
+ *
166
+ * - Unclosed brackets, strings, trailing commas
167
+ * - JavaScript-style comments (`//` and multi-line)
168
+ * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
169
+ * - Markdown code block extraction, junk prefix skipping
170
+ *
171
+ * Also coerces double-stringified values based on the `Parameters` schema:
172
+ *
173
+ * - `"42"` → `42` (when schema expects number)
174
+ * - `"true"` → `true` (when schema expects boolean)
175
+ * - `"null"` → `null` (when schema expects null)
176
+ * - `"{...}"` → `{...}` (when schema expects object)
177
+ * - `"[...]"` → `[...]` (when schema expects array)
178
+ *
179
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
180
+ * `typia.validate()` for that.
181
+ *
182
+ * For repeated parsing, use {@link createParse} to avoid regenerating the schema
183
+ * each time.
184
+ *
185
+ * Related functions:
186
+ *
187
+ * - {@link createParse} — Create reusable parser function
188
+ * - {@link coerce} — Type coercion for already-parsed objects
189
+ * - {@link parameters} — Generate parameters schema from type
190
+ *
191
+ * @template Parameters Target parameters type (object with static properties)
192
+ * @template Config LLM schema configuration
193
+ * @param input Raw JSON string (potentially incomplete or malformed)
194
+ * @returns Parse result with typed data on success, or partial data with errors
195
+ */
196
+ export declare function parse<Parameters extends Record<string, any>, Config extends Partial<ILlmSchema.IConfig> = {}>(input: string): IJsonParseResult<Parameters>;
197
+ /**
198
+ * Coerce LLM arguments to match expected schema types.
199
+ *
200
+ * LLMs often return values with incorrect types (e.g., numbers as strings).
201
+ * This function recursively coerces values based on the `Parameters` schema:
202
+ *
203
+ * - `"42"` → `42` (when schema expects number)
204
+ * - `"true"` → `true` (when schema expects boolean)
205
+ * - `"null"` → `null` (when schema expects null)
206
+ * - `"{...}"` → `{...}` (when schema expects object)
207
+ * - `"[...]"` → `[...]` (when schema expects array)
208
+ *
209
+ * Use this when your SDK provides already-parsed objects but values may have
210
+ * wrong types. For raw JSON strings, use {@link parse} instead.
211
+ *
212
+ * For repeated coercion, use {@link createCoerce} to avoid regenerating the
213
+ * schema each time.
214
+ *
215
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
216
+ * `typia.validate()` for that.
217
+ *
218
+ * Related functions:
219
+ *
220
+ * - {@link createCoerce} — Create reusable coercer function
221
+ * - {@link parse} — Parse and coerce raw JSON strings
222
+ * - {@link parameters} — Generate parameters schema from type
223
+ *
224
+ * @template Parameters Target parameters type (object with static properties)
225
+ * @template Config LLM schema configuration
226
+ * @param input Parsed arguments object from LLM (with potentially wrong types)
227
+ * @returns Coerced arguments with corrected types
228
+ */
229
+ export declare function coerce<Parameters extends Record<string, any>, Config extends Partial<ILlmSchema.IConfig> = {}>(input: Parameters): Parameters;
230
+ /**
231
+ * Create reusable LLM JSON parser with type coercion.
232
+ *
233
+ * @danger You must configure the generic argument `Parameters`
234
+ */
235
+ export declare function createParse(): never;
236
+ /**
237
+ * Create reusable lenient JSON parser with schema-based type coercion.
238
+ *
239
+ * Returns a parser function that handles incomplete or malformed JSON commonly
240
+ * produced by LLMs:
241
+ *
242
+ * - Unclosed brackets, strings, trailing commas
243
+ * - JavaScript-style comments (`//` and multi-line)
244
+ * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
245
+ * - Markdown code block extraction, junk prefix skipping
246
+ *
247
+ * Also coerces double-stringified values based on the `Parameters` schema:
248
+ *
249
+ * - `"42"` → `42` (when schema expects number)
250
+ * - `"true"` → `true` (when schema expects boolean)
251
+ * - `"null"` → `null` (when schema expects null)
252
+ * - `"{...}"` → `{...}` (when schema expects object)
253
+ * - `"[...]"` → `[...]` (when schema expects array)
254
+ *
255
+ * Use this instead of {@link parse} when parsing multiple inputs to avoid
256
+ * regenerating the schema each time.
257
+ *
258
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
259
+ * `typia.validate()` for that.
260
+ *
261
+ * Related functions:
262
+ *
263
+ * - {@link parse} — One-shot parsing (regenerates schema each call)
264
+ * - {@link createCoerce} — Create reusable coercer function
265
+ * - {@link parameters} — Generate parameters schema from type
266
+ *
267
+ * @template Parameters Target parameters type (object with static properties)
268
+ * @template Config LLM schema configuration
269
+ * @returns Reusable parser function
270
+ */
271
+ export declare function createParse<Parameters extends Record<string, any>, Config extends Partial<ILlmSchema.IConfig> = {}>(): (input: string) => IJsonParseResult<Parameters>;
272
+ /**
273
+ * Create reusable LLM arguments coercer.
274
+ *
275
+ * @danger You must configure the generic argument `Parameters`
276
+ */
277
+ export declare function createCoerce(): never;
278
+ /**
279
+ * Create reusable coercer for LLM arguments.
280
+ *
281
+ * Returns a coercer function that fixes incorrect types commonly returned by
282
+ * LLMs (e.g., numbers as strings). Coerces values based on the `Parameters`
283
+ * schema:
284
+ *
285
+ * - `"42"` → `42` (when schema expects number)
286
+ * - `"true"` → `true` (when schema expects boolean)
287
+ * - `"null"` → `null` (when schema expects null)
288
+ * - `"{...}"` → `{...}` (when schema expects object)
289
+ * - `"[...]"` → `[...]` (when schema expects array)
290
+ *
291
+ * Use this instead of {@link coerce} when coercing multiple inputs to avoid
292
+ * regenerating the schema each time.
293
+ *
294
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
295
+ * `typia.validate()` for that.
296
+ *
297
+ * Related functions:
298
+ *
299
+ * - {@link coerce} — One-shot coercion (regenerates schema each call)
300
+ * - {@link createParse} — Create reusable parser function
301
+ * - {@link parameters} — Generate parameters schema from type
302
+ *
303
+ * @template Parameters Target parameters type (object with static properties)
304
+ * @template Config LLM schema configuration
305
+ * @returns Reusable coercer function
306
+ */
307
+ export declare function createCoerce<Parameters extends Record<string, any>, Config extends Partial<ILlmSchema.IConfig> = {}>(): (input: Parameters) => Parameters;
package/lib/llm.js CHANGED
@@ -4,6 +4,10 @@ exports.controller = controller;
4
4
  exports.application = application;
5
5
  exports.parameters = parameters;
6
6
  exports.schema = schema;
7
+ exports.parse = parse;
8
+ exports.coerce = coerce;
9
+ exports.createParse = createParse;
10
+ exports.createCoerce = createCoerce;
7
11
  const NoTransformConfigurationError_1 = require("./transformers/NoTransformConfigurationError");
8
12
  /** @internal */
9
13
  function controller(..._args) {
@@ -21,4 +25,20 @@ function parameters() {
21
25
  function schema() {
22
26
  (0, NoTransformConfigurationError_1.NoTransformConfigurationError)("llm.schema");
23
27
  }
28
+ /** @internal */
29
+ function parse() {
30
+ (0, NoTransformConfigurationError_1.NoTransformConfigurationError)("llm.parse");
31
+ }
32
+ /** @internal */
33
+ function coerce() {
34
+ (0, NoTransformConfigurationError_1.NoTransformConfigurationError)("llm.coerce");
35
+ }
36
+ /** @internal */
37
+ function createParse() {
38
+ (0, NoTransformConfigurationError_1.NoTransformConfigurationError)("llm.createParse");
39
+ }
40
+ /** @internal */
41
+ function createCoerce() {
42
+ (0, NoTransformConfigurationError_1.NoTransformConfigurationError)("llm.createCoerce");
43
+ }
24
44
  //# sourceMappingURL=llm.js.map
package/lib/llm.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"llm.js","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":";;AAmEA,gCAEC;AA2DD,kCAEC;AAqCD,gCAEC;AAuCD,wBAEC;AAhND,gGAA6F;AAgE7F,gBAAgB;AAChB,SAAgB,UAAU,CAAC,GAAG,KAAY;IACxC,IAAA,6DAA6B,EAAC,gBAAgB,CAAC,CAAC;AAClD,CAAC;AA0DD,gBAAgB;AAChB,SAAgB,WAAW;IACzB,IAAA,6DAA6B,EAAC,iBAAiB,CAAC,CAAC;AACnD,CAAC;AAoCD,gBAAgB;AAChB,SAAgB,UAAU;IACxB,IAAA,6DAA6B,EAAC,gBAAgB,CAAC,CAAC;AAClD,CAAC;AAsCD,gBAAgB;AAChB,SAAgB,MAAM;IACpB,IAAA,6DAA6B,EAAC,YAAY,CAAC,CAAC;AAC9C,CAAC"}
1
+ {"version":3,"file":"llm.js","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":";;AAwEA,gCAEC;AA2DD,kCAEC;AAqCD,gCAEC;AAuCD,wBAEC;AAkDD,sBAEC;AAwCD,wBAEC;AAkDD,kCAEC;AA4CD,oCAEC;AAhZD,gGAA6F;AAgE7F,gBAAgB;AAChB,SAAgB,UAAU,CAAC,GAAG,KAAY;IACxC,IAAA,6DAA6B,EAAC,gBAAgB,CAAC,CAAC;AAClD,CAAC;AA0DD,gBAAgB;AAChB,SAAgB,WAAW;IACzB,IAAA,6DAA6B,EAAC,iBAAiB,CAAC,CAAC;AACnD,CAAC;AAoCD,gBAAgB;AAChB,SAAgB,UAAU;IACxB,IAAA,6DAA6B,EAAC,gBAAgB,CAAC,CAAC;AAClD,CAAC;AAsCD,gBAAgB;AAChB,SAAgB,MAAM;IACpB,IAAA,6DAA6B,EAAC,YAAY,CAAC,CAAC;AAC9C,CAAC;AAiDD,gBAAgB;AAChB,SAAgB,KAAK;IACnB,IAAA,6DAA6B,EAAC,WAAW,CAAC,CAAC;AAC7C,CAAC;AAuCD,gBAAgB;AAChB,SAAgB,MAAM;IACpB,IAAA,6DAA6B,EAAC,YAAY,CAAC,CAAC;AAC9C,CAAC;AAiDD,gBAAgB;AAChB,SAAgB,WAAW;IACzB,IAAA,6DAA6B,EAAC,iBAAiB,CAAC,CAAC;AACnD,CAAC;AA2CD,gBAAgB;AAChB,SAAgB,YAAY;IAC1B,IAAA,6DAA6B,EAAC,kBAAkB,CAAC,CAAC;AACpD,CAAC"}
package/lib/llm.mjs CHANGED
@@ -16,6 +16,22 @@ function parameters() {
16
16
  function schema() {
17
17
  NoTransformConfigurationError("llm.schema");
18
18
  }
19
+ /** @internal */
20
+ function parse() {
21
+ NoTransformConfigurationError("llm.parse");
22
+ }
23
+ /** @internal */
24
+ function coerce() {
25
+ NoTransformConfigurationError("llm.coerce");
26
+ }
27
+ /** @internal */
28
+ function createParse() {
29
+ NoTransformConfigurationError("llm.createParse");
30
+ }
31
+ /** @internal */
32
+ function createCoerce() {
33
+ NoTransformConfigurationError("llm.createCoerce");
34
+ }
19
35
 
20
- export { application, controller, parameters, schema };
36
+ export { application, coerce, controller, createCoerce, createParse, parameters, parse, schema };
21
37
  //# sourceMappingURL=llm.mjs.map
package/lib/llm.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"llm.mjs","sources":["../src/llm.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAkEA;AACM,SAAU,UAAU,CAAC,GAAG,KAAY,EAAA;IACxC,6BAA6B,CAAC,gBAAgB,CAAC;AACjD;AA0DA;SACgB,WAAW,GAAA;IACzB,6BAA6B,CAAC,iBAAiB,CAAC;AAClD;AAoCA;SACgB,UAAU,GAAA;IACxB,6BAA6B,CAAC,gBAAgB,CAAC;AACjD;AAsCA;SACgB,MAAM,GAAA;IACpB,6BAA6B,CAAC,YAAY,CAAC;AAC7C;;;;"}
1
+ {"version":3,"file":"llm.mjs","sources":["../src/llm.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAuEA;AACM,SAAU,UAAU,CAAC,GAAG,KAAY,EAAA;IACxC,6BAA6B,CAAC,gBAAgB,CAAC;AACjD;AA0DA;SACgB,WAAW,GAAA;IACzB,6BAA6B,CAAC,iBAAiB,CAAC;AAClD;AAoCA;SACgB,UAAU,GAAA;IACxB,6BAA6B,CAAC,gBAAgB,CAAC;AACjD;AAsCA;SACgB,MAAM,GAAA;IACpB,6BAA6B,CAAC,YAAY,CAAC;AAC7C;AAiDA;SACgB,KAAK,GAAA;IACnB,6BAA6B,CAAC,WAAW,CAAC;AAC5C;AAuCA;SACgB,MAAM,GAAA;IACpB,6BAA6B,CAAC,YAAY,CAAC;AAC7C;AAiDA;SACgB,WAAW,GAAA;IACzB,6BAA6B,CAAC,iBAAiB,CAAC;AAClD;AA2CA;SACgB,YAAY,GAAA;IAC1B,6BAA6B,CAAC,kBAAkB,CAAC;AACnD;;;;"}
@@ -1 +1 @@
1
- export { AssertionGuard, IValidation, IRandomGenerator, OpenApi, IJsonSchemaCollection, IJsonSchemaUnit, ILlmController, ILlmApplication, ILlmFunction, ILlmSchema, IMetadataSchema, IMetadataSchemaCollection, IMetadataSchemaUnit, IMetadataComponents, IMetadataTypeTag, IJsDocTagInfo, Primitive, Resolved, CamelCase, PascalCase, SnakeCase, IReadableURLSearchParams, tags, } from "@typia/interface";
1
+ export { AssertionGuard, IJsonParseResult, IValidation, IRandomGenerator, OpenApi, IJsonSchemaCollection, IJsonSchemaUnit, ILlmController, ILlmApplication, ILlmFunction, ILlmSchema, IMetadataSchema, IMetadataSchemaCollection, IMetadataSchemaUnit, IMetadataComponents, IMetadataTypeTag, IJsDocTagInfo, Primitive, Resolved, CamelCase, PascalCase, SnakeCase, IReadableURLSearchParams, tags, } from "@typia/interface";
@@ -1 +1 @@
1
- {"version":3,"file":"re-exports.js","sourceRoot":"","sources":["../src/re-exports.ts"],"names":[],"mappings":";;;AAAA,8CA+B0B;AAFxB,aAAa;AACb,iGAAA,IAAI,OAAA"}
1
+ {"version":3,"file":"re-exports.js","sourceRoot":"","sources":["../src/re-exports.ts"],"names":[],"mappings":";;;AAAA,8CAgC0B;AAFxB,aAAa;AACb,iGAAA,IAAI,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typia",
3
- "version": "12.0.0-dev.20260307",
3
+ "version": "12.0.0-dev.20260309",
4
4
  "description": "Superfast runtime validators with only one line",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -50,10 +50,10 @@
50
50
  "inquirer": "^8.2.5",
51
51
  "package-manager-detector": "^0.2.0",
52
52
  "randexp": "^0.5.3",
53
- "@typia/core": "^12.0.0-dev.20260307",
54
- "@typia/interface": "^12.0.0-dev.20260307",
55
- "@typia/transform": "^12.0.0-dev.20260307",
56
- "@typia/utils": "^12.0.0-dev.20260307"
53
+ "@typia/interface": "^12.0.0-dev.20260309",
54
+ "@typia/utils": "^12.0.0-dev.20260309",
55
+ "@typia/transform": "^12.0.0-dev.20260309",
56
+ "@typia/core": "^12.0.0-dev.20260309"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "typescript": ">=4.8.0 <5.10.0"
@@ -0,0 +1,7 @@
1
+ import { ILlmSchema } from "@typia/interface";
2
+ import { LlmJson } from "@typia/utils";
3
+
4
+ export const _coerceLlmArguments = <T>(
5
+ value: unknown,
6
+ parameters: ILlmSchema.IParameters,
7
+ ): T => LlmJson.coerce(value, parameters);
@@ -18,6 +18,7 @@ export const _llmApplicationFinalize = <Class extends object = any>(
18
18
  ...func,
19
19
  parse: (input: string): IJsonParseResult<unknown> =>
20
20
  LlmJson.parse(input, func.parameters),
21
+ coerce: (input: unknown): unknown => LlmJson.coerce(input, func.parameters),
21
22
  validate: config?.validate?.[func.name] ?? func.validate,
22
23
  })),
23
24
  });
@@ -0,0 +1,7 @@
1
+ import { IJsonParseResult, ILlmSchema } from "@typia/interface";
2
+ import { LlmJson } from "@typia/utils";
3
+
4
+ export const _parseLlmArguments = <T>(
5
+ input: string,
6
+ parameters: ILlmSchema.IParameters,
7
+ ): IJsonParseResult<T> => LlmJson.parse(input, parameters);
package/src/llm.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { ILlmApplication, ILlmController, ILlmSchema } from "@typia/interface";
1
+ import {
2
+ IJsonParseResult,
3
+ ILlmApplication,
4
+ ILlmController,
5
+ ILlmSchema,
6
+ } from "@typia/interface";
2
7
 
3
8
  import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
4
9
 
@@ -209,3 +214,195 @@ export function schema<T, Config extends Partial<ILlmSchema.IConfig> = {}>(
209
214
  export function schema(): never {
210
215
  NoTransformConfigurationError("llm.schema");
211
216
  }
217
+
218
+ /**
219
+ * Parse LLM response JSON with type coercion.
220
+ *
221
+ * @danger You must configure the generic argument `Parameters`
222
+ */
223
+ export function parse(input: string): never;
224
+
225
+ /**
226
+ * Parse lenient JSON with schema-based type coercion.
227
+ *
228
+ * Handles incomplete or malformed JSON commonly produced by LLMs:
229
+ *
230
+ * - Unclosed brackets, strings, trailing commas
231
+ * - JavaScript-style comments (`//` and multi-line)
232
+ * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
233
+ * - Markdown code block extraction, junk prefix skipping
234
+ *
235
+ * Also coerces double-stringified values based on the `Parameters` schema:
236
+ *
237
+ * - `"42"` → `42` (when schema expects number)
238
+ * - `"true"` → `true` (when schema expects boolean)
239
+ * - `"null"` → `null` (when schema expects null)
240
+ * - `"{...}"` → `{...}` (when schema expects object)
241
+ * - `"[...]"` → `[...]` (when schema expects array)
242
+ *
243
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
244
+ * `typia.validate()` for that.
245
+ *
246
+ * For repeated parsing, use {@link createParse} to avoid regenerating the schema
247
+ * each time.
248
+ *
249
+ * Related functions:
250
+ *
251
+ * - {@link createParse} — Create reusable parser function
252
+ * - {@link coerce} — Type coercion for already-parsed objects
253
+ * - {@link parameters} — Generate parameters schema from type
254
+ *
255
+ * @template Parameters Target parameters type (object with static properties)
256
+ * @template Config LLM schema configuration
257
+ * @param input Raw JSON string (potentially incomplete or malformed)
258
+ * @returns Parse result with typed data on success, or partial data with errors
259
+ */
260
+ export function parse<
261
+ Parameters extends Record<string, any>,
262
+ Config extends Partial<ILlmSchema.IConfig> = {},
263
+ >(input: string): IJsonParseResult<Parameters>;
264
+
265
+ /** @internal */
266
+ export function parse(): never {
267
+ NoTransformConfigurationError("llm.parse");
268
+ }
269
+
270
+ /**
271
+ * Coerce LLM arguments to match expected schema types.
272
+ *
273
+ * LLMs often return values with incorrect types (e.g., numbers as strings).
274
+ * This function recursively coerces values based on the `Parameters` schema:
275
+ *
276
+ * - `"42"` → `42` (when schema expects number)
277
+ * - `"true"` → `true` (when schema expects boolean)
278
+ * - `"null"` → `null` (when schema expects null)
279
+ * - `"{...}"` → `{...}` (when schema expects object)
280
+ * - `"[...]"` → `[...]` (when schema expects array)
281
+ *
282
+ * Use this when your SDK provides already-parsed objects but values may have
283
+ * wrong types. For raw JSON strings, use {@link parse} instead.
284
+ *
285
+ * For repeated coercion, use {@link createCoerce} to avoid regenerating the
286
+ * schema each time.
287
+ *
288
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
289
+ * `typia.validate()` for that.
290
+ *
291
+ * Related functions:
292
+ *
293
+ * - {@link createCoerce} — Create reusable coercer function
294
+ * - {@link parse} — Parse and coerce raw JSON strings
295
+ * - {@link parameters} — Generate parameters schema from type
296
+ *
297
+ * @template Parameters Target parameters type (object with static properties)
298
+ * @template Config LLM schema configuration
299
+ * @param input Parsed arguments object from LLM (with potentially wrong types)
300
+ * @returns Coerced arguments with corrected types
301
+ */
302
+ export function coerce<
303
+ Parameters extends Record<string, any>,
304
+ Config extends Partial<ILlmSchema.IConfig> = {},
305
+ >(input: Parameters): Parameters;
306
+
307
+ /** @internal */
308
+ export function coerce(): never {
309
+ NoTransformConfigurationError("llm.coerce");
310
+ }
311
+
312
+ /**
313
+ * Create reusable LLM JSON parser with type coercion.
314
+ *
315
+ * @danger You must configure the generic argument `Parameters`
316
+ */
317
+ export function createParse(): never;
318
+
319
+ /**
320
+ * Create reusable lenient JSON parser with schema-based type coercion.
321
+ *
322
+ * Returns a parser function that handles incomplete or malformed JSON commonly
323
+ * produced by LLMs:
324
+ *
325
+ * - Unclosed brackets, strings, trailing commas
326
+ * - JavaScript-style comments (`//` and multi-line)
327
+ * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
328
+ * - Markdown code block extraction, junk prefix skipping
329
+ *
330
+ * Also coerces double-stringified values based on the `Parameters` schema:
331
+ *
332
+ * - `"42"` → `42` (when schema expects number)
333
+ * - `"true"` → `true` (when schema expects boolean)
334
+ * - `"null"` → `null` (when schema expects null)
335
+ * - `"{...}"` → `{...}` (when schema expects object)
336
+ * - `"[...]"` → `[...]` (when schema expects array)
337
+ *
338
+ * Use this instead of {@link parse} when parsing multiple inputs to avoid
339
+ * regenerating the schema each time.
340
+ *
341
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
342
+ * `typia.validate()` for that.
343
+ *
344
+ * Related functions:
345
+ *
346
+ * - {@link parse} — One-shot parsing (regenerates schema each call)
347
+ * - {@link createCoerce} — Create reusable coercer function
348
+ * - {@link parameters} — Generate parameters schema from type
349
+ *
350
+ * @template Parameters Target parameters type (object with static properties)
351
+ * @template Config LLM schema configuration
352
+ * @returns Reusable parser function
353
+ */
354
+ export function createParse<
355
+ Parameters extends Record<string, any>,
356
+ Config extends Partial<ILlmSchema.IConfig> = {},
357
+ >(): (input: string) => IJsonParseResult<Parameters>;
358
+
359
+ /** @internal */
360
+ export function createParse(): never {
361
+ NoTransformConfigurationError("llm.createParse");
362
+ }
363
+
364
+ /**
365
+ * Create reusable LLM arguments coercer.
366
+ *
367
+ * @danger You must configure the generic argument `Parameters`
368
+ */
369
+ export function createCoerce(): never;
370
+
371
+ /**
372
+ * Create reusable coercer for LLM arguments.
373
+ *
374
+ * Returns a coercer function that fixes incorrect types commonly returned by
375
+ * LLMs (e.g., numbers as strings). Coerces values based on the `Parameters`
376
+ * schema:
377
+ *
378
+ * - `"42"` → `42` (when schema expects number)
379
+ * - `"true"` → `true` (when schema expects boolean)
380
+ * - `"null"` → `null` (when schema expects null)
381
+ * - `"{...}"` → `{...}` (when schema expects object)
382
+ * - `"[...]"` → `[...]` (when schema expects array)
383
+ *
384
+ * Use this instead of {@link coerce} when coercing multiple inputs to avoid
385
+ * regenerating the schema each time.
386
+ *
387
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
388
+ * `typia.validate()` for that.
389
+ *
390
+ * Related functions:
391
+ *
392
+ * - {@link coerce} — One-shot coercion (regenerates schema each call)
393
+ * - {@link createParse} — Create reusable parser function
394
+ * - {@link parameters} — Generate parameters schema from type
395
+ *
396
+ * @template Parameters Target parameters type (object with static properties)
397
+ * @template Config LLM schema configuration
398
+ * @returns Reusable coercer function
399
+ */
400
+ export function createCoerce<
401
+ Parameters extends Record<string, any>,
402
+ Config extends Partial<ILlmSchema.IConfig> = {},
403
+ >(): (input: Parameters) => Parameters;
404
+
405
+ /** @internal */
406
+ export function createCoerce(): never {
407
+ NoTransformConfigurationError("llm.createCoerce");
408
+ }
package/src/re-exports.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export {
2
2
  // validate
3
3
  AssertionGuard,
4
+ IJsonParseResult,
4
5
  IValidation,
5
6
  IRandomGenerator,
6
7
  // json