@wp-typia/project-tools 0.23.1 → 0.24.1

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 (157) hide show
  1. package/dist/runtime/built-in-block-non-ts-basic-artifacts.d.ts +9 -0
  2. package/dist/runtime/built-in-block-non-ts-basic-artifacts.js +84 -0
  3. package/dist/runtime/built-in-block-non-ts-compound-artifacts.d.ts +9 -0
  4. package/dist/runtime/built-in-block-non-ts-compound-artifacts.js +36 -0
  5. package/dist/runtime/built-in-block-non-ts-compound-templates.d.ts +23 -0
  6. package/dist/runtime/built-in-block-non-ts-compound-templates.js +453 -0
  7. package/dist/runtime/built-in-block-non-ts-family-artifacts.d.ts +8 -26
  8. package/dist/runtime/built-in-block-non-ts-family-artifacts.js +8 -1034
  9. package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.d.ts +9 -0
  10. package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.js +83 -0
  11. package/dist/runtime/built-in-block-non-ts-persistence-artifacts.d.ts +9 -0
  12. package/dist/runtime/built-in-block-non-ts-persistence-artifacts.js +33 -0
  13. package/dist/runtime/built-in-block-non-ts-persistence-templates.d.ts +23 -0
  14. package/dist/runtime/built-in-block-non-ts-persistence-templates.js +395 -0
  15. package/dist/runtime/cli-add-collision.js +8 -0
  16. package/dist/runtime/cli-add-help.js +11 -7
  17. package/dist/runtime/cli-add-kind-ids.d.ts +1 -1
  18. package/dist/runtime/cli-add-kind-ids.js +1 -0
  19. package/dist/runtime/cli-add-types.d.ts +28 -1
  20. package/dist/runtime/cli-add-types.js +2 -0
  21. package/dist/runtime/cli-add-workspace-ability-anchors.d.ts +24 -0
  22. package/dist/runtime/cli-add-workspace-ability-anchors.js +294 -0
  23. package/dist/runtime/cli-add-workspace-ability-registry.d.ts +10 -0
  24. package/dist/runtime/cli-add-workspace-ability-registry.js +51 -0
  25. package/dist/runtime/cli-add-workspace-ability-scaffold.d.ts +1 -1
  26. package/dist/runtime/cli-add-workspace-ability-scaffold.js +5 -311
  27. package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +1 -1
  28. package/dist/runtime/cli-add-workspace-ai-anchors.d.ts +4 -4
  29. package/dist/runtime/cli-add-workspace-ai-anchors.js +4 -232
  30. package/dist/runtime/cli-add-workspace-ai-scaffold.js +4 -2
  31. package/dist/runtime/cli-add-workspace-ai-source-emitters.d.ts +1 -4
  32. package/dist/runtime/cli-add-workspace-ai-source-emitters.js +3 -171
  33. package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.d.ts +5 -0
  34. package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.js +236 -0
  35. package/dist/runtime/cli-add-workspace-ai-sync-script-source.d.ts +4 -0
  36. package/dist/runtime/cli-add-workspace-ai-sync-script-source.js +145 -0
  37. package/dist/runtime/cli-add-workspace-assets.d.ts +6 -63
  38. package/dist/runtime/cli-add-workspace-assets.js +6 -950
  39. package/dist/runtime/cli-add-workspace-binding-source-anchors.d.ts +23 -0
  40. package/dist/runtime/cli-add-workspace-binding-source-anchors.js +112 -0
  41. package/dist/runtime/cli-add-workspace-binding-source-source-emitters.d.ts +33 -0
  42. package/dist/runtime/cli-add-workspace-binding-source-source-emitters.js +436 -0
  43. package/dist/runtime/cli-add-workspace-binding-source-types.d.ts +20 -0
  44. package/dist/runtime/cli-add-workspace-binding-source-types.js +1 -0
  45. package/dist/runtime/cli-add-workspace-binding-source.d.ts +40 -0
  46. package/dist/runtime/cli-add-workspace-binding-source.js +275 -0
  47. package/dist/runtime/cli-add-workspace-block-style.d.ts +22 -0
  48. package/dist/runtime/cli-add-workspace-block-style.js +148 -0
  49. package/dist/runtime/cli-add-workspace-block-transform.d.ts +32 -0
  50. package/dist/runtime/cli-add-workspace-block-transform.js +197 -0
  51. package/dist/runtime/cli-add-workspace-contract.js +1 -1
  52. package/dist/runtime/cli-add-workspace-core-variation.d.ts +22 -0
  53. package/dist/runtime/cli-add-workspace-core-variation.js +429 -0
  54. package/dist/runtime/cli-add-workspace-editor-plugin-anchors.d.ts +37 -0
  55. package/dist/runtime/cli-add-workspace-editor-plugin-anchors.js +206 -0
  56. package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.d.ts +47 -0
  57. package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.js +219 -0
  58. package/dist/runtime/cli-add-workspace-editor-plugin.d.ts +22 -0
  59. package/dist/runtime/cli-add-workspace-editor-plugin.js +78 -0
  60. package/dist/runtime/cli-add-workspace-hooked-block.d.ts +23 -0
  61. package/dist/runtime/cli-add-workspace-hooked-block.js +57 -0
  62. package/dist/runtime/cli-add-workspace-integration-env-files.d.ts +33 -0
  63. package/dist/runtime/cli-add-workspace-integration-env-files.js +65 -0
  64. package/dist/runtime/cli-add-workspace-integration-env-package-json.d.ts +38 -0
  65. package/dist/runtime/cli-add-workspace-integration-env-package-json.js +122 -0
  66. package/dist/runtime/cli-add-workspace-integration-env-source-emitters.d.ts +44 -0
  67. package/dist/runtime/cli-add-workspace-integration-env-source-emitters.js +262 -0
  68. package/dist/runtime/cli-add-workspace-integration-env.js +5 -345
  69. package/dist/runtime/cli-add-workspace-pattern-anchors.d.ts +10 -0
  70. package/dist/runtime/cli-add-workspace-pattern-anchors.js +95 -0
  71. package/dist/runtime/cli-add-workspace-pattern-options.d.ts +20 -0
  72. package/dist/runtime/cli-add-workspace-pattern-options.js +113 -0
  73. package/dist/runtime/cli-add-workspace-pattern-source-emitters.d.ts +20 -0
  74. package/dist/runtime/cli-add-workspace-pattern-source-emitters.js +57 -0
  75. package/dist/runtime/cli-add-workspace-pattern.d.ts +42 -0
  76. package/dist/runtime/cli-add-workspace-pattern.js +99 -0
  77. package/dist/runtime/cli-add-workspace-post-meta.js +1 -1
  78. package/dist/runtime/cli-add-workspace-registration-hooks.d.ts +50 -0
  79. package/dist/runtime/cli-add-workspace-registration-hooks.js +162 -0
  80. package/dist/runtime/cli-add-workspace-rest-anchors.d.ts +6 -9
  81. package/dist/runtime/cli-add-workspace-rest-anchors.js +6 -466
  82. package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.d.ts +17 -0
  83. package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.js +108 -0
  84. package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.d.ts +9 -0
  85. package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.js +142 -0
  86. package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.d.ts +51 -0
  87. package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.js +415 -0
  88. package/dist/runtime/cli-add-workspace-rest-generated.js +5 -3
  89. package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.d.ts +80 -0
  90. package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.js +238 -0
  91. package/dist/runtime/cli-add-workspace-rest-manual.js +3 -16
  92. package/dist/runtime/cli-add-workspace-rest-php-templates.d.ts +1 -7
  93. package/dist/runtime/cli-add-workspace-rest-php-templates.js +3 -322
  94. package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.d.ts +33 -0
  95. package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.js +145 -0
  96. package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.d.ts +9 -0
  97. package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.js +162 -0
  98. package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.d.ts +7 -0
  99. package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.js +193 -0
  100. package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +5 -99
  101. package/dist/runtime/cli-add-workspace-rest-source-emitters.js +5 -663
  102. package/dist/runtime/cli-add-workspace-rest-source-utils.d.ts +17 -0
  103. package/dist/runtime/cli-add-workspace-rest-source-utils.js +50 -0
  104. package/dist/runtime/cli-add-workspace-rest-sync-script-shared.d.ts +56 -0
  105. package/dist/runtime/cli-add-workspace-rest-sync-script-shared.js +122 -0
  106. package/dist/runtime/cli-add-workspace-rest-types.d.ts +3 -3
  107. package/dist/runtime/cli-add-workspace-variation.d.ts +22 -0
  108. package/dist/runtime/cli-add-workspace-variation.js +162 -0
  109. package/dist/runtime/cli-add-workspace.d.ts +42 -107
  110. package/dist/runtime/cli-add-workspace.js +42 -674
  111. package/dist/runtime/cli-add.d.ts +3 -3
  112. package/dist/runtime/cli-add.js +2 -2
  113. package/dist/runtime/cli-core.d.ts +2 -1
  114. package/dist/runtime/cli-core.js +1 -1
  115. package/dist/runtime/cli-doctor-workspace-bindings.js +59 -0
  116. package/dist/runtime/cli-doctor-workspace-block-addons.js +33 -5
  117. package/dist/runtime/cli-doctor.d.ts +2 -0
  118. package/dist/runtime/cli-doctor.js +13 -2
  119. package/dist/runtime/cli-help.js +7 -4
  120. package/dist/runtime/index.d.ts +5 -2
  121. package/dist/runtime/index.js +4 -2
  122. package/dist/runtime/json-utils.d.ts +2 -5
  123. package/dist/runtime/json-utils.js +2 -5
  124. package/dist/runtime/local-dev-presets.js +2 -1
  125. package/dist/runtime/package-versions.d.ts +1 -0
  126. package/dist/runtime/package-versions.js +15 -8
  127. package/dist/runtime/pattern-catalog-section-roles.d.ts +101 -0
  128. package/dist/runtime/pattern-catalog-section-roles.js +276 -0
  129. package/dist/runtime/pattern-catalog.d.ts +67 -0
  130. package/dist/runtime/pattern-catalog.js +225 -0
  131. package/dist/runtime/post-meta-binding-fields.d.ts +46 -0
  132. package/dist/runtime/post-meta-binding-fields.js +135 -0
  133. package/dist/runtime/template-source-cache-markers.js +7 -2
  134. package/dist/runtime/typia-llm-json-schema.d.ts +24 -0
  135. package/dist/runtime/typia-llm-json-schema.js +33 -0
  136. package/dist/runtime/typia-llm-openapi-constraints.d.ts +20 -0
  137. package/dist/runtime/typia-llm-openapi-constraints.js +254 -0
  138. package/dist/runtime/typia-llm-projection.d.ts +25 -0
  139. package/dist/runtime/typia-llm-projection.js +58 -0
  140. package/dist/runtime/typia-llm-render.d.ts +21 -0
  141. package/dist/runtime/typia-llm-render.js +252 -0
  142. package/dist/runtime/typia-llm-sync.d.ts +10 -0
  143. package/dist/runtime/typia-llm-sync.js +63 -0
  144. package/dist/runtime/typia-llm-types.d.ts +197 -0
  145. package/dist/runtime/typia-llm-types.js +1 -0
  146. package/dist/runtime/typia-llm.d.ts +9 -255
  147. package/dist/runtime/typia-llm.js +5 -634
  148. package/dist/runtime/workspace-inventory-mutations.js +13 -0
  149. package/dist/runtime/workspace-inventory-section-descriptors.js +9 -1
  150. package/dist/runtime/workspace-inventory-templates.d.ts +2 -2
  151. package/dist/runtime/workspace-inventory-templates.js +9 -1
  152. package/dist/runtime/workspace-inventory-types.d.ts +9 -1
  153. package/package.json +8 -3
  154. package/templates/_shared/compound/core/scripts/block-config.ts.mustache +22 -0
  155. package/templates/_shared/compound/core/scripts/sync-types-to-block-json.ts.mustache +103 -2
  156. package/templates/_shared/compound/core/src/inner-blocks-templates.ts.mustache +13 -0
  157. package/templates/_shared/compound/persistence/scripts/block-config.ts.mustache +22 -1
@@ -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
+ }
@@ -0,0 +1,197 @@
1
+ import type { ArtifactSyncExecutionOptions, EndpointManifestDefinition, EndpointManifestEndpointDefinition } from '@wp-typia/block-runtime/metadata-core';
2
+ import type { ILlmFunction, ILlmSchema, ILlmStructuredOutput } from 'typia';
3
+ import type { EndpointAuthIntent, EndpointWordPressAuthDefinition, OpenApiDocument } from './schema-core.js';
4
+ /**
5
+ * Method-level descriptor projected from an endpoint manifest for a generated
6
+ * `typia.llm` controller interface.
7
+ */
8
+ export interface TypiaLlmEndpointMethodDescriptor {
9
+ /** Normalized auth intent derived from the endpoint manifest. */
10
+ authIntent: EndpointAuthIntent;
11
+ /** Optional auth mode propagated from legacy manifest metadata. */
12
+ authMode?: EndpointManifestEndpointDefinition['authMode'];
13
+ /** Human-readable operation summary. */
14
+ description?: string;
15
+ /** Input type used by the generated controller method, or null for no input. */
16
+ inputTypeName: string | null;
17
+ /** Type names that must be imported when inputTypeName is an inline composite. */
18
+ inputTypeImportNames?: readonly string[];
19
+ /** HTTP method from the source endpoint manifest. */
20
+ method: EndpointManifestEndpointDefinition['method'];
21
+ /** Stable operation identifier used as the generated method name. */
22
+ operationId: string;
23
+ /** Output type used by the generated controller method. */
24
+ outputTypeName: string;
25
+ /** REST path from the source endpoint manifest. */
26
+ path: string;
27
+ /** Tags copied from the source endpoint manifest. */
28
+ tags: readonly string[];
29
+ /** Optional WordPress auth overlay preserved for downstream adapters. */
30
+ wordpressAuth?: EndpointWordPressAuthDefinition;
31
+ }
32
+ /**
33
+ * Configures the generated TypeScript module that asks `typia.llm` to derive
34
+ * function-calling and structured-output artifacts from canonical contracts.
35
+ */
36
+ export interface RenderTypiaLlmModuleOptions {
37
+ /** Export name for the generated `typia.llm.application<...>()` value. */
38
+ applicationExportName: string;
39
+ /** Generated controller interface name. */
40
+ interfaceName: string;
41
+ /** Endpoint manifest that owns REST operation metadata and source type names. */
42
+ manifest: EndpointManifestDefinition;
43
+ /** Export name for the generated `typia.llm.structuredOutput<...>()` value. */
44
+ structuredOutputExportName: string;
45
+ /** TypeScript output type used for structured-output projection. */
46
+ structuredOutputTypeName: string;
47
+ /** Import path from the generated module to the canonical TypeScript contracts. */
48
+ typesImportPath: string;
49
+ }
50
+ /**
51
+ * Configures writing or checking the generated `typia.llm` adapter module.
52
+ */
53
+ export interface SyncTypiaLlmAdapterModuleOptions extends ArtifactSyncExecutionOptions, RenderTypiaLlmModuleOptions {
54
+ /** Destination path for the generated TypeScript adapter module. */
55
+ generatedSourceFile: string;
56
+ }
57
+ /**
58
+ * Describes the generated adapter module and where it was written or checked.
59
+ */
60
+ export interface SyncTypiaLlmAdapterModuleResult {
61
+ /** True when the source file was only verified, false when it was written. */
62
+ check: boolean;
63
+ /** Generated endpoint method descriptors used by the module renderer. */
64
+ methodDescriptors: TypiaLlmEndpointMethodDescriptor[];
65
+ /** Rendered TypeScript module source. */
66
+ source: string;
67
+ /** Destination path for the generated TypeScript adapter module. */
68
+ sourceFile: string;
69
+ }
70
+ /**
71
+ * Function schema shape projected from a compiled `typia.llm.application(...)`
72
+ * result.
73
+ */
74
+ export interface TypiaLlmFunctionLike extends Pick<ILlmFunction, 'description' | 'name' | 'output' | 'parameters'> {
75
+ /** Function description generated by `typia.llm`. */
76
+ description?: string;
77
+ /** Function name generated by `typia.llm`. */
78
+ name: string;
79
+ /** Optional output schema generated by `typia.llm`. */
80
+ output?: ILlmSchema.IParameters;
81
+ /** Function parameter schema generated by `typia.llm`. */
82
+ parameters: ILlmSchema.IParameters;
83
+ /** Optional tags generated by `typia.llm`. */
84
+ tags?: readonly string[];
85
+ }
86
+ /**
87
+ * Application shape projected from a compiled `typia.llm.application(...)`
88
+ * result.
89
+ */
90
+ export interface TypiaLlmApplicationLike {
91
+ /** Function schemas generated by `typia.llm`. */
92
+ functions: readonly TypiaLlmFunctionLike[];
93
+ }
94
+ /**
95
+ * Structured-output shape projected from a compiled
96
+ * `typia.llm.structuredOutput(...)` result.
97
+ */
98
+ export interface TypiaLlmStructuredOutputLike extends Pick<ILlmStructuredOutput, 'parameters'> {
99
+ /** Structured output parameters generated by `typia.llm`. */
100
+ parameters: ILlmStructuredOutput['parameters'];
101
+ }
102
+ /**
103
+ * JSON-friendly function artifact for downstream adapter consumers.
104
+ */
105
+ export interface ProjectedTypiaLlmFunctionArtifact {
106
+ /** Function description generated by `typia.llm`. */
107
+ description?: string;
108
+ /** Function name generated by `typia.llm`. */
109
+ name: string;
110
+ /** Optional output schema generated by `typia.llm`. */
111
+ output?: ILlmSchema.IParameters;
112
+ /** Function parameter schema generated by `typia.llm`. */
113
+ parameters: ILlmSchema.IParameters;
114
+ /** Optional tags generated by `typia.llm`. */
115
+ tags?: string[];
116
+ }
117
+ /**
118
+ * JSON-friendly application artifact for downstream adapter consumers.
119
+ */
120
+ export interface ProjectedTypiaLlmApplicationArtifact {
121
+ /** Function-calling artifacts generated by `typia.llm`. */
122
+ functions: ProjectedTypiaLlmFunctionArtifact[];
123
+ /** Source metadata that keeps the artifact tied to canonical contracts. */
124
+ generatedFrom: {
125
+ baselineOpenApiPath?: string;
126
+ blockSlug: string;
127
+ manifestSource: 'endpoint-manifest+typescript';
128
+ };
129
+ }
130
+ /**
131
+ * JSON-friendly structured-output artifact for downstream adapter consumers.
132
+ */
133
+ export interface ProjectedTypiaLlmStructuredOutputArtifact {
134
+ /** Source metadata that keeps the artifact tied to canonical contracts. */
135
+ generatedFrom: {
136
+ aiSchemaPath?: string;
137
+ blockSlug: string;
138
+ outputTypeName: string;
139
+ };
140
+ /** Structured output parameters generated by `typia.llm`. */
141
+ parameters: ILlmStructuredOutput['parameters'];
142
+ }
143
+ /**
144
+ * Configures optional OpenAPI-backed constraint restoration for projected
145
+ * `typia.llm` function artifacts.
146
+ */
147
+ export interface ProjectTypiaLlmOpenApiProjectionOptions {
148
+ /** Canonical endpoint-aware OpenAPI document for the projected contracts. */
149
+ openApiDocument: OpenApiDocument;
150
+ /** Optional override for resolving one function schema to an operation id. */
151
+ resolveOperationId?: (functionSchema: TypiaLlmFunctionLike, functionArtifact: ProjectedTypiaLlmFunctionArtifact) => string;
152
+ }
153
+ /**
154
+ * Configures projection of a compiled `typia.llm.application(...)` result into
155
+ * the JSON-friendly adapter artifact.
156
+ */
157
+ export interface ProjectTypiaLlmApplicationArtifactOptions {
158
+ /** Compiled application value produced by `typia.llm.application(...)`. */
159
+ application: TypiaLlmApplicationLike;
160
+ /** Source metadata for the generated JSON artifact. */
161
+ generatedFrom: ProjectedTypiaLlmApplicationArtifact['generatedFrom'];
162
+ /** Optional OpenAPI projection that restores canonical schema constraints. */
163
+ openApiProjection?: ProjectTypiaLlmOpenApiProjectionOptions;
164
+ /** Optional hook for adapter-specific function schema normalization. */
165
+ transformFunction?: (functionArtifact: ProjectedTypiaLlmFunctionArtifact, functionSchema: TypiaLlmFunctionLike) => ProjectedTypiaLlmFunctionArtifact;
166
+ }
167
+ /**
168
+ * Configures direct OpenAPI-backed constraint restoration for one projected
169
+ * function artifact.
170
+ */
171
+ export interface ApplyOpenApiConstraintsToTypiaLlmFunctionArtifactOptions {
172
+ /** Projected function artifact to enrich with canonical constraints. */
173
+ functionArtifact: ProjectedTypiaLlmFunctionArtifact;
174
+ /** Canonical endpoint-aware OpenAPI document. */
175
+ openApiDocument: OpenApiDocument;
176
+ /** Operation id that owns the request/response contract for this function. */
177
+ operationId: string;
178
+ }
179
+ /**
180
+ * Configures projection of a compiled `typia.llm.structuredOutput(...)` result
181
+ * into the JSON-friendly adapter artifact.
182
+ */
183
+ export interface ProjectTypiaLlmStructuredOutputArtifactOptions {
184
+ /** Source metadata for the generated JSON artifact. */
185
+ generatedFrom: ProjectedTypiaLlmStructuredOutputArtifact['generatedFrom'];
186
+ /** Compiled structured-output value produced by `typia.llm.structuredOutput(...)`. */
187
+ structuredOutput: TypiaLlmStructuredOutputLike;
188
+ }
189
+ /**
190
+ * Generated Typia LLM artifact payload and destination.
191
+ */
192
+ export type GeneratedTypiaLlmArtifactFile = {
193
+ /** File contents to write or compare. */
194
+ content: string;
195
+ /** Destination path for the generated artifact file. */
196
+ filePath: string;
197
+ };
@@ -0,0 +1 @@
1
+ export {};