@wp-typia/project-tools 0.23.0 → 0.24.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.
Files changed (228) hide show
  1. package/dist/runtime/ai-feature-artifacts.js +4 -1
  2. package/dist/runtime/block-generator-service-spec.js +2 -1
  3. package/dist/runtime/built-in-block-non-ts-basic-artifacts.d.ts +9 -0
  4. package/dist/runtime/built-in-block-non-ts-basic-artifacts.js +84 -0
  5. package/dist/runtime/built-in-block-non-ts-compound-artifacts.d.ts +9 -0
  6. package/dist/runtime/built-in-block-non-ts-compound-artifacts.js +36 -0
  7. package/dist/runtime/built-in-block-non-ts-compound-templates.d.ts +23 -0
  8. package/dist/runtime/built-in-block-non-ts-compound-templates.js +453 -0
  9. package/dist/runtime/built-in-block-non-ts-family-artifacts.d.ts +8 -26
  10. package/dist/runtime/built-in-block-non-ts-family-artifacts.js +8 -1034
  11. package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.d.ts +9 -0
  12. package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.js +83 -0
  13. package/dist/runtime/built-in-block-non-ts-persistence-artifacts.d.ts +9 -0
  14. package/dist/runtime/built-in-block-non-ts-persistence-artifacts.js +33 -0
  15. package/dist/runtime/built-in-block-non-ts-persistence-templates.d.ts +23 -0
  16. package/dist/runtime/built-in-block-non-ts-persistence-templates.js +395 -0
  17. package/dist/runtime/cli-add-block-json.js +5 -1
  18. package/dist/runtime/cli-add-collision.js +8 -0
  19. package/dist/runtime/cli-add-help.js +14 -10
  20. package/dist/runtime/cli-add-kind-ids.d.ts +1 -1
  21. package/dist/runtime/cli-add-kind-ids.js +1 -0
  22. package/dist/runtime/cli-add-types.d.ts +45 -6
  23. package/dist/runtime/cli-add-types.js +2 -0
  24. package/dist/runtime/cli-add-validation.d.ts +7 -0
  25. package/dist/runtime/cli-add-validation.js +9 -0
  26. package/dist/runtime/cli-add-workspace-ability-anchors.d.ts +24 -0
  27. package/dist/runtime/cli-add-workspace-ability-anchors.js +294 -0
  28. package/dist/runtime/cli-add-workspace-ability-registry.d.ts +10 -0
  29. package/dist/runtime/cli-add-workspace-ability-registry.js +51 -0
  30. package/dist/runtime/cli-add-workspace-ability-scaffold.d.ts +1 -1
  31. package/dist/runtime/cli-add-workspace-ability-scaffold.js +5 -308
  32. package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +6 -2
  33. package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.d.ts +34 -0
  34. package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.js +483 -0
  35. package/dist/runtime/cli-add-workspace-admin-view-templates-default.d.ts +30 -0
  36. package/dist/runtime/cli-add-workspace-admin-view-templates-default.js +310 -0
  37. package/dist/runtime/cli-add-workspace-admin-view-templates-rest.d.ts +25 -0
  38. package/dist/runtime/cli-add-workspace-admin-view-templates-rest.js +124 -0
  39. package/dist/runtime/cli-add-workspace-admin-view-templates-settings.d.ts +34 -0
  40. package/dist/runtime/cli-add-workspace-admin-view-templates-settings.js +370 -0
  41. package/dist/runtime/cli-add-workspace-admin-view-templates-shared.d.ts +49 -0
  42. package/dist/runtime/cli-add-workspace-admin-view-templates-shared.js +259 -0
  43. package/dist/runtime/cli-add-workspace-admin-view-templates.d.ts +18 -27
  44. package/dist/runtime/cli-add-workspace-admin-view-templates.js +30 -1326
  45. package/dist/runtime/cli-add-workspace-ai-anchors.d.ts +4 -4
  46. package/dist/runtime/cli-add-workspace-ai-anchors.js +8 -233
  47. package/dist/runtime/cli-add-workspace-ai-scaffold.js +4 -2
  48. package/dist/runtime/cli-add-workspace-ai-source-emitters.d.ts +1 -4
  49. package/dist/runtime/cli-add-workspace-ai-source-emitters.js +1 -129
  50. package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.d.ts +5 -0
  51. package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.js +236 -0
  52. package/dist/runtime/cli-add-workspace-ai-sync-script-source.d.ts +4 -0
  53. package/dist/runtime/cli-add-workspace-ai-sync-script-source.js +145 -0
  54. package/dist/runtime/cli-add-workspace-assets.d.ts +6 -63
  55. package/dist/runtime/cli-add-workspace-assets.js +6 -950
  56. package/dist/runtime/cli-add-workspace-binding-source-anchors.d.ts +23 -0
  57. package/dist/runtime/cli-add-workspace-binding-source-anchors.js +112 -0
  58. package/dist/runtime/cli-add-workspace-binding-source-source-emitters.d.ts +33 -0
  59. package/dist/runtime/cli-add-workspace-binding-source-source-emitters.js +436 -0
  60. package/dist/runtime/cli-add-workspace-binding-source-types.d.ts +20 -0
  61. package/dist/runtime/cli-add-workspace-binding-source-types.js +1 -0
  62. package/dist/runtime/cli-add-workspace-binding-source.d.ts +40 -0
  63. package/dist/runtime/cli-add-workspace-binding-source.js +275 -0
  64. package/dist/runtime/cli-add-workspace-block-style.d.ts +22 -0
  65. package/dist/runtime/cli-add-workspace-block-style.js +148 -0
  66. package/dist/runtime/cli-add-workspace-block-transform.d.ts +32 -0
  67. package/dist/runtime/cli-add-workspace-block-transform.js +197 -0
  68. package/dist/runtime/cli-add-workspace-contract.js +1 -1
  69. package/dist/runtime/cli-add-workspace-core-variation.d.ts +20 -0
  70. package/dist/runtime/cli-add-workspace-core-variation.js +322 -0
  71. package/dist/runtime/cli-add-workspace-editor-plugin-anchors.d.ts +37 -0
  72. package/dist/runtime/cli-add-workspace-editor-plugin-anchors.js +206 -0
  73. package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.d.ts +47 -0
  74. package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.js +219 -0
  75. package/dist/runtime/cli-add-workspace-editor-plugin.d.ts +22 -0
  76. package/dist/runtime/cli-add-workspace-editor-plugin.js +78 -0
  77. package/dist/runtime/cli-add-workspace-hooked-block.d.ts +23 -0
  78. package/dist/runtime/cli-add-workspace-hooked-block.js +57 -0
  79. package/dist/runtime/cli-add-workspace-integration-env-files.d.ts +33 -0
  80. package/dist/runtime/cli-add-workspace-integration-env-files.js +65 -0
  81. package/dist/runtime/cli-add-workspace-integration-env-package-json.d.ts +38 -0
  82. package/dist/runtime/cli-add-workspace-integration-env-package-json.js +122 -0
  83. package/dist/runtime/cli-add-workspace-integration-env-source-emitters.d.ts +44 -0
  84. package/dist/runtime/cli-add-workspace-integration-env-source-emitters.js +262 -0
  85. package/dist/runtime/cli-add-workspace-integration-env.d.ts +3 -1
  86. package/dist/runtime/cli-add-workspace-integration-env.js +10 -313
  87. package/dist/runtime/cli-add-workspace-pattern-anchors.d.ts +10 -0
  88. package/dist/runtime/cli-add-workspace-pattern-anchors.js +95 -0
  89. package/dist/runtime/cli-add-workspace-pattern-options.d.ts +20 -0
  90. package/dist/runtime/cli-add-workspace-pattern-options.js +113 -0
  91. package/dist/runtime/cli-add-workspace-pattern-source-emitters.d.ts +20 -0
  92. package/dist/runtime/cli-add-workspace-pattern-source-emitters.js +57 -0
  93. package/dist/runtime/cli-add-workspace-pattern.d.ts +42 -0
  94. package/dist/runtime/cli-add-workspace-pattern.js +99 -0
  95. package/dist/runtime/cli-add-workspace-post-meta.js +1 -1
  96. package/dist/runtime/cli-add-workspace-registration-hooks.d.ts +50 -0
  97. package/dist/runtime/cli-add-workspace-registration-hooks.js +162 -0
  98. package/dist/runtime/cli-add-workspace-rest-anchors.d.ts +9 -4
  99. package/dist/runtime/cli-add-workspace-rest-anchors.js +9 -428
  100. package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.d.ts +17 -0
  101. package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.js +108 -0
  102. package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.d.ts +9 -0
  103. package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.js +142 -0
  104. package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.d.ts +51 -0
  105. package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.js +415 -0
  106. package/dist/runtime/cli-add-workspace-rest-generated.d.ts +9 -0
  107. package/dist/runtime/cli-add-workspace-rest-generated.js +160 -0
  108. package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.d.ts +80 -0
  109. package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.js +238 -0
  110. package/dist/runtime/cli-add-workspace-rest-manual.d.ts +8 -0
  111. package/dist/runtime/cli-add-workspace-rest-manual.js +266 -0
  112. package/dist/runtime/cli-add-workspace-rest-php-templates.d.ts +18 -0
  113. package/dist/runtime/cli-add-workspace-rest-php-templates.js +359 -0
  114. package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.d.ts +33 -0
  115. package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.js +145 -0
  116. package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.d.ts +9 -0
  117. package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.js +162 -0
  118. package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.d.ts +7 -0
  119. package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.js +193 -0
  120. package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +5 -91
  121. package/dist/runtime/cli-add-workspace-rest-source-emitters.js +5 -642
  122. package/dist/runtime/cli-add-workspace-rest-source-utils.d.ts +17 -0
  123. package/dist/runtime/cli-add-workspace-rest-source-utils.js +50 -0
  124. package/dist/runtime/cli-add-workspace-rest-sync-script-shared.d.ts +56 -0
  125. package/dist/runtime/cli-add-workspace-rest-sync-script-shared.js +122 -0
  126. package/dist/runtime/cli-add-workspace-rest-types.d.ts +108 -0
  127. package/dist/runtime/cli-add-workspace-rest-types.js +1 -0
  128. package/dist/runtime/cli-add-workspace-rest.d.ts +3 -20
  129. package/dist/runtime/cli-add-workspace-rest.js +33 -788
  130. package/dist/runtime/cli-add-workspace-variation.d.ts +22 -0
  131. package/dist/runtime/cli-add-workspace-variation.js +162 -0
  132. package/dist/runtime/cli-add-workspace.d.ts +42 -107
  133. package/dist/runtime/cli-add-workspace.js +42 -674
  134. package/dist/runtime/cli-add.d.ts +3 -3
  135. package/dist/runtime/cli-add.js +2 -2
  136. package/dist/runtime/cli-core.d.ts +3 -2
  137. package/dist/runtime/cli-core.js +2 -2
  138. package/dist/runtime/cli-diagnostics.d.ts +3 -1
  139. package/dist/runtime/cli-diagnostics.js +17 -5
  140. package/dist/runtime/cli-doctor-workspace-bindings.js +63 -1
  141. package/dist/runtime/cli-doctor-workspace-block-addons.d.ts +12 -0
  142. package/dist/runtime/cli-doctor-workspace-block-addons.js +162 -0
  143. package/dist/runtime/cli-doctor-workspace-block-iframe.d.ts +9 -0
  144. package/dist/runtime/cli-doctor-workspace-block-iframe.js +228 -0
  145. package/dist/runtime/cli-doctor-workspace-block-metadata.d.ts +11 -0
  146. package/dist/runtime/cli-doctor-workspace-block-metadata.js +111 -0
  147. package/dist/runtime/cli-doctor-workspace-blocks.js +6 -424
  148. package/dist/runtime/cli-doctor-workspace-features-abilities.d.ts +11 -0
  149. package/dist/runtime/cli-doctor-workspace-features-abilities.js +112 -0
  150. package/dist/runtime/cli-doctor-workspace-features-admin-views.d.ts +11 -0
  151. package/dist/runtime/cli-doctor-workspace-features-admin-views.js +128 -0
  152. package/dist/runtime/cli-doctor-workspace-features-ai.d.ts +11 -0
  153. package/dist/runtime/cli-doctor-workspace-features-ai.js +57 -0
  154. package/dist/runtime/cli-doctor-workspace-features-editor-plugins.d.ts +11 -0
  155. package/dist/runtime/cli-doctor-workspace-features-editor-plugins.js +80 -0
  156. package/dist/runtime/cli-doctor-workspace-features-post-meta.d.ts +11 -0
  157. package/dist/runtime/cli-doctor-workspace-features-post-meta.js +77 -0
  158. package/dist/runtime/cli-doctor-workspace-features-rest.d.ts +11 -0
  159. package/dist/runtime/cli-doctor-workspace-features-rest.js +120 -0
  160. package/dist/runtime/cli-doctor-workspace-features.js +14 -487
  161. package/dist/runtime/cli-doctor.d.ts +54 -3
  162. package/dist/runtime/cli-doctor.js +92 -10
  163. package/dist/runtime/cli-help.js +12 -7
  164. package/dist/runtime/cli-init-package-json.js +4 -2
  165. package/dist/runtime/cli-prompt.d.ts +16 -2
  166. package/dist/runtime/cli-prompt.js +29 -12
  167. package/dist/runtime/cli-scaffold.d.ts +2 -1
  168. package/dist/runtime/cli-scaffold.js +19 -10
  169. package/dist/runtime/external-template-guards.js +4 -6
  170. package/dist/runtime/index.d.ts +6 -3
  171. package/dist/runtime/index.js +4 -2
  172. package/dist/runtime/json-utils.d.ts +62 -4
  173. package/dist/runtime/json-utils.js +78 -4
  174. package/dist/runtime/local-dev-presets.js +6 -2
  175. package/dist/runtime/migration-ui-capability.js +4 -1
  176. package/dist/runtime/migration-utils.js +4 -1
  177. package/dist/runtime/package-managers.js +6 -1
  178. package/dist/runtime/package-versions.d.ts +1 -0
  179. package/dist/runtime/package-versions.js +16 -3
  180. package/dist/runtime/pattern-catalog.d.ts +122 -0
  181. package/dist/runtime/pattern-catalog.js +471 -0
  182. package/dist/runtime/post-meta-binding-fields.d.ts +46 -0
  183. package/dist/runtime/post-meta-binding-fields.js +135 -0
  184. package/dist/runtime/scaffold-bootstrap.js +7 -2
  185. package/dist/runtime/scaffold-package-manager-files.js +5 -1
  186. package/dist/runtime/scaffold-repository-reference.js +4 -2
  187. package/dist/runtime/scaffold-template-variables.js +2 -1
  188. package/dist/runtime/scaffold.d.ts +18 -1
  189. package/dist/runtime/scaffold.js +55 -2
  190. package/dist/runtime/temp-roots.js +4 -1
  191. package/dist/runtime/template-layers.js +4 -1
  192. package/dist/runtime/template-registry.js +9 -3
  193. package/dist/runtime/template-source-contracts.d.ts +2 -0
  194. package/dist/runtime/template-source-normalization.js +2 -1
  195. package/dist/runtime/template-source-remote.js +18 -5
  196. package/dist/runtime/template-source-seeds.js +10 -3
  197. package/dist/runtime/typia-llm-json-schema.d.ts +24 -0
  198. package/dist/runtime/typia-llm-json-schema.js +33 -0
  199. package/dist/runtime/typia-llm-openapi-constraints.d.ts +20 -0
  200. package/dist/runtime/typia-llm-openapi-constraints.js +254 -0
  201. package/dist/runtime/typia-llm-projection.d.ts +25 -0
  202. package/dist/runtime/typia-llm-projection.js +58 -0
  203. package/dist/runtime/typia-llm-render.d.ts +21 -0
  204. package/dist/runtime/typia-llm-render.js +252 -0
  205. package/dist/runtime/typia-llm-sync.d.ts +10 -0
  206. package/dist/runtime/typia-llm-sync.js +63 -0
  207. package/dist/runtime/typia-llm-types.d.ts +197 -0
  208. package/dist/runtime/typia-llm-types.js +1 -0
  209. package/dist/runtime/typia-llm.d.ts +9 -255
  210. package/dist/runtime/typia-llm.js +5 -634
  211. package/dist/runtime/workspace-inventory-mutations.js +15 -1
  212. package/dist/runtime/workspace-inventory-parser-entries.d.ts +17 -0
  213. package/dist/runtime/workspace-inventory-parser-entries.js +157 -0
  214. package/dist/runtime/workspace-inventory-parser-validation.d.ts +104 -0
  215. package/dist/runtime/workspace-inventory-parser-validation.js +34 -0
  216. package/dist/runtime/workspace-inventory-parser.d.ts +3 -45
  217. package/dist/runtime/workspace-inventory-parser.js +3 -581
  218. package/dist/runtime/workspace-inventory-section-descriptors.d.ts +19 -0
  219. package/dist/runtime/workspace-inventory-section-descriptors.js +443 -0
  220. package/dist/runtime/workspace-inventory-templates.d.ts +3 -3
  221. package/dist/runtime/workspace-inventory-templates.js +10 -1
  222. package/dist/runtime/workspace-inventory-types.d.ts +10 -1
  223. package/dist/runtime/workspace-project.js +4 -6
  224. package/package.json +8 -3
  225. package/templates/_shared/compound/core/scripts/block-config.ts.mustache +22 -0
  226. package/templates/_shared/compound/core/scripts/sync-types-to-block-json.ts.mustache +103 -2
  227. package/templates/_shared/compound/core/src/inner-blocks-templates.ts.mustache +13 -0
  228. package/templates/_shared/compound/persistence/scripts/block-config.ts.mustache +22 -1
@@ -0,0 +1,254 @@
1
+ import { cloneJsonValue } from './json-utils.js';
2
+ import { assertJsonSchemaObject, cloneJsonValueIfDefined, isJsonSchemaObject, } from './typia-llm-json-schema.js';
3
+ const JSON_SCHEMA_CONSTRAINT_KEYS = [
4
+ 'additionalProperties',
5
+ 'const',
6
+ 'default',
7
+ 'enum',
8
+ 'exclusiveMaximum',
9
+ 'exclusiveMinimum',
10
+ 'format',
11
+ 'maxItems',
12
+ 'maxLength',
13
+ 'maximum',
14
+ 'minItems',
15
+ 'minLength',
16
+ 'minimum',
17
+ 'multipleOf',
18
+ 'pattern',
19
+ 'type',
20
+ ];
21
+ function decodeJsonPointerSegment(segment) {
22
+ return segment.replace(/~1/g, '/').replace(/~0/g, '~');
23
+ }
24
+ function resolveOpenApiReferenceTarget(document, reference) {
25
+ if (!reference.startsWith('#/')) {
26
+ throw new Error(`Unsupported OpenAPI schema reference "${reference}".`);
27
+ }
28
+ let current = document;
29
+ for (const rawSegment of reference.slice(2).split('/')) {
30
+ const segment = decodeJsonPointerSegment(rawSegment);
31
+ if (Array.isArray(current)) {
32
+ const index = Number.parseInt(segment, 10);
33
+ current = Number.isInteger(index) ? current[index] : undefined;
34
+ continue;
35
+ }
36
+ if (!isJsonSchemaObject(current)) {
37
+ current = undefined;
38
+ break;
39
+ }
40
+ current = current[segment];
41
+ }
42
+ if (!isJsonSchemaObject(current)) {
43
+ throw new Error(`Unable to resolve OpenAPI schema reference "${reference}".`);
44
+ }
45
+ return current;
46
+ }
47
+ function resolveOpenApiSchemaObject(document, schema, seenReferences = new Set()) {
48
+ if (!isJsonSchemaObject(schema)) {
49
+ return {};
50
+ }
51
+ const reference = schema.$ref;
52
+ if (typeof reference !== 'string') {
53
+ return schema;
54
+ }
55
+ if (seenReferences.has(reference)) {
56
+ return schema;
57
+ }
58
+ return resolveOpenApiSchemaObject(document, resolveOpenApiReferenceTarget(document, reference), new Set([...seenReferences, reference]));
59
+ }
60
+ function collectOpenApiSeenReferences(schema, seenReferences) {
61
+ const reference = schema.$ref;
62
+ if (typeof reference !== 'string' || seenReferences.has(reference)) {
63
+ return seenReferences;
64
+ }
65
+ return new Set([...seenReferences, reference]);
66
+ }
67
+ /**
68
+ * Copy constraint-oriented JSON Schema keywords from `source` into `target`.
69
+ *
70
+ * This helper intentionally mutates and returns `target` so nested OpenAPI
71
+ * constraint restoration can preserve the projected typia.llm schema shape.
72
+ * Callers that need immutable behavior should clone the target before calling.
73
+ */
74
+ function mergeJsonSchemaConstraintProperties(document, target, source, seenReferences = new Set()) {
75
+ const nextSeenReferences = collectOpenApiSeenReferences(source, seenReferences);
76
+ const resolvedSource = resolveOpenApiSchemaObject(document, source, seenReferences);
77
+ const merged = target;
78
+ for (const key of JSON_SCHEMA_CONSTRAINT_KEYS) {
79
+ if (resolvedSource[key] !== undefined) {
80
+ merged[key] = cloneJsonValue(resolvedSource[key]);
81
+ }
82
+ }
83
+ if (Array.isArray(resolvedSource.required)) {
84
+ merged.required = resolvedSource.required.filter((value) => typeof value === 'string');
85
+ }
86
+ if (Array.isArray(resolvedSource.items)) {
87
+ merged.items = cloneJsonValue(resolvedSource.items);
88
+ }
89
+ else if (isJsonSchemaObject(resolvedSource.items)) {
90
+ const nextItems = isJsonSchemaObject(merged.items) ? merged.items : {};
91
+ merged.items = mergeJsonSchemaConstraintProperties(document, nextItems, resolvedSource.items, nextSeenReferences);
92
+ }
93
+ if (isJsonSchemaObject(resolvedSource.properties)) {
94
+ const targetProperties = isJsonSchemaObject(merged.properties)
95
+ ? merged.properties
96
+ : {};
97
+ for (const [propertyName, propertySchema] of Object.entries(resolvedSource.properties)) {
98
+ if (!isJsonSchemaObject(propertySchema)) {
99
+ continue;
100
+ }
101
+ const nextProperty = isJsonSchemaObject(targetProperties[propertyName])
102
+ ? targetProperties[propertyName]
103
+ : {};
104
+ targetProperties[propertyName] = mergeJsonSchemaConstraintProperties(document, nextProperty, propertySchema, nextSeenReferences);
105
+ }
106
+ merged.properties = targetProperties;
107
+ }
108
+ return merged;
109
+ }
110
+ function findOpenApiOperationById(document, operationId) {
111
+ for (const pathItem of Object.values(document.paths)) {
112
+ if (!isJsonSchemaObject(pathItem)) {
113
+ continue;
114
+ }
115
+ for (const method of ['delete', 'get', 'patch', 'post', 'put']) {
116
+ const operation = resolveOpenApiSchemaObject(document, pathItem[method]);
117
+ if (!isJsonSchemaObject(operation) ||
118
+ typeof operation.operationId !== 'string') {
119
+ continue;
120
+ }
121
+ if (operation.operationId === operationId) {
122
+ return operation;
123
+ }
124
+ }
125
+ }
126
+ return null;
127
+ }
128
+ function resolveOpenApiRequestBodySchema(operation, document) {
129
+ const requestBody = resolveOpenApiSchemaObject(document, operation.requestBody);
130
+ const content = isJsonSchemaObject(requestBody.content)
131
+ ? requestBody.content
132
+ : null;
133
+ const jsonMediaType = content && isJsonSchemaObject(content['application/json'])
134
+ ? content['application/json']
135
+ : null;
136
+ const schema = jsonMediaType?.schema;
137
+ if (!isJsonSchemaObject(schema)) {
138
+ return null;
139
+ }
140
+ return resolveOpenApiSchemaObject(document, schema);
141
+ }
142
+ function resolveOpenApiSuccessResponseSchema(operation, document) {
143
+ for (const [statusCode, response] of Object.entries(operation.responses)) {
144
+ const resolvedResponse = resolveOpenApiSchemaObject(document, response);
145
+ if (!/^2(?:\d\d|XX)$/u.test(statusCode) ||
146
+ !isJsonSchemaObject(resolvedResponse)) {
147
+ continue;
148
+ }
149
+ const content = isJsonSchemaObject(resolvedResponse.content)
150
+ ? resolvedResponse.content
151
+ : null;
152
+ const jsonMediaType = content && isJsonSchemaObject(content['application/json'])
153
+ ? content['application/json']
154
+ : null;
155
+ const schema = jsonMediaType?.schema;
156
+ if (!isJsonSchemaObject(schema)) {
157
+ continue;
158
+ }
159
+ return resolveOpenApiSchemaObject(document, schema);
160
+ }
161
+ return null;
162
+ }
163
+ function getOrCreateObjectProperty(target, propertyName) {
164
+ const targetProperties = isJsonSchemaObject(target.properties)
165
+ ? target.properties
166
+ : {};
167
+ const nextProperty = isJsonSchemaObject(targetProperties[propertyName])
168
+ ? targetProperties[propertyName]
169
+ : {};
170
+ targetProperties[propertyName] = nextProperty;
171
+ target.properties = targetProperties;
172
+ return nextProperty;
173
+ }
174
+ function applyOpenApiQueryParameterConstraints(target, operation, document) {
175
+ for (const parameter of operation.parameters ?? []) {
176
+ const resolvedParameter = resolveOpenApiSchemaObject(document, parameter);
177
+ if (!isJsonSchemaObject(resolvedParameter) ||
178
+ resolvedParameter.in !== 'query' ||
179
+ typeof resolvedParameter.name !== 'string') {
180
+ continue;
181
+ }
182
+ const propertyTarget = getOrCreateObjectProperty(target, resolvedParameter.name);
183
+ mergeJsonSchemaConstraintProperties(document, propertyTarget, resolveOpenApiSchemaObject(document, resolvedParameter.schema));
184
+ if (resolvedParameter.required === true) {
185
+ const required = new Set(Array.isArray(target.required)
186
+ ? target.required.filter((value) => typeof value === 'string')
187
+ : []);
188
+ required.add(resolvedParameter.name);
189
+ target.required = [...required];
190
+ }
191
+ }
192
+ }
193
+ /**
194
+ * Clone a projected function artifact before mutation-oriented constraint work.
195
+ *
196
+ * @param functionArtifact Projected artifact to clone.
197
+ * @returns A cloned artifact with parameters and optional output deep-cloned,
198
+ * and tags shallow-copied when present.
199
+ */
200
+ export function cloneProjectedTypiaLlmFunctionArtifact(functionArtifact) {
201
+ return {
202
+ description: functionArtifact.description,
203
+ name: functionArtifact.name,
204
+ output: cloneJsonValueIfDefined(functionArtifact.output),
205
+ parameters: cloneJsonValue(functionArtifact.parameters),
206
+ ...(functionArtifact.tags ? { tags: [...functionArtifact.tags] } : {}),
207
+ };
208
+ }
209
+ /**
210
+ * Restores canonical request and response constraints from an endpoint-aware
211
+ * OpenAPI document onto one projected `typia.llm` function artifact.
212
+ *
213
+ * Query-only inputs merge into the root parameter object. Mixed body/query
214
+ * inputs merge into the generated `body` and `query` properties.
215
+ *
216
+ * @param options Projected artifact plus the canonical OpenAPI document.
217
+ * @returns A cloned artifact enriched with OpenAPI-backed constraints when available.
218
+ */
219
+ export function applyOpenApiConstraintsToTypiaLlmFunctionArtifact({ functionArtifact, openApiDocument, operationId, }) {
220
+ const constrainedArtifact = cloneProjectedTypiaLlmFunctionArtifact(functionArtifact);
221
+ const operation = findOpenApiOperationById(openApiDocument, operationId);
222
+ if (!operation) {
223
+ return constrainedArtifact;
224
+ }
225
+ const hasQueryParameters = (operation.parameters ?? []).some((parameter) => {
226
+ const resolvedParameter = resolveOpenApiSchemaObject(openApiDocument, parameter);
227
+ return (isJsonSchemaObject(resolvedParameter) &&
228
+ resolvedParameter.in === 'query' &&
229
+ typeof resolvedParameter.name === 'string');
230
+ });
231
+ const requestBodySchema = resolveOpenApiRequestBodySchema(operation, openApiDocument);
232
+ const parameterSchema = assertJsonSchemaObject(constrainedArtifact.parameters, `typia.llm parameters for "${constrainedArtifact.name}"`);
233
+ if (requestBodySchema) {
234
+ if (hasQueryParameters) {
235
+ mergeJsonSchemaConstraintProperties(openApiDocument, getOrCreateObjectProperty(parameterSchema, 'body'), requestBodySchema);
236
+ }
237
+ else {
238
+ mergeJsonSchemaConstraintProperties(openApiDocument, parameterSchema, requestBodySchema);
239
+ }
240
+ }
241
+ if (hasQueryParameters) {
242
+ applyOpenApiQueryParameterConstraints(requestBodySchema
243
+ ? getOrCreateObjectProperty(parameterSchema, 'query')
244
+ : parameterSchema, operation, openApiDocument);
245
+ }
246
+ if (constrainedArtifact.output) {
247
+ const outputSchema = assertJsonSchemaObject(constrainedArtifact.output, `typia.llm output for "${constrainedArtifact.name}"`);
248
+ const responseSchema = resolveOpenApiSuccessResponseSchema(operation, openApiDocument);
249
+ if (responseSchema) {
250
+ mergeJsonSchemaConstraintProperties(openApiDocument, outputSchema, responseSchema);
251
+ }
252
+ }
253
+ return constrainedArtifact;
254
+ }
@@ -0,0 +1,25 @@
1
+ import type { ProjectedTypiaLlmApplicationArtifact, ProjectedTypiaLlmFunctionArtifact, ProjectedTypiaLlmStructuredOutputArtifact, ProjectTypiaLlmApplicationArtifactOptions, ProjectTypiaLlmStructuredOutputArtifactOptions, TypiaLlmFunctionLike } from './typia-llm-types.js';
2
+ /**
3
+ * Projects one compiled `typia.llm` function schema into a JSON-friendly
4
+ * artifact record.
5
+ *
6
+ * @param functionSchema Function schema from a compiled `typia.llm.application(...)`.
7
+ * @returns JSON-friendly function artifact.
8
+ */
9
+ export declare function projectTypiaLlmApplicationFunction(functionSchema: TypiaLlmFunctionLike): ProjectedTypiaLlmFunctionArtifact;
10
+ /**
11
+ * Projects a compiled `typia.llm.application(...)` result into a JSON-friendly
12
+ * downstream adapter artifact.
13
+ *
14
+ * @param options Compiled application value and source metadata.
15
+ * @returns JSON-friendly application artifact.
16
+ */
17
+ export declare function projectTypiaLlmApplicationArtifact({ application, generatedFrom, openApiProjection, transformFunction, }: ProjectTypiaLlmApplicationArtifactOptions): ProjectedTypiaLlmApplicationArtifact;
18
+ /**
19
+ * Projects a compiled `typia.llm.structuredOutput(...)` result into a
20
+ * JSON-friendly downstream adapter artifact.
21
+ *
22
+ * @param options Compiled structured-output value and source metadata.
23
+ * @returns JSON-friendly structured-output artifact.
24
+ */
25
+ export declare function projectTypiaLlmStructuredOutputArtifact({ generatedFrom, structuredOutput, }: ProjectTypiaLlmStructuredOutputArtifactOptions): ProjectedTypiaLlmStructuredOutputArtifact;
@@ -0,0 +1,58 @@
1
+ import { cloneJsonValue } from './json-utils.js';
2
+ import { cloneJsonValueIfDefined } from './typia-llm-json-schema.js';
3
+ import { applyOpenApiConstraintsToTypiaLlmFunctionArtifact, cloneProjectedTypiaLlmFunctionArtifact, } from './typia-llm-openapi-constraints.js';
4
+ /**
5
+ * Projects one compiled `typia.llm` function schema into a JSON-friendly
6
+ * artifact record.
7
+ *
8
+ * @param functionSchema Function schema from a compiled `typia.llm.application(...)`.
9
+ * @returns JSON-friendly function artifact.
10
+ */
11
+ export function projectTypiaLlmApplicationFunction(functionSchema) {
12
+ return {
13
+ description: functionSchema.description,
14
+ name: functionSchema.name,
15
+ output: cloneJsonValueIfDefined(functionSchema.output),
16
+ parameters: cloneJsonValue(functionSchema.parameters),
17
+ ...(functionSchema.tags ? { tags: [...functionSchema.tags] } : {}),
18
+ };
19
+ }
20
+ /**
21
+ * Projects a compiled `typia.llm.application(...)` result into a JSON-friendly
22
+ * downstream adapter artifact.
23
+ *
24
+ * @param options Compiled application value and source metadata.
25
+ * @returns JSON-friendly application artifact.
26
+ */
27
+ export function projectTypiaLlmApplicationArtifact({ application, generatedFrom, openApiProjection, transformFunction, }) {
28
+ return {
29
+ functions: application.functions.map((functionSchema) => {
30
+ const functionArtifact = projectTypiaLlmApplicationFunction(functionSchema);
31
+ const openApiAlignedArtifact = openApiProjection
32
+ ? applyOpenApiConstraintsToTypiaLlmFunctionArtifact({
33
+ functionArtifact,
34
+ openApiDocument: openApiProjection.openApiDocument,
35
+ operationId: openApiProjection.resolveOperationId?.(functionSchema, functionArtifact) ?? functionSchema.name,
36
+ })
37
+ : functionArtifact;
38
+ const transformedArtifact = transformFunction
39
+ ? transformFunction(openApiAlignedArtifact, functionSchema)
40
+ : openApiAlignedArtifact;
41
+ return cloneProjectedTypiaLlmFunctionArtifact(transformedArtifact);
42
+ }),
43
+ generatedFrom: cloneJsonValue(generatedFrom),
44
+ };
45
+ }
46
+ /**
47
+ * Projects a compiled `typia.llm.structuredOutput(...)` result into a
48
+ * JSON-friendly downstream adapter artifact.
49
+ *
50
+ * @param options Compiled structured-output value and source metadata.
51
+ * @returns JSON-friendly structured-output artifact.
52
+ */
53
+ export function projectTypiaLlmStructuredOutputArtifact({ generatedFrom, structuredOutput, }) {
54
+ return {
55
+ generatedFrom: cloneJsonValue(generatedFrom),
56
+ parameters: cloneJsonValue(structuredOutput.parameters),
57
+ };
58
+ }
@@ -0,0 +1,21 @@
1
+ import type { EndpointManifestDefinition } from '@wp-typia/block-runtime/metadata-core';
2
+ import type { RenderTypiaLlmModuleOptions, TypiaLlmEndpointMethodDescriptor } from './typia-llm-types.js';
3
+ export declare function renderTypiaLlmModuleFromMethodDescriptors({ applicationExportName, interfaceName, structuredOutputExportName, structuredOutputTypeName, typesImportPath, }: Omit<RenderTypiaLlmModuleOptions, 'manifest'>, methods: readonly TypiaLlmEndpointMethodDescriptor[]): string;
4
+ /**
5
+ * Builds the generated controller method descriptors that bridge endpoint
6
+ * manifests to `typia.llm` TypeScript interfaces.
7
+ *
8
+ * @param manifest Endpoint manifest that owns operation and source type names.
9
+ * @returns Ordered method descriptors matching the manifest endpoints.
10
+ * @throws When an endpoint has ambiguous query/body input mapping.
11
+ * @throws When an endpoint references a missing input or output contract.
12
+ */
13
+ export declare function buildTypiaLlmEndpointMethodDescriptors(manifest: EndpointManifestDefinition): TypiaLlmEndpointMethodDescriptor[];
14
+ /**
15
+ * Renders a build-time-only TypeScript module that invokes `typia.llm` against
16
+ * canonical manifest-owned contracts.
17
+ *
18
+ * @param options Render options for the generated adapter module.
19
+ * @returns The generated TypeScript source.
20
+ */
21
+ export declare function renderTypiaLlmModule({ applicationExportName, interfaceName, manifest, structuredOutputExportName, structuredOutputTypeName, typesImportPath, }: RenderTypiaLlmModuleOptions): string;
@@ -0,0 +1,252 @@
1
+ import { normalizeEndpointAuthDefinition } from './schema-core.js';
2
+ const TYPESCRIPT_RESERVED_WORDS = new Set([
3
+ 'abstract',
4
+ 'any',
5
+ 'as',
6
+ 'asserts',
7
+ 'async',
8
+ 'await',
9
+ 'bigint',
10
+ 'boolean',
11
+ 'break',
12
+ 'case',
13
+ 'catch',
14
+ 'class',
15
+ 'const',
16
+ 'constructor',
17
+ 'continue',
18
+ 'debugger',
19
+ 'declare',
20
+ 'default',
21
+ 'delete',
22
+ 'do',
23
+ 'else',
24
+ 'enum',
25
+ 'export',
26
+ 'extends',
27
+ 'false',
28
+ 'finally',
29
+ 'for',
30
+ 'from',
31
+ 'function',
32
+ 'get',
33
+ 'global',
34
+ 'if',
35
+ 'implements',
36
+ 'import',
37
+ 'in',
38
+ 'infer',
39
+ 'instanceof',
40
+ 'interface',
41
+ 'is',
42
+ 'keyof',
43
+ 'let',
44
+ 'module',
45
+ 'namespace',
46
+ 'never',
47
+ 'new',
48
+ 'null',
49
+ 'number',
50
+ 'object',
51
+ 'of',
52
+ 'package',
53
+ 'private',
54
+ 'protected',
55
+ 'public',
56
+ 'readonly',
57
+ 'require',
58
+ 'return',
59
+ 'satisfies',
60
+ 'set',
61
+ 'static',
62
+ 'string',
63
+ 'super',
64
+ 'switch',
65
+ 'symbol',
66
+ 'this',
67
+ 'throw',
68
+ 'true',
69
+ 'try',
70
+ 'type',
71
+ 'typeof',
72
+ 'undefined',
73
+ 'unique',
74
+ 'unknown',
75
+ 'var',
76
+ 'void',
77
+ 'while',
78
+ 'with',
79
+ 'yield',
80
+ ]);
81
+ function getContractSourceTypeName(manifest, endpoint, contractName) {
82
+ const contract = manifest.contracts[contractName];
83
+ if (!contract) {
84
+ throw new Error(`Endpoint "${endpoint.operationId}" references missing input contract "${contractName}".`);
85
+ }
86
+ return contract.sourceTypeName;
87
+ }
88
+ function getEndpointInputTypeDescriptor(manifest, endpoint) {
89
+ if (endpoint.bodyContract && endpoint.queryContract) {
90
+ const bodyTypeName = getContractSourceTypeName(manifest, endpoint, endpoint.bodyContract);
91
+ const queryTypeName = getContractSourceTypeName(manifest, endpoint, endpoint.queryContract);
92
+ return {
93
+ importTypeNames: [bodyTypeName, queryTypeName],
94
+ signatureTypeName: `{ body: ${bodyTypeName}; query: ${queryTypeName} }`,
95
+ };
96
+ }
97
+ const contractName = endpoint.method === 'GET'
98
+ ? endpoint.queryContract ?? null
99
+ : endpoint.bodyContract ?? endpoint.queryContract ?? null;
100
+ if (!contractName) {
101
+ return {
102
+ importTypeNames: [],
103
+ signatureTypeName: null,
104
+ };
105
+ }
106
+ const sourceTypeName = getContractSourceTypeName(manifest, endpoint, contractName);
107
+ return {
108
+ importTypeNames: [sourceTypeName],
109
+ signatureTypeName: sourceTypeName,
110
+ };
111
+ }
112
+ function getEndpointOutputTypeName(manifest, endpoint) {
113
+ const contract = manifest.contracts[endpoint.responseContract];
114
+ if (!contract) {
115
+ throw new Error(`Endpoint "${endpoint.operationId}" references missing response contract "${endpoint.responseContract}".`);
116
+ }
117
+ return contract.sourceTypeName;
118
+ }
119
+ function escapeJsDocLine(line) {
120
+ return line.replace(/\*\//g, '* /');
121
+ }
122
+ function renderDescriptionJsDocLines(method) {
123
+ const description = method.description && method.description.trim().length > 0
124
+ ? method.description
125
+ : method.operationId;
126
+ const descriptionLines = description
127
+ .replace(/\r\n?/g, '\n')
128
+ .split('\n')
129
+ .map((line) => line.trim().replace(/\s+/g, ' '))
130
+ .filter(Boolean);
131
+ return (descriptionLines.length > 0
132
+ ? descriptionLines
133
+ : [method.operationId]).map((line) => ` * ${escapeJsDocLine(line)}`);
134
+ }
135
+ function renderMethodJsDoc(method) {
136
+ const lines = [
137
+ '/**',
138
+ ...renderDescriptionJsDocLines(method),
139
+ ' *',
140
+ ` * REST path: ${method.method} ${method.path}`,
141
+ ` * Auth intent: ${method.authIntent}`,
142
+ ...(method.wordpressAuth
143
+ ? [
144
+ ` * WordPress auth: ${method.wordpressAuth.mechanism}${method.wordpressAuth.publicTokenField
145
+ ? ` (field: ${method.wordpressAuth.publicTokenField})`
146
+ : ''}`,
147
+ ]
148
+ : []),
149
+ ...method.tags.map((tag) => ` * @tag ${escapeJsDocLine(tag)}`),
150
+ ' */',
151
+ ];
152
+ return lines.join('\n');
153
+ }
154
+ function renderMethodSignature(method) {
155
+ const inputSignature = method.inputTypeName === null ? '' : `input: ${method.inputTypeName}`;
156
+ const methodName = /^[$A-Z_][$0-9A-Z_]*$/i.test(method.operationId) &&
157
+ !TYPESCRIPT_RESERVED_WORDS.has(method.operationId)
158
+ ? method.operationId
159
+ : JSON.stringify(method.operationId);
160
+ return `${methodName}(${inputSignature}): ${method.outputTypeName};`;
161
+ }
162
+ export function renderTypiaLlmModuleFromMethodDescriptors({ applicationExportName, interfaceName, structuredOutputExportName, structuredOutputTypeName, typesImportPath, }, methods) {
163
+ const importedTypeNames = new Set([structuredOutputTypeName]);
164
+ for (const method of methods) {
165
+ importedTypeNames.add(method.outputTypeName);
166
+ if (method.inputTypeImportNames) {
167
+ for (const inputTypeImportName of method.inputTypeImportNames) {
168
+ importedTypeNames.add(inputTypeImportName);
169
+ }
170
+ }
171
+ else if (method.inputTypeName) {
172
+ importedTypeNames.add(method.inputTypeName);
173
+ }
174
+ }
175
+ const imports = Array.from(importedTypeNames).sort().join(',\n\t');
176
+ const methodBlocks = methods
177
+ .map((method) => {
178
+ const jsDoc = renderMethodJsDoc(method)
179
+ .split('\n')
180
+ .map((line) => `\t${line}`)
181
+ .join('\n');
182
+ return `${jsDoc}\n\t${renderMethodSignature(method)}`;
183
+ })
184
+ .join('\n\n');
185
+ return `import typia from "typia";
186
+ import type {
187
+ \t${imports},
188
+ } from "${typesImportPath}";
189
+
190
+ export interface ${interfaceName} {
191
+ ${methodBlocks}
192
+ }
193
+
194
+ export const ${applicationExportName} =
195
+ \ttypia.llm.application<${interfaceName}>();
196
+
197
+ export const ${structuredOutputExportName} =
198
+ \ttypia.llm.structuredOutput<${structuredOutputTypeName}>();
199
+ `;
200
+ }
201
+ /**
202
+ * Builds the generated controller method descriptors that bridge endpoint
203
+ * manifests to `typia.llm` TypeScript interfaces.
204
+ *
205
+ * @param manifest Endpoint manifest that owns operation and source type names.
206
+ * @returns Ordered method descriptors matching the manifest endpoints.
207
+ * @throws When an endpoint has ambiguous query/body input mapping.
208
+ * @throws When an endpoint references a missing input or output contract.
209
+ */
210
+ export function buildTypiaLlmEndpointMethodDescriptors(manifest) {
211
+ return manifest.endpoints.map((endpoint) => {
212
+ const normalizedAuth = normalizeEndpointAuthDefinition(endpoint);
213
+ const inputTypeDescriptor = getEndpointInputTypeDescriptor(manifest, endpoint);
214
+ const inputTypeName = inputTypeDescriptor.signatureTypeName;
215
+ const shouldUseInlineInputImports = inputTypeName !== null &&
216
+ inputTypeDescriptor.importTypeNames.length > 0 &&
217
+ inputTypeDescriptor.importTypeNames[0] !== inputTypeName;
218
+ return {
219
+ authIntent: normalizedAuth.auth,
220
+ ...(normalizedAuth.authMode ? { authMode: normalizedAuth.authMode } : {}),
221
+ description: endpoint.summary,
222
+ inputTypeName,
223
+ ...(shouldUseInlineInputImports
224
+ ? { inputTypeImportNames: inputTypeDescriptor.importTypeNames }
225
+ : {}),
226
+ method: endpoint.method,
227
+ operationId: endpoint.operationId,
228
+ outputTypeName: getEndpointOutputTypeName(manifest, endpoint),
229
+ path: endpoint.path,
230
+ tags: endpoint.tags ?? [],
231
+ ...(normalizedAuth.wordpressAuth
232
+ ? { wordpressAuth: normalizedAuth.wordpressAuth }
233
+ : {}),
234
+ };
235
+ });
236
+ }
237
+ /**
238
+ * Renders a build-time-only TypeScript module that invokes `typia.llm` against
239
+ * canonical manifest-owned contracts.
240
+ *
241
+ * @param options Render options for the generated adapter module.
242
+ * @returns The generated TypeScript source.
243
+ */
244
+ export function renderTypiaLlmModule({ applicationExportName, interfaceName, manifest, structuredOutputExportName, structuredOutputTypeName, typesImportPath, }) {
245
+ return renderTypiaLlmModuleFromMethodDescriptors({
246
+ applicationExportName,
247
+ interfaceName,
248
+ structuredOutputExportName,
249
+ structuredOutputTypeName,
250
+ typesImportPath,
251
+ }, buildTypiaLlmEndpointMethodDescriptors(manifest));
252
+ }
@@ -0,0 +1,10 @@
1
+ import type { SyncTypiaLlmAdapterModuleOptions, SyncTypiaLlmAdapterModuleResult } from './typia-llm-types.js';
2
+ /**
3
+ * Writes or verifies the generated build-time `typia.llm` adapter module. The
4
+ * returned TypeScript source still needs to be compiled by the consuming
5
+ * project's Typia transformer before JSON artifacts can be read from it.
6
+ *
7
+ * @param options Generated module destination plus render options.
8
+ * @returns Rendered source, method descriptors, and the checked/written file path.
9
+ */
10
+ export declare function syncTypiaLlmAdapterModule({ check, generatedSourceFile, ...renderOptions }: SyncTypiaLlmAdapterModuleOptions): Promise<SyncTypiaLlmAdapterModuleResult>;
@@ -0,0 +1,63 @@
1
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { getOptionalNodeErrorCode, isFileNotFoundError, } from './fs-async.js';
4
+ import { buildTypiaLlmEndpointMethodDescriptors, renderTypiaLlmModuleFromMethodDescriptors, } from './typia-llm-render.js';
5
+ function normalizeGeneratedArtifactContent(content) {
6
+ return content.replace(/\r\n?/g, '\n');
7
+ }
8
+ async function reconcileGeneratedTypiaLlmArtifacts(artifacts, check) {
9
+ if (!check) {
10
+ for (const artifact of artifacts) {
11
+ await mkdir(path.dirname(artifact.filePath), {
12
+ recursive: true,
13
+ });
14
+ await writeFile(artifact.filePath, artifact.content, 'utf8');
15
+ }
16
+ return;
17
+ }
18
+ const issues = [];
19
+ for (const artifact of artifacts) {
20
+ try {
21
+ const current = normalizeGeneratedArtifactContent(await readFile(artifact.filePath, 'utf8'));
22
+ const expected = normalizeGeneratedArtifactContent(artifact.content);
23
+ if (current !== expected) {
24
+ issues.push(`- ${artifact.filePath} (stale)`);
25
+ }
26
+ }
27
+ catch (error) {
28
+ if (isFileNotFoundError(error)) {
29
+ issues.push(`- ${artifact.filePath} (missing)`);
30
+ continue;
31
+ }
32
+ const code = getOptionalNodeErrorCode(error);
33
+ issues.push(`- ${artifact.filePath} (unreadable: ${error instanceof Error ? error.message : code ?? 'unknown'})`);
34
+ }
35
+ }
36
+ if (issues.length > 0) {
37
+ throw new Error(`Generated typia.llm artifacts are missing or stale:\n${issues.join('\n')}`);
38
+ }
39
+ }
40
+ /**
41
+ * Writes or verifies the generated build-time `typia.llm` adapter module. The
42
+ * returned TypeScript source still needs to be compiled by the consuming
43
+ * project's Typia transformer before JSON artifacts can be read from it.
44
+ *
45
+ * @param options Generated module destination plus render options.
46
+ * @returns Rendered source, method descriptors, and the checked/written file path.
47
+ */
48
+ export async function syncTypiaLlmAdapterModule({ check = false, generatedSourceFile, ...renderOptions }) {
49
+ const methodDescriptors = buildTypiaLlmEndpointMethodDescriptors(renderOptions.manifest);
50
+ const source = renderTypiaLlmModuleFromMethodDescriptors(renderOptions, methodDescriptors);
51
+ await reconcileGeneratedTypiaLlmArtifacts([
52
+ {
53
+ content: source,
54
+ filePath: generatedSourceFile,
55
+ },
56
+ ], check);
57
+ return {
58
+ check,
59
+ methodDescriptors,
60
+ source,
61
+ sourceFile: generatedSourceFile,
62
+ };
63
+ }