@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.
- package/dist/runtime/ai-feature-artifacts.js +4 -1
- package/dist/runtime/block-generator-service-spec.js +2 -1
- package/dist/runtime/built-in-block-non-ts-basic-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-basic-artifacts.js +84 -0
- package/dist/runtime/built-in-block-non-ts-compound-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-compound-artifacts.js +36 -0
- package/dist/runtime/built-in-block-non-ts-compound-templates.d.ts +23 -0
- package/dist/runtime/built-in-block-non-ts-compound-templates.js +453 -0
- package/dist/runtime/built-in-block-non-ts-family-artifacts.d.ts +8 -26
- package/dist/runtime/built-in-block-non-ts-family-artifacts.js +8 -1034
- package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.js +83 -0
- package/dist/runtime/built-in-block-non-ts-persistence-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-persistence-artifacts.js +33 -0
- package/dist/runtime/built-in-block-non-ts-persistence-templates.d.ts +23 -0
- package/dist/runtime/built-in-block-non-ts-persistence-templates.js +395 -0
- package/dist/runtime/cli-add-block-json.js +5 -1
- package/dist/runtime/cli-add-collision.js +8 -0
- package/dist/runtime/cli-add-help.js +14 -10
- package/dist/runtime/cli-add-kind-ids.d.ts +1 -1
- package/dist/runtime/cli-add-kind-ids.js +1 -0
- package/dist/runtime/cli-add-types.d.ts +45 -6
- package/dist/runtime/cli-add-types.js +2 -0
- package/dist/runtime/cli-add-validation.d.ts +7 -0
- package/dist/runtime/cli-add-validation.js +9 -0
- package/dist/runtime/cli-add-workspace-ability-anchors.d.ts +24 -0
- package/dist/runtime/cli-add-workspace-ability-anchors.js +294 -0
- package/dist/runtime/cli-add-workspace-ability-registry.d.ts +10 -0
- package/dist/runtime/cli-add-workspace-ability-registry.js +51 -0
- package/dist/runtime/cli-add-workspace-ability-scaffold.d.ts +1 -1
- package/dist/runtime/cli-add-workspace-ability-scaffold.js +5 -308
- package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +6 -2
- package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.d.ts +34 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.js +483 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-default.d.ts +30 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-default.js +310 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-rest.d.ts +25 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-rest.js +124 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-settings.d.ts +34 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-settings.js +370 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-shared.d.ts +49 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-shared.js +259 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates.d.ts +18 -27
- package/dist/runtime/cli-add-workspace-admin-view-templates.js +30 -1326
- package/dist/runtime/cli-add-workspace-ai-anchors.d.ts +4 -4
- package/dist/runtime/cli-add-workspace-ai-anchors.js +8 -233
- package/dist/runtime/cli-add-workspace-ai-scaffold.js +4 -2
- package/dist/runtime/cli-add-workspace-ai-source-emitters.d.ts +1 -4
- package/dist/runtime/cli-add-workspace-ai-source-emitters.js +1 -129
- package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.d.ts +5 -0
- package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.js +236 -0
- package/dist/runtime/cli-add-workspace-ai-sync-script-source.d.ts +4 -0
- package/dist/runtime/cli-add-workspace-ai-sync-script-source.js +145 -0
- package/dist/runtime/cli-add-workspace-assets.d.ts +6 -63
- package/dist/runtime/cli-add-workspace-assets.js +6 -950
- package/dist/runtime/cli-add-workspace-binding-source-anchors.d.ts +23 -0
- package/dist/runtime/cli-add-workspace-binding-source-anchors.js +112 -0
- package/dist/runtime/cli-add-workspace-binding-source-source-emitters.d.ts +33 -0
- package/dist/runtime/cli-add-workspace-binding-source-source-emitters.js +436 -0
- package/dist/runtime/cli-add-workspace-binding-source-types.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-binding-source-types.js +1 -0
- package/dist/runtime/cli-add-workspace-binding-source.d.ts +40 -0
- package/dist/runtime/cli-add-workspace-binding-source.js +275 -0
- package/dist/runtime/cli-add-workspace-block-style.d.ts +22 -0
- package/dist/runtime/cli-add-workspace-block-style.js +148 -0
- package/dist/runtime/cli-add-workspace-block-transform.d.ts +32 -0
- package/dist/runtime/cli-add-workspace-block-transform.js +197 -0
- package/dist/runtime/cli-add-workspace-contract.js +1 -1
- package/dist/runtime/cli-add-workspace-core-variation.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-core-variation.js +322 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-anchors.d.ts +37 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-anchors.js +206 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.d.ts +47 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.js +219 -0
- package/dist/runtime/cli-add-workspace-editor-plugin.d.ts +22 -0
- package/dist/runtime/cli-add-workspace-editor-plugin.js +78 -0
- package/dist/runtime/cli-add-workspace-hooked-block.d.ts +23 -0
- package/dist/runtime/cli-add-workspace-hooked-block.js +57 -0
- package/dist/runtime/cli-add-workspace-integration-env-files.d.ts +33 -0
- package/dist/runtime/cli-add-workspace-integration-env-files.js +65 -0
- package/dist/runtime/cli-add-workspace-integration-env-package-json.d.ts +38 -0
- package/dist/runtime/cli-add-workspace-integration-env-package-json.js +122 -0
- package/dist/runtime/cli-add-workspace-integration-env-source-emitters.d.ts +44 -0
- package/dist/runtime/cli-add-workspace-integration-env-source-emitters.js +262 -0
- package/dist/runtime/cli-add-workspace-integration-env.d.ts +3 -1
- package/dist/runtime/cli-add-workspace-integration-env.js +10 -313
- package/dist/runtime/cli-add-workspace-pattern-anchors.d.ts +10 -0
- package/dist/runtime/cli-add-workspace-pattern-anchors.js +95 -0
- package/dist/runtime/cli-add-workspace-pattern-options.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-pattern-options.js +113 -0
- package/dist/runtime/cli-add-workspace-pattern-source-emitters.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-pattern-source-emitters.js +57 -0
- package/dist/runtime/cli-add-workspace-pattern.d.ts +42 -0
- package/dist/runtime/cli-add-workspace-pattern.js +99 -0
- package/dist/runtime/cli-add-workspace-post-meta.js +1 -1
- package/dist/runtime/cli-add-workspace-registration-hooks.d.ts +50 -0
- package/dist/runtime/cli-add-workspace-registration-hooks.js +162 -0
- package/dist/runtime/cli-add-workspace-rest-anchors.d.ts +9 -4
- package/dist/runtime/cli-add-workspace-rest-anchors.js +9 -428
- package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.d.ts +17 -0
- package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.js +108 -0
- package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.js +142 -0
- package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.d.ts +51 -0
- package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.js +415 -0
- package/dist/runtime/cli-add-workspace-rest-generated.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-generated.js +160 -0
- package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.d.ts +80 -0
- package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.js +238 -0
- package/dist/runtime/cli-add-workspace-rest-manual.d.ts +8 -0
- package/dist/runtime/cli-add-workspace-rest-manual.js +266 -0
- package/dist/runtime/cli-add-workspace-rest-php-templates.d.ts +18 -0
- package/dist/runtime/cli-add-workspace-rest-php-templates.js +359 -0
- package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.d.ts +33 -0
- package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.js +145 -0
- package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.js +162 -0
- package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.d.ts +7 -0
- package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.js +193 -0
- package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +5 -91
- package/dist/runtime/cli-add-workspace-rest-source-emitters.js +5 -642
- package/dist/runtime/cli-add-workspace-rest-source-utils.d.ts +17 -0
- package/dist/runtime/cli-add-workspace-rest-source-utils.js +50 -0
- package/dist/runtime/cli-add-workspace-rest-sync-script-shared.d.ts +56 -0
- package/dist/runtime/cli-add-workspace-rest-sync-script-shared.js +122 -0
- package/dist/runtime/cli-add-workspace-rest-types.d.ts +108 -0
- package/dist/runtime/cli-add-workspace-rest-types.js +1 -0
- package/dist/runtime/cli-add-workspace-rest.d.ts +3 -20
- package/dist/runtime/cli-add-workspace-rest.js +33 -788
- package/dist/runtime/cli-add-workspace-variation.d.ts +22 -0
- package/dist/runtime/cli-add-workspace-variation.js +162 -0
- package/dist/runtime/cli-add-workspace.d.ts +42 -107
- package/dist/runtime/cli-add-workspace.js +42 -674
- package/dist/runtime/cli-add.d.ts +3 -3
- package/dist/runtime/cli-add.js +2 -2
- package/dist/runtime/cli-core.d.ts +3 -2
- package/dist/runtime/cli-core.js +2 -2
- package/dist/runtime/cli-diagnostics.d.ts +3 -1
- package/dist/runtime/cli-diagnostics.js +17 -5
- package/dist/runtime/cli-doctor-workspace-bindings.js +63 -1
- package/dist/runtime/cli-doctor-workspace-block-addons.d.ts +12 -0
- package/dist/runtime/cli-doctor-workspace-block-addons.js +162 -0
- package/dist/runtime/cli-doctor-workspace-block-iframe.d.ts +9 -0
- package/dist/runtime/cli-doctor-workspace-block-iframe.js +228 -0
- package/dist/runtime/cli-doctor-workspace-block-metadata.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-block-metadata.js +111 -0
- package/dist/runtime/cli-doctor-workspace-blocks.js +6 -424
- package/dist/runtime/cli-doctor-workspace-features-abilities.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-abilities.js +112 -0
- package/dist/runtime/cli-doctor-workspace-features-admin-views.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-admin-views.js +128 -0
- package/dist/runtime/cli-doctor-workspace-features-ai.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-ai.js +57 -0
- package/dist/runtime/cli-doctor-workspace-features-editor-plugins.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-editor-plugins.js +80 -0
- package/dist/runtime/cli-doctor-workspace-features-post-meta.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-post-meta.js +77 -0
- package/dist/runtime/cli-doctor-workspace-features-rest.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-rest.js +120 -0
- package/dist/runtime/cli-doctor-workspace-features.js +14 -487
- package/dist/runtime/cli-doctor.d.ts +54 -3
- package/dist/runtime/cli-doctor.js +92 -10
- package/dist/runtime/cli-help.js +12 -7
- package/dist/runtime/cli-init-package-json.js +4 -2
- package/dist/runtime/cli-prompt.d.ts +16 -2
- package/dist/runtime/cli-prompt.js +29 -12
- package/dist/runtime/cli-scaffold.d.ts +2 -1
- package/dist/runtime/cli-scaffold.js +19 -10
- package/dist/runtime/external-template-guards.js +4 -6
- package/dist/runtime/index.d.ts +6 -3
- package/dist/runtime/index.js +4 -2
- package/dist/runtime/json-utils.d.ts +62 -4
- package/dist/runtime/json-utils.js +78 -4
- package/dist/runtime/local-dev-presets.js +6 -2
- package/dist/runtime/migration-ui-capability.js +4 -1
- package/dist/runtime/migration-utils.js +4 -1
- package/dist/runtime/package-managers.js +6 -1
- package/dist/runtime/package-versions.d.ts +1 -0
- package/dist/runtime/package-versions.js +16 -3
- package/dist/runtime/pattern-catalog.d.ts +122 -0
- package/dist/runtime/pattern-catalog.js +471 -0
- package/dist/runtime/post-meta-binding-fields.d.ts +46 -0
- package/dist/runtime/post-meta-binding-fields.js +135 -0
- package/dist/runtime/scaffold-bootstrap.js +7 -2
- package/dist/runtime/scaffold-package-manager-files.js +5 -1
- package/dist/runtime/scaffold-repository-reference.js +4 -2
- package/dist/runtime/scaffold-template-variables.js +2 -1
- package/dist/runtime/scaffold.d.ts +18 -1
- package/dist/runtime/scaffold.js +55 -2
- package/dist/runtime/temp-roots.js +4 -1
- package/dist/runtime/template-layers.js +4 -1
- package/dist/runtime/template-registry.js +9 -3
- package/dist/runtime/template-source-contracts.d.ts +2 -0
- package/dist/runtime/template-source-normalization.js +2 -1
- package/dist/runtime/template-source-remote.js +18 -5
- package/dist/runtime/template-source-seeds.js +10 -3
- package/dist/runtime/typia-llm-json-schema.d.ts +24 -0
- package/dist/runtime/typia-llm-json-schema.js +33 -0
- package/dist/runtime/typia-llm-openapi-constraints.d.ts +20 -0
- package/dist/runtime/typia-llm-openapi-constraints.js +254 -0
- package/dist/runtime/typia-llm-projection.d.ts +25 -0
- package/dist/runtime/typia-llm-projection.js +58 -0
- package/dist/runtime/typia-llm-render.d.ts +21 -0
- package/dist/runtime/typia-llm-render.js +252 -0
- package/dist/runtime/typia-llm-sync.d.ts +10 -0
- package/dist/runtime/typia-llm-sync.js +63 -0
- package/dist/runtime/typia-llm-types.d.ts +197 -0
- package/dist/runtime/typia-llm-types.js +1 -0
- package/dist/runtime/typia-llm.d.ts +9 -255
- package/dist/runtime/typia-llm.js +5 -634
- package/dist/runtime/workspace-inventory-mutations.js +15 -1
- package/dist/runtime/workspace-inventory-parser-entries.d.ts +17 -0
- package/dist/runtime/workspace-inventory-parser-entries.js +157 -0
- package/dist/runtime/workspace-inventory-parser-validation.d.ts +104 -0
- package/dist/runtime/workspace-inventory-parser-validation.js +34 -0
- package/dist/runtime/workspace-inventory-parser.d.ts +3 -45
- package/dist/runtime/workspace-inventory-parser.js +3 -581
- package/dist/runtime/workspace-inventory-section-descriptors.d.ts +19 -0
- package/dist/runtime/workspace-inventory-section-descriptors.js +443 -0
- package/dist/runtime/workspace-inventory-templates.d.ts +3 -3
- package/dist/runtime/workspace-inventory-templates.js +10 -1
- package/dist/runtime/workspace-inventory-types.d.ts +10 -1
- package/dist/runtime/workspace-project.js +4 -6
- package/package.json +8 -3
- package/templates/_shared/compound/core/scripts/block-config.ts.mustache +22 -0
- package/templates/_shared/compound/core/scripts/sync-types-to-block-json.ts.mustache +103 -2
- package/templates/_shared/compound/core/src/inner-blocks-templates.ts.mustache +13 -0
- package/templates/_shared/compound/persistence/scripts/block-config.ts.mustache +22 -1
|
@@ -1,634 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const TYPESCRIPT_RESERVED_WORDS = new Set([
|
|
7
|
-
'abstract',
|
|
8
|
-
'any',
|
|
9
|
-
'as',
|
|
10
|
-
'asserts',
|
|
11
|
-
'async',
|
|
12
|
-
'await',
|
|
13
|
-
'bigint',
|
|
14
|
-
'boolean',
|
|
15
|
-
'break',
|
|
16
|
-
'case',
|
|
17
|
-
'catch',
|
|
18
|
-
'class',
|
|
19
|
-
'const',
|
|
20
|
-
'constructor',
|
|
21
|
-
'continue',
|
|
22
|
-
'debugger',
|
|
23
|
-
'declare',
|
|
24
|
-
'default',
|
|
25
|
-
'delete',
|
|
26
|
-
'do',
|
|
27
|
-
'else',
|
|
28
|
-
'enum',
|
|
29
|
-
'export',
|
|
30
|
-
'extends',
|
|
31
|
-
'false',
|
|
32
|
-
'finally',
|
|
33
|
-
'for',
|
|
34
|
-
'from',
|
|
35
|
-
'function',
|
|
36
|
-
'get',
|
|
37
|
-
'global',
|
|
38
|
-
'if',
|
|
39
|
-
'implements',
|
|
40
|
-
'import',
|
|
41
|
-
'in',
|
|
42
|
-
'infer',
|
|
43
|
-
'instanceof',
|
|
44
|
-
'interface',
|
|
45
|
-
'is',
|
|
46
|
-
'keyof',
|
|
47
|
-
'let',
|
|
48
|
-
'module',
|
|
49
|
-
'namespace',
|
|
50
|
-
'never',
|
|
51
|
-
'new',
|
|
52
|
-
'null',
|
|
53
|
-
'number',
|
|
54
|
-
'object',
|
|
55
|
-
'of',
|
|
56
|
-
'package',
|
|
57
|
-
'private',
|
|
58
|
-
'protected',
|
|
59
|
-
'public',
|
|
60
|
-
'readonly',
|
|
61
|
-
'require',
|
|
62
|
-
'return',
|
|
63
|
-
'satisfies',
|
|
64
|
-
'set',
|
|
65
|
-
'static',
|
|
66
|
-
'string',
|
|
67
|
-
'super',
|
|
68
|
-
'switch',
|
|
69
|
-
'symbol',
|
|
70
|
-
'this',
|
|
71
|
-
'throw',
|
|
72
|
-
'true',
|
|
73
|
-
'try',
|
|
74
|
-
'type',
|
|
75
|
-
'typeof',
|
|
76
|
-
'undefined',
|
|
77
|
-
'unique',
|
|
78
|
-
'unknown',
|
|
79
|
-
'var',
|
|
80
|
-
'void',
|
|
81
|
-
'while',
|
|
82
|
-
'with',
|
|
83
|
-
'yield',
|
|
84
|
-
]);
|
|
85
|
-
const JSON_SCHEMA_CONSTRAINT_KEYS = [
|
|
86
|
-
'additionalProperties',
|
|
87
|
-
'const',
|
|
88
|
-
'default',
|
|
89
|
-
'enum',
|
|
90
|
-
'exclusiveMaximum',
|
|
91
|
-
'exclusiveMinimum',
|
|
92
|
-
'format',
|
|
93
|
-
'maxItems',
|
|
94
|
-
'maxLength',
|
|
95
|
-
'maximum',
|
|
96
|
-
'minItems',
|
|
97
|
-
'minLength',
|
|
98
|
-
'minimum',
|
|
99
|
-
'multipleOf',
|
|
100
|
-
'pattern',
|
|
101
|
-
'type',
|
|
102
|
-
];
|
|
103
|
-
function cloneJsonValueIfDefined(value) {
|
|
104
|
-
return value === undefined ? undefined : cloneJsonValue(value);
|
|
105
|
-
}
|
|
106
|
-
function isJsonSchemaObject(value) {
|
|
107
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Narrow a `typia.llm` artifact field before applying JSON Schema mutations.
|
|
111
|
-
*
|
|
112
|
-
* @param value Candidate schema value emitted by `typia.llm`.
|
|
113
|
-
* @param context Human-readable artifact path for diagnostics.
|
|
114
|
-
* @returns The value narrowed to the shared JSON Schema object shape.
|
|
115
|
-
*/
|
|
116
|
-
export function assertJsonSchemaObject(value, context) {
|
|
117
|
-
if (isJsonSchemaObject(value)) {
|
|
118
|
-
return value;
|
|
119
|
-
}
|
|
120
|
-
throw new Error(`${context} must be a JSON Schema object.`);
|
|
121
|
-
}
|
|
122
|
-
function decodeJsonPointerSegment(segment) {
|
|
123
|
-
return segment.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
124
|
-
}
|
|
125
|
-
function resolveOpenApiReferenceTarget(document, reference) {
|
|
126
|
-
if (!reference.startsWith('#/')) {
|
|
127
|
-
throw new Error(`Unsupported OpenAPI schema reference "${reference}".`);
|
|
128
|
-
}
|
|
129
|
-
let current = document;
|
|
130
|
-
for (const rawSegment of reference.slice(2).split('/')) {
|
|
131
|
-
const segment = decodeJsonPointerSegment(rawSegment);
|
|
132
|
-
if (Array.isArray(current)) {
|
|
133
|
-
const index = Number.parseInt(segment, 10);
|
|
134
|
-
current = Number.isInteger(index) ? current[index] : undefined;
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
if (!isJsonSchemaObject(current)) {
|
|
138
|
-
current = undefined;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
current = current[segment];
|
|
142
|
-
}
|
|
143
|
-
if (!isJsonSchemaObject(current)) {
|
|
144
|
-
throw new Error(`Unable to resolve OpenAPI schema reference "${reference}".`);
|
|
145
|
-
}
|
|
146
|
-
return current;
|
|
147
|
-
}
|
|
148
|
-
function resolveOpenApiSchemaObject(document, schema, seenReferences = new Set()) {
|
|
149
|
-
if (!isJsonSchemaObject(schema)) {
|
|
150
|
-
return {};
|
|
151
|
-
}
|
|
152
|
-
const reference = schema.$ref;
|
|
153
|
-
if (typeof reference !== 'string') {
|
|
154
|
-
return schema;
|
|
155
|
-
}
|
|
156
|
-
if (seenReferences.has(reference)) {
|
|
157
|
-
return schema;
|
|
158
|
-
}
|
|
159
|
-
return resolveOpenApiSchemaObject(document, resolveOpenApiReferenceTarget(document, reference), new Set([...seenReferences, reference]));
|
|
160
|
-
}
|
|
161
|
-
function collectOpenApiSeenReferences(schema, seenReferences) {
|
|
162
|
-
const reference = schema.$ref;
|
|
163
|
-
if (typeof reference !== 'string' || seenReferences.has(reference)) {
|
|
164
|
-
return seenReferences;
|
|
165
|
-
}
|
|
166
|
-
return new Set([...seenReferences, reference]);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Copy constraint-oriented JSON Schema keywords from `source` into `target`.
|
|
170
|
-
*
|
|
171
|
-
* This helper intentionally mutates and returns `target` so nested OpenAPI
|
|
172
|
-
* constraint restoration can preserve the projected typia.llm schema shape.
|
|
173
|
-
* Callers that need immutable behavior should clone the target before calling.
|
|
174
|
-
*/
|
|
175
|
-
function mergeJsonSchemaConstraintProperties(document, target, source, seenReferences = new Set()) {
|
|
176
|
-
const nextSeenReferences = collectOpenApiSeenReferences(source, seenReferences);
|
|
177
|
-
const resolvedSource = resolveOpenApiSchemaObject(document, source, seenReferences);
|
|
178
|
-
const merged = target;
|
|
179
|
-
for (const key of JSON_SCHEMA_CONSTRAINT_KEYS) {
|
|
180
|
-
if (resolvedSource[key] !== undefined) {
|
|
181
|
-
merged[key] = cloneJsonValue(resolvedSource[key]);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (Array.isArray(resolvedSource.required)) {
|
|
185
|
-
merged.required = resolvedSource.required.filter((value) => typeof value === 'string');
|
|
186
|
-
}
|
|
187
|
-
if (Array.isArray(resolvedSource.items)) {
|
|
188
|
-
merged.items = cloneJsonValue(resolvedSource.items);
|
|
189
|
-
}
|
|
190
|
-
else if (isJsonSchemaObject(resolvedSource.items)) {
|
|
191
|
-
const nextItems = isJsonSchemaObject(merged.items) ? merged.items : {};
|
|
192
|
-
merged.items = mergeJsonSchemaConstraintProperties(document, nextItems, resolvedSource.items, nextSeenReferences);
|
|
193
|
-
}
|
|
194
|
-
if (isJsonSchemaObject(resolvedSource.properties)) {
|
|
195
|
-
const targetProperties = isJsonSchemaObject(merged.properties)
|
|
196
|
-
? merged.properties
|
|
197
|
-
: {};
|
|
198
|
-
for (const [propertyName, propertySchema] of Object.entries(resolvedSource.properties)) {
|
|
199
|
-
if (!isJsonSchemaObject(propertySchema)) {
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
const nextProperty = isJsonSchemaObject(targetProperties[propertyName])
|
|
203
|
-
? targetProperties[propertyName]
|
|
204
|
-
: {};
|
|
205
|
-
targetProperties[propertyName] = mergeJsonSchemaConstraintProperties(document, nextProperty, propertySchema, nextSeenReferences);
|
|
206
|
-
}
|
|
207
|
-
merged.properties = targetProperties;
|
|
208
|
-
}
|
|
209
|
-
return merged;
|
|
210
|
-
}
|
|
211
|
-
function findOpenApiOperationById(document, operationId) {
|
|
212
|
-
for (const pathItem of Object.values(document.paths)) {
|
|
213
|
-
if (!isJsonSchemaObject(pathItem)) {
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
for (const method of ['delete', 'get', 'patch', 'post', 'put']) {
|
|
217
|
-
const operation = resolveOpenApiSchemaObject(document, pathItem[method]);
|
|
218
|
-
if (!isJsonSchemaObject(operation) ||
|
|
219
|
-
typeof operation.operationId !== 'string') {
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
if (operation.operationId === operationId) {
|
|
223
|
-
return operation;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
function resolveOpenApiRequestBodySchema(operation, document) {
|
|
230
|
-
const requestBody = resolveOpenApiSchemaObject(document, operation.requestBody);
|
|
231
|
-
const content = isJsonSchemaObject(requestBody.content)
|
|
232
|
-
? requestBody.content
|
|
233
|
-
: null;
|
|
234
|
-
const jsonMediaType = content && isJsonSchemaObject(content['application/json'])
|
|
235
|
-
? content['application/json']
|
|
236
|
-
: null;
|
|
237
|
-
const schema = jsonMediaType?.schema;
|
|
238
|
-
if (!isJsonSchemaObject(schema)) {
|
|
239
|
-
return null;
|
|
240
|
-
}
|
|
241
|
-
return resolveOpenApiSchemaObject(document, schema);
|
|
242
|
-
}
|
|
243
|
-
function resolveOpenApiSuccessResponseSchema(operation, document) {
|
|
244
|
-
for (const [statusCode, response] of Object.entries(operation.responses)) {
|
|
245
|
-
const resolvedResponse = resolveOpenApiSchemaObject(document, response);
|
|
246
|
-
if (!/^2(?:\d\d|XX)$/u.test(statusCode) ||
|
|
247
|
-
!isJsonSchemaObject(resolvedResponse)) {
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
const content = isJsonSchemaObject(resolvedResponse.content)
|
|
251
|
-
? resolvedResponse.content
|
|
252
|
-
: null;
|
|
253
|
-
const jsonMediaType = content && isJsonSchemaObject(content['application/json'])
|
|
254
|
-
? content['application/json']
|
|
255
|
-
: null;
|
|
256
|
-
const schema = jsonMediaType?.schema;
|
|
257
|
-
if (!isJsonSchemaObject(schema)) {
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
return resolveOpenApiSchemaObject(document, schema);
|
|
261
|
-
}
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
function getOrCreateObjectProperty(target, propertyName) {
|
|
265
|
-
const targetProperties = isJsonSchemaObject(target.properties)
|
|
266
|
-
? target.properties
|
|
267
|
-
: {};
|
|
268
|
-
const nextProperty = isJsonSchemaObject(targetProperties[propertyName])
|
|
269
|
-
? targetProperties[propertyName]
|
|
270
|
-
: {};
|
|
271
|
-
targetProperties[propertyName] = nextProperty;
|
|
272
|
-
target.properties = targetProperties;
|
|
273
|
-
return nextProperty;
|
|
274
|
-
}
|
|
275
|
-
function applyOpenApiQueryParameterConstraints(target, operation, document) {
|
|
276
|
-
for (const parameter of operation.parameters ?? []) {
|
|
277
|
-
const resolvedParameter = resolveOpenApiSchemaObject(document, parameter);
|
|
278
|
-
if (!isJsonSchemaObject(resolvedParameter) ||
|
|
279
|
-
resolvedParameter.in !== 'query' ||
|
|
280
|
-
typeof resolvedParameter.name !== 'string') {
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
const propertyTarget = getOrCreateObjectProperty(target, resolvedParameter.name);
|
|
284
|
-
mergeJsonSchemaConstraintProperties(document, propertyTarget, resolveOpenApiSchemaObject(document, resolvedParameter.schema));
|
|
285
|
-
if (resolvedParameter.required === true) {
|
|
286
|
-
const required = new Set(Array.isArray(target.required)
|
|
287
|
-
? target.required.filter((value) => typeof value === 'string')
|
|
288
|
-
: []);
|
|
289
|
-
required.add(resolvedParameter.name);
|
|
290
|
-
target.required = [...required];
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
function getContractSourceTypeName(manifest, endpoint, contractName) {
|
|
295
|
-
const contract = manifest.contracts[contractName];
|
|
296
|
-
if (!contract) {
|
|
297
|
-
throw new Error(`Endpoint "${endpoint.operationId}" references missing input contract "${contractName}".`);
|
|
298
|
-
}
|
|
299
|
-
return contract.sourceTypeName;
|
|
300
|
-
}
|
|
301
|
-
function getEndpointInputTypeDescriptor(manifest, endpoint) {
|
|
302
|
-
if (endpoint.bodyContract && endpoint.queryContract) {
|
|
303
|
-
const bodyTypeName = getContractSourceTypeName(manifest, endpoint, endpoint.bodyContract);
|
|
304
|
-
const queryTypeName = getContractSourceTypeName(manifest, endpoint, endpoint.queryContract);
|
|
305
|
-
return {
|
|
306
|
-
importTypeNames: [bodyTypeName, queryTypeName],
|
|
307
|
-
signatureTypeName: `{ body: ${bodyTypeName}; query: ${queryTypeName} }`,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
const contractName = endpoint.method === 'GET'
|
|
311
|
-
? endpoint.queryContract ?? null
|
|
312
|
-
: endpoint.bodyContract ?? endpoint.queryContract ?? null;
|
|
313
|
-
if (!contractName) {
|
|
314
|
-
return {
|
|
315
|
-
importTypeNames: [],
|
|
316
|
-
signatureTypeName: null,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
const sourceTypeName = getContractSourceTypeName(manifest, endpoint, contractName);
|
|
320
|
-
return {
|
|
321
|
-
importTypeNames: [sourceTypeName],
|
|
322
|
-
signatureTypeName: sourceTypeName,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
function getEndpointOutputTypeName(manifest, endpoint) {
|
|
326
|
-
const contract = manifest.contracts[endpoint.responseContract];
|
|
327
|
-
if (!contract) {
|
|
328
|
-
throw new Error(`Endpoint "${endpoint.operationId}" references missing response contract "${endpoint.responseContract}".`);
|
|
329
|
-
}
|
|
330
|
-
return contract.sourceTypeName;
|
|
331
|
-
}
|
|
332
|
-
function escapeJsDocLine(line) {
|
|
333
|
-
return line.replace(/\*\//g, '* /');
|
|
334
|
-
}
|
|
335
|
-
function normalizeGeneratedArtifactContent(content) {
|
|
336
|
-
return content.replace(/\r\n?/g, '\n');
|
|
337
|
-
}
|
|
338
|
-
function renderDescriptionJsDocLines(method) {
|
|
339
|
-
const description = method.description && method.description.trim().length > 0
|
|
340
|
-
? method.description
|
|
341
|
-
: method.operationId;
|
|
342
|
-
const descriptionLines = description
|
|
343
|
-
.replace(/\r\n?/g, '\n')
|
|
344
|
-
.split('\n')
|
|
345
|
-
.map((line) => line.trim().replace(/\s+/g, ' '))
|
|
346
|
-
.filter(Boolean);
|
|
347
|
-
return (descriptionLines.length > 0
|
|
348
|
-
? descriptionLines
|
|
349
|
-
: [method.operationId]).map((line) => ` * ${escapeJsDocLine(line)}`);
|
|
350
|
-
}
|
|
351
|
-
function renderMethodJsDoc(method) {
|
|
352
|
-
const lines = [
|
|
353
|
-
'/**',
|
|
354
|
-
...renderDescriptionJsDocLines(method),
|
|
355
|
-
' *',
|
|
356
|
-
` * REST path: ${method.method} ${method.path}`,
|
|
357
|
-
` * Auth intent: ${method.authIntent}`,
|
|
358
|
-
...(method.wordpressAuth
|
|
359
|
-
? [
|
|
360
|
-
` * WordPress auth: ${method.wordpressAuth.mechanism}${method.wordpressAuth.publicTokenField
|
|
361
|
-
? ` (field: ${method.wordpressAuth.publicTokenField})`
|
|
362
|
-
: ''}`,
|
|
363
|
-
]
|
|
364
|
-
: []),
|
|
365
|
-
...method.tags.map((tag) => ` * @tag ${escapeJsDocLine(tag)}`),
|
|
366
|
-
' */',
|
|
367
|
-
];
|
|
368
|
-
return lines.join('\n');
|
|
369
|
-
}
|
|
370
|
-
function renderMethodSignature(method) {
|
|
371
|
-
const inputSignature = method.inputTypeName === null ? '' : `input: ${method.inputTypeName}`;
|
|
372
|
-
const methodName = /^[$A-Z_][$0-9A-Z_]*$/i.test(method.operationId) &&
|
|
373
|
-
!TYPESCRIPT_RESERVED_WORDS.has(method.operationId)
|
|
374
|
-
? method.operationId
|
|
375
|
-
: JSON.stringify(method.operationId);
|
|
376
|
-
return `${methodName}(${inputSignature}): ${method.outputTypeName};`;
|
|
377
|
-
}
|
|
378
|
-
function renderTypiaLlmModuleFromMethodDescriptors({ applicationExportName, interfaceName, structuredOutputExportName, structuredOutputTypeName, typesImportPath, }, methods) {
|
|
379
|
-
const importedTypeNames = new Set([structuredOutputTypeName]);
|
|
380
|
-
for (const method of methods) {
|
|
381
|
-
importedTypeNames.add(method.outputTypeName);
|
|
382
|
-
if (method.inputTypeImportNames) {
|
|
383
|
-
for (const inputTypeImportName of method.inputTypeImportNames) {
|
|
384
|
-
importedTypeNames.add(inputTypeImportName);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
else if (method.inputTypeName) {
|
|
388
|
-
importedTypeNames.add(method.inputTypeName);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
const imports = Array.from(importedTypeNames).sort().join(',\n\t');
|
|
392
|
-
const methodBlocks = methods
|
|
393
|
-
.map((method) => {
|
|
394
|
-
const jsDoc = renderMethodJsDoc(method)
|
|
395
|
-
.split('\n')
|
|
396
|
-
.map((line) => `\t${line}`)
|
|
397
|
-
.join('\n');
|
|
398
|
-
return `${jsDoc}\n\t${renderMethodSignature(method)}`;
|
|
399
|
-
})
|
|
400
|
-
.join('\n\n');
|
|
401
|
-
return `import typia from "typia";
|
|
402
|
-
import type {
|
|
403
|
-
\t${imports},
|
|
404
|
-
} from "${typesImportPath}";
|
|
405
|
-
|
|
406
|
-
export interface ${interfaceName} {
|
|
407
|
-
${methodBlocks}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
export const ${applicationExportName} =
|
|
411
|
-
\ttypia.llm.application<${interfaceName}>();
|
|
412
|
-
|
|
413
|
-
export const ${structuredOutputExportName} =
|
|
414
|
-
\ttypia.llm.structuredOutput<${structuredOutputTypeName}>();
|
|
415
|
-
`;
|
|
416
|
-
}
|
|
417
|
-
async function reconcileGeneratedTypiaLlmArtifacts(artifacts, check) {
|
|
418
|
-
if (!check) {
|
|
419
|
-
for (const artifact of artifacts) {
|
|
420
|
-
await mkdir(path.dirname(artifact.filePath), {
|
|
421
|
-
recursive: true,
|
|
422
|
-
});
|
|
423
|
-
await writeFile(artifact.filePath, artifact.content, 'utf8');
|
|
424
|
-
}
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
const issues = [];
|
|
428
|
-
for (const artifact of artifacts) {
|
|
429
|
-
try {
|
|
430
|
-
const current = normalizeGeneratedArtifactContent(await readFile(artifact.filePath, 'utf8'));
|
|
431
|
-
const expected = normalizeGeneratedArtifactContent(artifact.content);
|
|
432
|
-
if (current !== expected) {
|
|
433
|
-
issues.push(`- ${artifact.filePath} (stale)`);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
catch (error) {
|
|
437
|
-
if (isFileNotFoundError(error)) {
|
|
438
|
-
issues.push(`- ${artifact.filePath} (missing)`);
|
|
439
|
-
continue;
|
|
440
|
-
}
|
|
441
|
-
const code = getOptionalNodeErrorCode(error);
|
|
442
|
-
issues.push(`- ${artifact.filePath} (unreadable: ${error instanceof Error ? error.message : code ?? 'unknown'})`);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
if (issues.length > 0) {
|
|
446
|
-
throw new Error(`Generated typia.llm artifacts are missing or stale:\n${issues.join('\n')}`);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Builds the generated controller method descriptors that bridge endpoint
|
|
451
|
-
* manifests to `typia.llm` TypeScript interfaces.
|
|
452
|
-
*
|
|
453
|
-
* @param manifest Endpoint manifest that owns operation and source type names.
|
|
454
|
-
* @returns Ordered method descriptors matching the manifest endpoints.
|
|
455
|
-
* @throws When an endpoint has ambiguous query/body input mapping.
|
|
456
|
-
* @throws When an endpoint references a missing input or output contract.
|
|
457
|
-
*/
|
|
458
|
-
export function buildTypiaLlmEndpointMethodDescriptors(manifest) {
|
|
459
|
-
return manifest.endpoints.map((endpoint) => {
|
|
460
|
-
const normalizedAuth = normalizeEndpointAuthDefinition(endpoint);
|
|
461
|
-
const inputTypeDescriptor = getEndpointInputTypeDescriptor(manifest, endpoint);
|
|
462
|
-
const inputTypeName = inputTypeDescriptor.signatureTypeName;
|
|
463
|
-
const shouldUseInlineInputImports = inputTypeName !== null &&
|
|
464
|
-
inputTypeDescriptor.importTypeNames.length > 0 &&
|
|
465
|
-
inputTypeDescriptor.importTypeNames[0] !== inputTypeName;
|
|
466
|
-
return {
|
|
467
|
-
authIntent: normalizedAuth.auth,
|
|
468
|
-
...(normalizedAuth.authMode ? { authMode: normalizedAuth.authMode } : {}),
|
|
469
|
-
description: endpoint.summary,
|
|
470
|
-
inputTypeName,
|
|
471
|
-
...(shouldUseInlineInputImports
|
|
472
|
-
? { inputTypeImportNames: inputTypeDescriptor.importTypeNames }
|
|
473
|
-
: {}),
|
|
474
|
-
method: endpoint.method,
|
|
475
|
-
operationId: endpoint.operationId,
|
|
476
|
-
outputTypeName: getEndpointOutputTypeName(manifest, endpoint),
|
|
477
|
-
path: endpoint.path,
|
|
478
|
-
tags: endpoint.tags ?? [],
|
|
479
|
-
...(normalizedAuth.wordpressAuth
|
|
480
|
-
? { wordpressAuth: normalizedAuth.wordpressAuth }
|
|
481
|
-
: {}),
|
|
482
|
-
};
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* Renders a build-time-only TypeScript module that invokes `typia.llm` against
|
|
487
|
-
* canonical manifest-owned contracts.
|
|
488
|
-
*
|
|
489
|
-
* @param options Render options for the generated adapter module.
|
|
490
|
-
* @returns The generated TypeScript source.
|
|
491
|
-
*/
|
|
492
|
-
export function renderTypiaLlmModule({ applicationExportName, interfaceName, manifest, structuredOutputExportName, structuredOutputTypeName, typesImportPath, }) {
|
|
493
|
-
return renderTypiaLlmModuleFromMethodDescriptors({
|
|
494
|
-
applicationExportName,
|
|
495
|
-
interfaceName,
|
|
496
|
-
structuredOutputExportName,
|
|
497
|
-
structuredOutputTypeName,
|
|
498
|
-
typesImportPath,
|
|
499
|
-
}, buildTypiaLlmEndpointMethodDescriptors(manifest));
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Writes or verifies the generated build-time `typia.llm` adapter module. The
|
|
503
|
-
* returned TypeScript source still needs to be compiled by the consuming
|
|
504
|
-
* project's Typia transformer before JSON artifacts can be read from it.
|
|
505
|
-
*
|
|
506
|
-
* @param options Generated module destination plus render options.
|
|
507
|
-
* @returns Rendered source, method descriptors, and the checked/written file path.
|
|
508
|
-
*/
|
|
509
|
-
export async function syncTypiaLlmAdapterModule({ check = false, generatedSourceFile, ...renderOptions }) {
|
|
510
|
-
const methodDescriptors = buildTypiaLlmEndpointMethodDescriptors(renderOptions.manifest);
|
|
511
|
-
const source = renderTypiaLlmModuleFromMethodDescriptors(renderOptions, methodDescriptors);
|
|
512
|
-
await reconcileGeneratedTypiaLlmArtifacts([
|
|
513
|
-
{
|
|
514
|
-
content: source,
|
|
515
|
-
filePath: generatedSourceFile,
|
|
516
|
-
},
|
|
517
|
-
], check);
|
|
518
|
-
return {
|
|
519
|
-
check,
|
|
520
|
-
methodDescriptors,
|
|
521
|
-
source,
|
|
522
|
-
sourceFile: generatedSourceFile,
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Projects one compiled `typia.llm` function schema into a JSON-friendly
|
|
527
|
-
* artifact record.
|
|
528
|
-
*
|
|
529
|
-
* @param functionSchema Function schema from a compiled `typia.llm.application(...)`.
|
|
530
|
-
* @returns JSON-friendly function artifact.
|
|
531
|
-
*/
|
|
532
|
-
export function projectTypiaLlmApplicationFunction(functionSchema) {
|
|
533
|
-
return {
|
|
534
|
-
description: functionSchema.description,
|
|
535
|
-
name: functionSchema.name,
|
|
536
|
-
output: cloneJsonValueIfDefined(functionSchema.output),
|
|
537
|
-
parameters: cloneJsonValue(functionSchema.parameters),
|
|
538
|
-
...(functionSchema.tags ? { tags: [...functionSchema.tags] } : {}),
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
function cloneProjectedTypiaLlmFunctionArtifact(functionArtifact) {
|
|
542
|
-
return {
|
|
543
|
-
description: functionArtifact.description,
|
|
544
|
-
name: functionArtifact.name,
|
|
545
|
-
output: cloneJsonValueIfDefined(functionArtifact.output),
|
|
546
|
-
parameters: cloneJsonValue(functionArtifact.parameters),
|
|
547
|
-
...(functionArtifact.tags ? { tags: [...functionArtifact.tags] } : {}),
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Restores canonical request and response constraints from an endpoint-aware
|
|
552
|
-
* OpenAPI document onto one projected `typia.llm` function artifact.
|
|
553
|
-
*
|
|
554
|
-
* Query-only inputs merge into the root parameter object. Mixed body/query
|
|
555
|
-
* inputs merge into the generated `body` and `query` properties.
|
|
556
|
-
*
|
|
557
|
-
* @param options Projected artifact plus the canonical OpenAPI document.
|
|
558
|
-
* @returns A cloned artifact enriched with OpenAPI-backed constraints when available.
|
|
559
|
-
*/
|
|
560
|
-
export function applyOpenApiConstraintsToTypiaLlmFunctionArtifact({ functionArtifact, openApiDocument, operationId, }) {
|
|
561
|
-
const constrainedArtifact = cloneProjectedTypiaLlmFunctionArtifact(functionArtifact);
|
|
562
|
-
const operation = findOpenApiOperationById(openApiDocument, operationId);
|
|
563
|
-
if (!operation) {
|
|
564
|
-
return constrainedArtifact;
|
|
565
|
-
}
|
|
566
|
-
const hasQueryParameters = (operation.parameters ?? []).some((parameter) => {
|
|
567
|
-
const resolvedParameter = resolveOpenApiSchemaObject(openApiDocument, parameter);
|
|
568
|
-
return (isJsonSchemaObject(resolvedParameter) &&
|
|
569
|
-
resolvedParameter.in === 'query' &&
|
|
570
|
-
typeof resolvedParameter.name === 'string');
|
|
571
|
-
});
|
|
572
|
-
const requestBodySchema = resolveOpenApiRequestBodySchema(operation, openApiDocument);
|
|
573
|
-
const parameterSchema = assertJsonSchemaObject(constrainedArtifact.parameters, `typia.llm parameters for "${constrainedArtifact.name}"`);
|
|
574
|
-
if (requestBodySchema) {
|
|
575
|
-
if (hasQueryParameters) {
|
|
576
|
-
mergeJsonSchemaConstraintProperties(openApiDocument, getOrCreateObjectProperty(parameterSchema, 'body'), requestBodySchema);
|
|
577
|
-
}
|
|
578
|
-
else {
|
|
579
|
-
mergeJsonSchemaConstraintProperties(openApiDocument, parameterSchema, requestBodySchema);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
if (hasQueryParameters) {
|
|
583
|
-
applyOpenApiQueryParameterConstraints(requestBodySchema
|
|
584
|
-
? getOrCreateObjectProperty(parameterSchema, 'query')
|
|
585
|
-
: parameterSchema, operation, openApiDocument);
|
|
586
|
-
}
|
|
587
|
-
if (constrainedArtifact.output) {
|
|
588
|
-
const outputSchema = assertJsonSchemaObject(constrainedArtifact.output, `typia.llm output for "${constrainedArtifact.name}"`);
|
|
589
|
-
const responseSchema = resolveOpenApiSuccessResponseSchema(operation, openApiDocument);
|
|
590
|
-
if (responseSchema) {
|
|
591
|
-
mergeJsonSchemaConstraintProperties(openApiDocument, outputSchema, responseSchema);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return constrainedArtifact;
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Projects a compiled `typia.llm.application(...)` result into a JSON-friendly
|
|
598
|
-
* downstream adapter artifact.
|
|
599
|
-
*
|
|
600
|
-
* @param options Compiled application value and source metadata.
|
|
601
|
-
* @returns JSON-friendly application artifact.
|
|
602
|
-
*/
|
|
603
|
-
export function projectTypiaLlmApplicationArtifact({ application, generatedFrom, openApiProjection, transformFunction, }) {
|
|
604
|
-
return {
|
|
605
|
-
functions: application.functions.map((functionSchema) => {
|
|
606
|
-
const functionArtifact = projectTypiaLlmApplicationFunction(functionSchema);
|
|
607
|
-
const openApiAlignedArtifact = openApiProjection
|
|
608
|
-
? applyOpenApiConstraintsToTypiaLlmFunctionArtifact({
|
|
609
|
-
functionArtifact,
|
|
610
|
-
openApiDocument: openApiProjection.openApiDocument,
|
|
611
|
-
operationId: openApiProjection.resolveOperationId?.(functionSchema, functionArtifact) ?? functionSchema.name,
|
|
612
|
-
})
|
|
613
|
-
: functionArtifact;
|
|
614
|
-
const transformedArtifact = transformFunction
|
|
615
|
-
? transformFunction(openApiAlignedArtifact, functionSchema)
|
|
616
|
-
: openApiAlignedArtifact;
|
|
617
|
-
return cloneProjectedTypiaLlmFunctionArtifact(transformedArtifact);
|
|
618
|
-
}),
|
|
619
|
-
generatedFrom: cloneJsonValue(generatedFrom),
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Projects a compiled `typia.llm.structuredOutput(...)` result into a
|
|
624
|
-
* JSON-friendly downstream adapter artifact.
|
|
625
|
-
*
|
|
626
|
-
* @param options Compiled structured-output value and source metadata.
|
|
627
|
-
* @returns JSON-friendly structured-output artifact.
|
|
628
|
-
*/
|
|
629
|
-
export function projectTypiaLlmStructuredOutputArtifact({ generatedFrom, structuredOutput, }) {
|
|
630
|
-
return {
|
|
631
|
-
generatedFrom: cloneJsonValue(generatedFrom),
|
|
632
|
-
parameters: cloneJsonValue(structuredOutput.parameters),
|
|
633
|
-
};
|
|
634
|
-
}
|
|
1
|
+
export { assertJsonSchemaObject } from './typia-llm-json-schema.js';
|
|
2
|
+
export { applyOpenApiConstraintsToTypiaLlmFunctionArtifact, } from './typia-llm-openapi-constraints.js';
|
|
3
|
+
export { projectTypiaLlmApplicationArtifact, projectTypiaLlmApplicationFunction, projectTypiaLlmStructuredOutputArtifact, } from './typia-llm-projection.js';
|
|
4
|
+
export { buildTypiaLlmEndpointMethodDescriptors, renderTypiaLlmModule, } from './typia-llm-render.js';
|
|
5
|
+
export { syncTypiaLlmAdapterModule } from './typia-llm-sync.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { escapeRegex } from "./php-utils.js";
|
|
4
|
-
import { BLOCK_INVENTORY_SECTION, INVENTORY_SECTIONS, } from "./workspace-inventory-
|
|
4
|
+
import { BLOCK_INVENTORY_SECTION, INVENTORY_SECTIONS, } from "./workspace-inventory-section-descriptors.js";
|
|
5
5
|
import { WORKSPACE_COMPATIBILITY_CONFIG_FIELD } from "./workspace-inventory-templates.js";
|
|
6
6
|
function ensureWorkspaceInventorySections(source) {
|
|
7
7
|
let nextSource = source.trimEnd();
|
|
@@ -136,8 +136,21 @@ export function updateWorkspaceInventorySource(source, options = {}) {
|
|
|
136
136
|
nextSource = options.transformSource(nextSource);
|
|
137
137
|
}
|
|
138
138
|
nextSource = appendInventorySectionEntries(nextSource, options);
|
|
139
|
+
for (const [fieldName, fieldSource] of [
|
|
140
|
+
["contentFile", "\tcontentFile?: string;"],
|
|
141
|
+
["file", "\tfile?: string;"],
|
|
142
|
+
["scope", "\tscope?: 'full' | 'section';"],
|
|
143
|
+
["sectionRole", "\tsectionRole?: string;"],
|
|
144
|
+
["tags", "\ttags?: string[];"],
|
|
145
|
+
["thumbnailUrl", "\tthumbnailUrl?: string;"],
|
|
146
|
+
["title", "\ttitle?: string;"],
|
|
147
|
+
]) {
|
|
148
|
+
nextSource = upsertInterfaceField(nextSource, "WorkspacePatternConfig", fieldName, fieldSource);
|
|
149
|
+
}
|
|
139
150
|
nextSource = ensureInterfaceField(nextSource, "WorkspaceBindingSourceConfig", "attribute", "\tattribute?: string;");
|
|
140
151
|
nextSource = ensureInterfaceField(nextSource, "WorkspaceBindingSourceConfig", "block", "\tblock?: string;");
|
|
152
|
+
nextSource = ensureInterfaceField(nextSource, "WorkspaceBindingSourceConfig", "metaPath", "\tmetaPath?: string;");
|
|
153
|
+
nextSource = ensureInterfaceField(nextSource, "WorkspaceBindingSourceConfig", "postMeta", "\tpostMeta?: string;");
|
|
141
154
|
nextSource = ensureInterfaceField(nextSource, "WorkspaceAbilityConfig", "compatibility", WORKSPACE_COMPATIBILITY_CONFIG_FIELD);
|
|
142
155
|
nextSource = normalizeInterfaceFieldBlock(nextSource, "WorkspaceAbilityConfig", "compatibility", WORKSPACE_COMPATIBILITY_CONFIG_FIELD, ["optionalFeatureIds: string[];", "requiredFeatureIds: string[];"]);
|
|
143
156
|
nextSource = ensureInterfaceField(nextSource, "WorkspaceAiFeatureConfig", "compatibility", WORKSPACE_COMPATIBILITY_CONFIG_FIELD);
|
|
@@ -157,6 +170,7 @@ export function updateWorkspaceInventorySource(source, options = {}) {
|
|
|
157
170
|
["responseTypeName", "\tresponseTypeName?: string;"],
|
|
158
171
|
["routePattern", "\troutePattern?: string;"],
|
|
159
172
|
["secretFieldName", "\tsecretFieldName?: string;"],
|
|
173
|
+
["secretPreserveOnEmpty", "\tsecretPreserveOnEmpty?: boolean;"],
|
|
160
174
|
["secretStateFieldName", "\tsecretStateFieldName?: string;"],
|
|
161
175
|
]) {
|
|
162
176
|
nextSource = upsertInterfaceField(nextSource, "WorkspaceRestResourceConfig", fieldName, fieldSource);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { type InventorySectionDescriptor } from "./workspace-inventory-parser-validation.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parse one descriptor-backed inventory section from a TypeScript source file.
|
|
5
|
+
*
|
|
6
|
+
* The generic `T` is the typed entry shape returned in `entries`. The
|
|
7
|
+
* `descriptor` supplies the exported array name, parser field metadata, and
|
|
8
|
+
* whether the section is required; this helper uses `findExportedArrayLiteral`
|
|
9
|
+
* and `parseInventoryEntries` to guarantee object-literal entries and literal
|
|
10
|
+
* field values. It returns parsed entries plus a `found` flag, and throws when
|
|
11
|
+
* required exports are missing, descriptors cannot resolve an export name, or
|
|
12
|
+
* exported values are not array literals.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseInventorySection<T extends object>(sourceFile: ts.SourceFile, descriptor: InventorySectionDescriptor): {
|
|
15
|
+
entries: T[];
|
|
16
|
+
found: boolean;
|
|
17
|
+
};
|