@typia/interface 12.0.0-dev.20260310 → 12.0.0-dev.20260312

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/lib/http/IHttpLlmApplication.d.ts +1 -1
  2. package/lib/http/IHttpLlmFunction.d.ts +1 -1
  3. package/lib/http/IHttpMigrateApplication.d.ts +1 -1
  4. package/lib/http/IHttpMigrateRoute.d.ts +2 -2
  5. package/lib/openapi/OpenApi.d.ts +35 -10
  6. package/lib/openapi/OpenApiV3.d.ts +7 -0
  7. package/lib/openapi/OpenApiV3_1.d.ts +7 -0
  8. package/lib/openapi/OpenApiV3_2.d.ts +489 -0
  9. package/lib/openapi/OpenApiV3_2.js +3 -0
  10. package/lib/openapi/OpenApiV3_2.js.map +1 -0
  11. package/lib/openapi/SwaggerV2.d.ts +7 -0
  12. package/lib/openapi/index.d.ts +1 -0
  13. package/lib/openapi/index.js +1 -0
  14. package/lib/openapi/index.js.map +1 -1
  15. package/lib/schema/ILlmApplication.d.ts +1 -2
  16. package/lib/schema/ILlmSchema.d.ts +1 -11
  17. package/lib/schema/ILlmStructuredOutput.d.ts +108 -0
  18. package/lib/schema/ILlmStructuredOutput.js +3 -0
  19. package/lib/schema/ILlmStructuredOutput.js.map +1 -0
  20. package/lib/schema/index.d.ts +1 -0
  21. package/lib/schema/index.js +1 -0
  22. package/lib/schema/index.js.map +1 -1
  23. package/package.json +1 -1
  24. package/src/http/IHttpLlmApplication.ts +72 -72
  25. package/src/http/IHttpLlmFunction.ts +34 -34
  26. package/src/http/IHttpMigrateApplication.ts +48 -48
  27. package/src/http/IHttpMigrateRoute.ts +165 -165
  28. package/src/openapi/OpenApi.ts +680 -643
  29. package/src/openapi/OpenApiV3.ts +663 -655
  30. package/src/openapi/OpenApiV3_1.ts +743 -735
  31. package/src/openapi/OpenApiV3_2.ts +773 -0
  32. package/src/openapi/SwaggerV2.ts +567 -559
  33. package/src/openapi/index.ts +5 -4
  34. package/src/schema/ILlmApplication.ts +1 -2
  35. package/src/schema/ILlmSchema.ts +1 -12
  36. package/src/schema/ILlmStructuredOutput.ts +112 -0
  37. package/src/schema/index.ts +15 -14
@@ -1,4 +1,5 @@
1
- export * from "./OpenApi";
2
- export * from "./OpenApiV3";
3
- export * from "./OpenApiV3_1";
4
- export * from "./SwaggerV2";
1
+ export * from "./OpenApi";
2
+ export * from "./OpenApiV3";
3
+ export * from "./OpenApiV3_1";
4
+ export * from "./OpenApiV3_2";
5
+ export * from "./SwaggerV2";
@@ -13,7 +13,6 @@ import { IValidation } from "./IValidation";
13
13
  *
14
14
  * - {@link ILlmApplication.IConfig.validate}: Custom validation per method
15
15
  * - {@link ILlmSchema.IConfig.strict}: OpenAI structured output mode
16
- * - {@link ILlmSchema.IConfig.reference}: Control `$ref` inlining behavior
17
16
  *
18
17
  * @author Jeongho Nam - https://github.com/samchon
19
18
  * @template Class Source class/interface type
@@ -32,7 +31,7 @@ export interface ILlmApplication<Class extends object = any> {
32
31
  * Configuration used to generate this application.
33
32
  *
34
33
  * Contains the settings that were applied during schema generation, including
35
- * reference handling, strict mode, and parameter separation.
34
+ * strict mode and any custom validation hooks.
36
35
  */
37
36
  config: ILlmApplication.IConfig<Class>;
38
37
 
@@ -36,20 +36,9 @@ export namespace ILlmSchema {
36
36
  * Configuration options for LLM schema generation.
37
37
  *
38
38
  * Controls how TypeScript types are converted to LLM-compatible JSON schemas.
39
- * These settings affect reference handling and OpenAI structured output
40
- * compatibility.
39
+ * These settings affect OpenAI structured output compatibility.
41
40
  */
42
41
  export interface IConfig {
43
- /**
44
- * Whether to allow `$ref` references everywhere.
45
- *
46
- * When `false`, references are inlined except for recursive types.
47
- * References reduce token cost but may cause hallucination.
48
- *
49
- * @default true
50
- */
51
- reference: boolean;
52
-
53
42
  /**
54
43
  * Whether to enable strict mode (OpenAI structured output).
55
44
  *
@@ -0,0 +1,112 @@
1
+ import { IJsonParseResult } from "./IJsonParseResult";
2
+ import { ILlmSchema } from "./ILlmSchema";
3
+ import { IValidation } from "./IValidation";
4
+
5
+ /**
6
+ * LLM structured output schema with parsing and validation utilities.
7
+ *
8
+ * `ILlmStructuredOutput<T>` is generated by `typia.llm.structuredOutput<T>()`
9
+ * to provide everything needed for handling LLM structured outputs: the JSON
10
+ * schema for prompting, and functions for parsing, coercing, and validating
11
+ * responses.
12
+ *
13
+ * Structured outputs allow LLMs to generate data conforming to a predefined
14
+ * schema instead of free-form text. This is useful for:
15
+ *
16
+ * - Extracting structured data from conversations
17
+ * - Generating typed responses for downstream processing
18
+ * - Ensuring consistent output formats across LLM calls
19
+ *
20
+ * Workflow:
21
+ *
22
+ * 1. Pass {@link parameters} schema to LLM provider
23
+ * 2. Receive LLM response (JSON string or pre-parsed object)
24
+ * 3. Use {@link parse} for raw strings or {@link coerce} for pre-parsed objects
25
+ * 4. Use {@link validate} to check the result and get detailed errors
26
+ *
27
+ * @author Jeongho Nam - https://github.com/samchon
28
+ * @template T The expected output type
29
+ */
30
+ export interface ILlmStructuredOutput<T = unknown> {
31
+ /**
32
+ * JSON schema for the structured output.
33
+ *
34
+ * Pass this schema to LLM providers (OpenAI, Anthropic, Google, etc.) to
35
+ * constrain the output format. The schema includes `$defs` for shared type
36
+ * definitions and `properties` for the output structure.
37
+ *
38
+ * Most LLM providers accept this directly in their structured output or
39
+ * response format configuration.
40
+ */
41
+ parameters: ILlmSchema.IParameters;
42
+
43
+ /**
44
+ * Lenient JSON parser with schema-based type coercion.
45
+ *
46
+ * Handles incomplete or malformed JSON commonly produced by LLMs:
47
+ *
48
+ * - Unclosed brackets, strings, trailing commas
49
+ * - JavaScript-style comments (`//` and multi-line)
50
+ * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
51
+ * - Markdown code block extraction, junk prefix skipping
52
+ *
53
+ * Also coerces double-stringified values based on the schema:
54
+ *
55
+ * - `"42"` → `42` (when schema expects number)
56
+ * - `"true"` → `true` (when schema expects boolean)
57
+ * - `"null"` → `null` (when schema expects null)
58
+ * - `"{...}"` → `{...}` (when schema expects object)
59
+ * - `"[...]"` → `[...]` (when schema expects array)
60
+ *
61
+ * Type validation is NOT performed — use {@link validate} after parsing.
62
+ *
63
+ * If the SDK (e.g., LangChain, Vercel AI, MCP) already parses JSON internally
64
+ * and provides a pre-parsed object, use {@link coerce} instead.
65
+ *
66
+ * @param input Raw JSON string from LLM output
67
+ * @returns Parse result with data on success, or partial data with errors
68
+ */
69
+ parse: (input: string) => IJsonParseResult<T>;
70
+
71
+ /**
72
+ * Coerce pre-parsed output to match expected schema types.
73
+ *
74
+ * **Use this only when the SDK already parses JSON internally.** For raw JSON
75
+ * strings from LLM output, use {@link parse} instead — it handles both lenient
76
+ * parsing and type coercion in one step.
77
+ *
78
+ * LLMs often return values with incorrect types even after parsing:
79
+ *
80
+ * - `"42"` → `42` (when schema expects number)
81
+ * - `"true"` → `true` (when schema expects boolean)
82
+ * - `"null"` → `null` (when schema expects null)
83
+ * - `"{...}"` → `{...}` (when schema expects object)
84
+ * - `"[...]"` → `[...]` (when schema expects array)
85
+ *
86
+ * This function recursively coerces these double-stringified values based on
87
+ * the {@link parameters} schema.
88
+ *
89
+ * Type validation is NOT performed — use {@link validate} after coercion.
90
+ *
91
+ * @param input Pre-parsed output object from SDK
92
+ * @returns Coerced output with corrected types
93
+ */
94
+ coerce: (input: unknown) => T;
95
+
96
+ /**
97
+ * Validates LLM-generated output against the schema.
98
+ *
99
+ * LLMs frequently make type errors such as returning strings instead of
100
+ * numbers or missing required properties. Use this validator to check output
101
+ * before further processing.
102
+ *
103
+ * When validation fails, use {@link LlmJson.stringify} from `@typia/utils` to
104
+ * format the error for LLM feedback. The formatted output shows the invalid
105
+ * JSON with inline error comments, helping the LLM understand and correct its
106
+ * mistakes in the next turn.
107
+ *
108
+ * @param input The output generated by the LLM
109
+ * @returns Validation result with success status and any errors
110
+ */
111
+ validate: (input: unknown) => IValidation<T>;
112
+ }
@@ -1,14 +1,15 @@
1
- export * from "./IResult";
2
- export * from "./IValidation";
3
-
4
- export * from "./IJsonSchemaTransformError";
5
- export * from "./IJsonSchemaApplication";
6
- export * from "./IJsonSchemaCollection";
7
- export * from "./IJsonSchemaUnit";
8
- export * from "./IJsonSchemaAttribute";
9
-
10
- export * from "./ILlmController";
11
- export * from "./ILlmApplication";
12
- export * from "./ILlmFunction";
13
- export * from "./ILlmSchema";
14
- export * from "./IJsonParseResult";
1
+ export * from "./IResult";
2
+ export * from "./IValidation";
3
+
4
+ export * from "./IJsonSchemaTransformError";
5
+ export * from "./IJsonSchemaApplication";
6
+ export * from "./IJsonSchemaCollection";
7
+ export * from "./IJsonSchemaUnit";
8
+ export * from "./IJsonSchemaAttribute";
9
+
10
+ export * from "./ILlmController";
11
+ export * from "./ILlmApplication";
12
+ export * from "./ILlmFunction";
13
+ export * from "./ILlmSchema";
14
+ export * from "./ILlmStructuredOutput";
15
+ export * from "./IJsonParseResult";