@ama-sdk/schematics 14.1.0-prerelease.40 → 14.1.0-prerelease.41
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/README.md +3 -2
- package/cli/genai-context/templates/SDK_CONTEXT.md.template +63 -0
- package/cli/genai-context/update-sdk-context.cjs +334 -0
- package/cli/genai-context/update-sdk-context.cjs.map +1 -0
- package/cli/genai-context/update-sdk-context.d.cts +19 -0
- package/cli/genai-context/update-sdk-context.d.cts.map +1 -0
- package/cli/genai-context/update-sdk-context.helpers.d.ts +54 -0
- package/cli/genai-context/update-sdk-context.helpers.d.ts.map +1 -0
- package/cli/genai-context/update-sdk-context.helpers.js +132 -0
- package/cli/genai-context/update-sdk-context.helpers.js.map +1 -0
- package/cli/genai-context/update-sdk-context.template.d.ts +24 -0
- package/cli/genai-context/update-sdk-context.template.d.ts.map +1 -0
- package/cli/genai-context/update-sdk-context.template.js +15 -0
- package/cli/genai-context/update-sdk-context.template.js.map +1 -0
- package/cli/update-sdk-genai-context.cjs +56 -0
- package/cli/update-sdk-genai-context.cjs.map +1 -0
- package/cli/update-sdk-genai-context.d.cts +3 -0
- package/cli/update-sdk-genai-context.d.cts.map +1 -0
- package/package.json +14 -10
- package/schematics/typescript/core/openapi-codegen-typescript/target/typescriptFetch-openapi-generator-tests.jar +0 -0
- package/schematics/typescript/core/openapi-codegen-typescript/target/typescriptFetch-openapi-generator.jar +0 -0
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ To align ourselves with OpenAPI 3.1, we now support arrays and objects in path a
|
|
|
116
116
|
Based on the values of the keywords `style` and `explode` within the specification file, the parameters are serialized accordingly in the URLs of the APIs.
|
|
117
117
|
For more information, check out OpenAPI's documentation on [parameter serialization](https://swagger.io/specification/).
|
|
118
118
|
|
|
119
|
-
It is important to note that, as in OpenAPI 3.1, we only support simple arrays and simple non-nested objects in path and query parameters.
|
|
119
|
+
It is important to note that, as in OpenAPI 3.1, we only support simple arrays and simple non-nested objects in path and query parameters.
|
|
120
120
|
The parameter types that we support are stored in `SupportedParamType` in the package `@ama-sdk/core`.
|
|
121
121
|
|
|
122
122
|
To enable the parameter serialization within your API, you can set the option `enableParameterSerialization` to `true` (its current default value is `false`) in the constructor. For example:
|
|
@@ -165,7 +165,7 @@ If your specification file includes dates, there are multiple options for the ge
|
|
|
165
165
|
to the `openapitools.json`.
|
|
166
166
|
> [!NOTE]
|
|
167
167
|
> An extra type to manage special timezone use cases can be used at property level thanks to the
|
|
168
|
-
> `x-local-timezone` vendor.
|
|
168
|
+
> `x-local-timezone` vendor.
|
|
169
169
|
> Please check out the [date documentation](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/schematics/schematics/typescript/shell/templates/base#manage-dates).
|
|
170
170
|
|
|
171
171
|
Example to use `Date`:
|
|
@@ -328,3 +328,4 @@ Use `--help` on each command for more information
|
|
|
328
328
|
| amasdk-clear-index | Remove the index files that are no longer necessary after the deletion of the associated model |
|
|
329
329
|
| amasdk-files-pack | Prepare the dist folder for publication |
|
|
330
330
|
| amasdk-update-spec-from-npm | Update the OpenAPI spec from an NPM package |
|
|
331
|
+
| amasdk-update-sdk-context | Update the SDK_CONTEXT.md file with the latest information from the OpenAPI spec (see [update-sdk-context](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/schematics/cli/genai-context/README.md)) |
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# SDK Context for AI Tools
|
|
2
|
+
|
|
3
|
+
This document provides context about the generated TypeScript SDK to help AI assistants understand the codebase structure and avoid hallucinations.
|
|
4
|
+
|
|
5
|
+
## SDK Information
|
|
6
|
+
|
|
7
|
+
- **Package Name**: `<%= packageName %>`
|
|
8
|
+
- **OpenAPI Version**: `<%= openApiVersion %>`
|
|
9
|
+
- **API Title**: <%= apiTitle %>
|
|
10
|
+
- **Generated with**: `@ama-sdk/schematics:typescript-core`
|
|
11
|
+
|
|
12
|
+
## Project Structure
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
<%= packageName %>/
|
|
16
|
+
├── api/ # API endpoint classes (domain-based)
|
|
17
|
+
<%= domainTree %>
|
|
18
|
+
│ └── index.ts
|
|
19
|
+
├── models/
|
|
20
|
+
│ ├── base/ # Auto-generated from OpenAPI (DO NOT MODIFY)
|
|
21
|
+
│ ├── core/ # Extensions of base models if needed
|
|
22
|
+
│ ├── custom/ # Custom business models if needed
|
|
23
|
+
│ └── index.ts
|
|
24
|
+
├── spec/ # Operation specifications
|
|
25
|
+
├── fixtures/ # Test fixtures
|
|
26
|
+
├── open-api.yaml # OpenAPI specification source
|
|
27
|
+
└── openapitools.json # Generator configuration
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Domains
|
|
31
|
+
|
|
32
|
+
The following domains were extracted from the OpenAPI specification. Each domain represents a logical grouping of related API operations.
|
|
33
|
+
|
|
34
|
+
<%= domainsSection %>
|
|
35
|
+
|
|
36
|
+
## Important Guidelines
|
|
37
|
+
|
|
38
|
+
### DO NOT
|
|
39
|
+
|
|
40
|
+
- Modify files in `src/models/base/` - these are auto-generated
|
|
41
|
+
- Invent operation IDs that don't exist in the domains above
|
|
42
|
+
- Assume model properties not defined in the OpenAPI spec
|
|
43
|
+
- Create new API classes outside the domain structure
|
|
44
|
+
|
|
45
|
+
### DO
|
|
46
|
+
|
|
47
|
+
- Use the exact operation IDs listed above
|
|
48
|
+
- Reference models from `src/models/base/` for type definitions
|
|
49
|
+
- Extend functionality in `src/models/core/` or `src/models/custom/` if needed
|
|
50
|
+
- Check `src/api/{domain}/{domain}-api.ts` for available methods
|
|
51
|
+
|
|
52
|
+
## User Disambiguation Notes
|
|
53
|
+
|
|
54
|
+
<!-- Add project-specific clarifications below -->
|
|
55
|
+
<% if (disambiguation) { %>
|
|
56
|
+
<%= disambiguation %>
|
|
57
|
+
<% } else { %>
|
|
58
|
+
(No disambiguation notes added yet. Run with --interactive to add notes.)
|
|
59
|
+
<% } %>
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
*This file was generated using `amasdk-update-sdk-context`. Re-run after SDK regeneration to update domains.*
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSdkContext = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const node_readline_1 = require("node:readline");
|
|
8
|
+
const core_1 = require("@angular-devkit/core");
|
|
9
|
+
const schematics_1 = require("@o3r/schematics");
|
|
10
|
+
const js_yaml_1 = require("js-yaml");
|
|
11
|
+
const update_sdk_context_helpers_1 = require("./update-sdk-context.helpers");
|
|
12
|
+
const update_sdk_context_template_1 = require("./update-sdk-context.template");
|
|
13
|
+
const DOMAIN_DESCRIPTIONS_FILENAME = 'domain-descriptions.json';
|
|
14
|
+
/**
|
|
15
|
+
* Load OpenAPI specifications from file or default locations
|
|
16
|
+
* @param projectPath Path to the OpenAPI specification file
|
|
17
|
+
* @param specFileName Name of the OpenAPI specification file
|
|
18
|
+
* @returns OpenAPI specification as JSON object
|
|
19
|
+
*/
|
|
20
|
+
function loadOpenAPISpec(projectPath, specFileName) {
|
|
21
|
+
let isYaml = false;
|
|
22
|
+
let specPath;
|
|
23
|
+
if (specFileName) {
|
|
24
|
+
specPath = (0, node_path_1.resolve)(projectPath, specFileName);
|
|
25
|
+
if (!(0, node_fs_1.existsSync)(specPath)) {
|
|
26
|
+
throw new Error(`OpenAPI specification not found at: ${specPath}`);
|
|
27
|
+
}
|
|
28
|
+
isYaml = specPath.endsWith('.yaml') || specPath.endsWith('.yml');
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const yamlPath = (0, node_path_1.join)(projectPath, 'open-api.yaml');
|
|
32
|
+
const jsonPath = (0, node_path_1.join)(projectPath, 'open-api.json');
|
|
33
|
+
if ((0, node_fs_1.existsSync)(yamlPath)) {
|
|
34
|
+
specPath = yamlPath;
|
|
35
|
+
isYaml = true;
|
|
36
|
+
}
|
|
37
|
+
else if ((0, node_fs_1.existsSync)(jsonPath)) {
|
|
38
|
+
specPath = jsonPath;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error(`No OpenAPI specification found. Looked for:\n - ${yamlPath}\n - ${jsonPath}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const specContent = (0, node_fs_1.readFileSync)(specPath, 'utf8');
|
|
45
|
+
try {
|
|
46
|
+
return (isYaml ? (0, js_yaml_1.load)(specContent) : JSON.parse(specContent));
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new Error(`Failed to parse OpenAPI specification at ${specPath}: ${error.message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Read the domain descriptions from user file, this allow for custom domain descriptions
|
|
54
|
+
* and extra clarifications
|
|
55
|
+
* @param filePath Path to the domain descriptions file
|
|
56
|
+
*/
|
|
57
|
+
function loadDomainDescriptions(filePath) {
|
|
58
|
+
if (!(0, node_fs_1.existsSync)(filePath)) {
|
|
59
|
+
throw new Error(`Domain descriptions file not found: ${filePath}`);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse((0, node_fs_1.readFileSync)(filePath, 'utf8'));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
throw new Error(`Failed to parse domain descriptions file: ${filePath}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Read the package.json file
|
|
70
|
+
* @param projectPath Path to the project root
|
|
71
|
+
*/
|
|
72
|
+
function loadPackageJson(projectPath) {
|
|
73
|
+
const packagePath = (0, node_path_1.join)(projectPath, 'package.json');
|
|
74
|
+
if ((0, node_fs_1.existsSync)(packagePath)) {
|
|
75
|
+
return JSON.parse((0, node_fs_1.readFileSync)(packagePath, 'utf8'));
|
|
76
|
+
}
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Read the existing disambiguation notes from SDK_CONTEXT.md
|
|
81
|
+
* @param projectPath Path to the project root
|
|
82
|
+
*/
|
|
83
|
+
function loadExistingDisambiguation(projectPath) {
|
|
84
|
+
const contextPath = (0, node_path_1.join)(projectPath, 'SDK_CONTEXT.md');
|
|
85
|
+
if ((0, node_fs_1.existsSync)(contextPath)) {
|
|
86
|
+
const content = (0, node_fs_1.readFileSync)(contextPath, 'utf8');
|
|
87
|
+
const match = content.match(/## User Disambiguation Notes\s*\n<!-- Add project-specific clarifications below -->\n([\s\S]*?)(?=\n---|\n##|$)/);
|
|
88
|
+
return match ? match[1].trim() : '';
|
|
89
|
+
}
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Generate the SDK_CONTEXT.md file
|
|
94
|
+
* @param spec OpenAPI specification as JSON object
|
|
95
|
+
* @param domains Map of domains
|
|
96
|
+
* @param packageName Package name
|
|
97
|
+
* @param disambiguation Disambiguation notes
|
|
98
|
+
*/
|
|
99
|
+
async function generateContextFile(spec, domains, packageName, disambiguation) {
|
|
100
|
+
const openApiVersion = 'openapi' in spec ? spec.openapi : ('swagger' in spec ? spec.swagger : 'unknown');
|
|
101
|
+
const apiTitle = spec.info?.title || 'Unknown API';
|
|
102
|
+
let domainsSection = '';
|
|
103
|
+
domains.forEach((domain) => {
|
|
104
|
+
domainsSection += `
|
|
105
|
+
### ${domain.name}
|
|
106
|
+
|
|
107
|
+
**What this domain is about**: ${domain.description}
|
|
108
|
+
|
|
109
|
+
**API Class**: \`src/api/${domain.name}/${domain.name}-api.ts\`
|
|
110
|
+
|
|
111
|
+
**Available Operations:**
|
|
112
|
+
|
|
113
|
+
| Operation ID | Method | Description |
|
|
114
|
+
|--------------|--------|-------------|
|
|
115
|
+
`;
|
|
116
|
+
domain.operations.forEach((op) => {
|
|
117
|
+
domainsSection += `| \`${op.operationId}\` | ${op.method} | ${op.summary} |\n`;
|
|
118
|
+
});
|
|
119
|
+
domainsSection += `\n**Models used in this domain:**\n`;
|
|
120
|
+
if (domain.models.size > 0) {
|
|
121
|
+
domain.models.forEach((model) => {
|
|
122
|
+
domainsSection += `- \`${model}\` - imported from \`src/models/base/${core_1.strings.dasherize(model)}/\`\n`;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
domainsSection += `- (none)\n`;
|
|
127
|
+
}
|
|
128
|
+
domainsSection += '\n';
|
|
129
|
+
});
|
|
130
|
+
const domainTree = Array.from(domains.values())
|
|
131
|
+
.map((d) => `│ ├── ${d.name}/ # ${d.description.substring(0, 40)}...`)
|
|
132
|
+
.join('\n');
|
|
133
|
+
return await (0, update_sdk_context_template_1.renderSdkContextTemplate)({
|
|
134
|
+
packageName,
|
|
135
|
+
openApiVersion,
|
|
136
|
+
apiTitle,
|
|
137
|
+
domainTree,
|
|
138
|
+
domainsSection,
|
|
139
|
+
disambiguation
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Prompt the user for disambiguation notes
|
|
144
|
+
* @param domains Map of domains
|
|
145
|
+
* @param existingDisambiguation Existing disambiguation notes
|
|
146
|
+
* @param hasCustomDescriptions Whether the user provided custom descriptions
|
|
147
|
+
* @param domainDescriptionsFileName Name of the domain descriptions file
|
|
148
|
+
* @param logger Logger instance
|
|
149
|
+
* @returns Disambiguation notes
|
|
150
|
+
*/
|
|
151
|
+
async function promptForDisambiguation(domains, existingDisambiguation, hasCustomDescriptions, domainDescriptionsFileName, logger) {
|
|
152
|
+
const rl = (0, node_readline_1.createInterface)({
|
|
153
|
+
input: process.stdin,
|
|
154
|
+
output: process.stdout
|
|
155
|
+
});
|
|
156
|
+
const question = (prompt) => {
|
|
157
|
+
return new Promise((res) => rl.question(prompt, res));
|
|
158
|
+
};
|
|
159
|
+
logger.log(`
|
|
160
|
+
=== SDK Context Update - Interactive Mode ===
|
|
161
|
+
Computed domain descriptions:
|
|
162
|
+
`);
|
|
163
|
+
domains.forEach((domain) => {
|
|
164
|
+
logger.log(`
|
|
165
|
+
• ${domain.name}
|
|
166
|
+
Description: ${domain.description}
|
|
167
|
+
Operations: ${domain.operations.length}
|
|
168
|
+
Models: ${domain.models.size}
|
|
169
|
+
`);
|
|
170
|
+
});
|
|
171
|
+
if (hasCustomDescriptions) {
|
|
172
|
+
logger.log(`(Using custom descriptions from --domain-descriptions file)`);
|
|
173
|
+
}
|
|
174
|
+
const confirmDomains = await question('\nAre these domain descriptions correct? (y/n): ');
|
|
175
|
+
if (confirmDomains.toLowerCase() !== 'y') {
|
|
176
|
+
const overrideFile = domainDescriptionsFileName || DOMAIN_DESCRIPTIONS_FILENAME;
|
|
177
|
+
logger.log(`
|
|
178
|
+
To modify domain descriptions, edit the override file:
|
|
179
|
+
File: ${overrideFile}
|
|
180
|
+
Format: { "domainName": "description", ... }
|
|
181
|
+
`);
|
|
182
|
+
rl.close();
|
|
183
|
+
throw new Error(hasCustomDescriptions
|
|
184
|
+
? `User rejected domain descriptions. Please edit the ${overrideFile} file and re-run this command.`
|
|
185
|
+
: `User rejected domain descriptions. Create ${overrideFile} and run: amasdk-update-sdk-context --interactive --domain-descriptions ${overrideFile}`);
|
|
186
|
+
}
|
|
187
|
+
logger.log(`
|
|
188
|
+
--- Disambiguation Notes ---
|
|
189
|
+
Add any clarifications AI tools should know about your SDK.
|
|
190
|
+
Examples: naming conventions, domain relationships, custom extensions, known limitations.
|
|
191
|
+
`);
|
|
192
|
+
if (existingDisambiguation) {
|
|
193
|
+
logger.log(`
|
|
194
|
+
Existing notes:
|
|
195
|
+
${existingDisambiguation}
|
|
196
|
+
`);
|
|
197
|
+
const keepExisting = await question(`
|
|
198
|
+
Keep existing disambiguation notes? (y/n): `);
|
|
199
|
+
if (keepExisting.toLowerCase() === 'y') {
|
|
200
|
+
const addMore = await question('Add more notes? (y/n): ');
|
|
201
|
+
if (addMore.toLowerCase() === 'y') {
|
|
202
|
+
const additional = await question('Enter additional notes (single line): ');
|
|
203
|
+
rl.close();
|
|
204
|
+
return `
|
|
205
|
+
${existingDisambiguation}
|
|
206
|
+
${additional}
|
|
207
|
+
`;
|
|
208
|
+
}
|
|
209
|
+
rl.close();
|
|
210
|
+
return existingDisambiguation;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const newNotes = await question(`
|
|
214
|
+
Enter disambiguation notes (or press Enter to skip):
|
|
215
|
+
`);
|
|
216
|
+
rl.close();
|
|
217
|
+
return newNotes || '';
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get the cpy-cli version from `@ama-sdk/schematics` package.json
|
|
221
|
+
*/
|
|
222
|
+
function getCpyCliVersion() {
|
|
223
|
+
const schematicsPackagePath = (0, node_path_1.join)(__dirname, '../../../package.json');
|
|
224
|
+
try {
|
|
225
|
+
const schematicsPackageJson = JSON.parse((0, node_fs_1.readFileSync)(schematicsPackagePath, 'utf8'));
|
|
226
|
+
return schematicsPackageJson.devDependencies?.['cpy-cli'] || null;
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Adds a prepare:context script to package.json that copies SDK_CONTEXT.md to dist/
|
|
234
|
+
* and updates the build script to include prepare:context if needed.
|
|
235
|
+
* @param packageJsonPath - Path to the package.json file
|
|
236
|
+
* @param logger - Logger instance
|
|
237
|
+
*/
|
|
238
|
+
async function addPrepareContextScript(packageJsonPath, logger) {
|
|
239
|
+
try {
|
|
240
|
+
if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
241
|
+
logger.error(`Package.json not found at: ${packageJsonPath}`);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const packageJsonContent = (0, node_fs_1.readFileSync)(packageJsonPath, 'utf8');
|
|
245
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
246
|
+
// Initialize scripts object if it doesn't exist
|
|
247
|
+
packageJson.scripts ||= {};
|
|
248
|
+
// Initialize devDependencies object if it doesn't exist
|
|
249
|
+
packageJson.devDependencies ||= {};
|
|
250
|
+
// Check if cpy-cli is available as dev dependency, install if missing
|
|
251
|
+
if (!packageJson.devDependencies['cpy-cli']) {
|
|
252
|
+
const cpyCliVersion = getCpyCliVersion();
|
|
253
|
+
if (cpyCliVersion) {
|
|
254
|
+
logger.log(`Installing cpy-cli@${cpyCliVersion} as dev dependency...`);
|
|
255
|
+
try {
|
|
256
|
+
const targetDir = (0, node_path_1.dirname)(packageJsonPath);
|
|
257
|
+
(0, node_child_process_1.execFileSync)((0, schematics_1.getPackageManager)(), [
|
|
258
|
+
...(0, schematics_1.getPackageManager)() === 'npm' ? ['install', '--save-dev'] : ['add', '--dev'],
|
|
259
|
+
`cpy-cli@${cpyCliVersion}`
|
|
260
|
+
], { cwd: targetDir, stdio: 'pipe', shell: process.platform === 'win32' });
|
|
261
|
+
packageJson.devDependencies['cpy-cli'] = cpyCliVersion;
|
|
262
|
+
logger.log(`Successfully installed cpy-cli@${cpyCliVersion}`);
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
logger.warn(`Failed to install cpy-cli: ${error instanceof Error ? error.message : String(error)}. Please install it manually.`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
logger.warn(`cpy-cli is required but version could not be determined. Please install it manually with: npm install --save-dev cpy-cli`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Add the prepare:context script if it doesn't exist
|
|
273
|
+
if (packageJson.scripts['prepare:context']) {
|
|
274
|
+
logger.log(`'prepare:context' script already exists in package.json`);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
packageJson.scripts['prepare:context'] = 'cpy SDK_CONTEXT.md dist/';
|
|
278
|
+
logger.log(`Added 'prepare:context' script to package.json`);
|
|
279
|
+
}
|
|
280
|
+
// Update build script to include prepare:context if it exists and doesn't already include it
|
|
281
|
+
if (packageJson.scripts.build && !packageJson.scripts.build.includes('prepare:context')) {
|
|
282
|
+
packageJson.scripts.build = `${packageJson.scripts.build} && npm run prepare:context`;
|
|
283
|
+
logger.log(`Updated 'build' script to include 'prepare:context'`);
|
|
284
|
+
}
|
|
285
|
+
// Write the updated package.json back to file
|
|
286
|
+
await node_fs_1.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
287
|
+
logger.log(`Package.json updated successfully: ${packageJsonPath}`);
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
// Ignore errors for now
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Generate the SDK_CONTEXT.md file
|
|
295
|
+
* @param projectPath Path to the project root
|
|
296
|
+
* @param specFileName Name of the OpenAPI spec file
|
|
297
|
+
* @param domainDescriptionsFileName Name of the domain descriptions file
|
|
298
|
+
* @param isInteractive Whether to run in interactive mode
|
|
299
|
+
* @param prepareScript Whether to add a prepare:context script to package.json
|
|
300
|
+
* @param logger Logger instance
|
|
301
|
+
*/
|
|
302
|
+
const generateSdkContext = async (projectPath, specFileName, domainDescriptionsFileName, isInteractive, prepareScript, logger) => {
|
|
303
|
+
logger.log(`Loading OpenAPI spec from: ${projectPath}`);
|
|
304
|
+
const spec = loadOpenAPISpec(projectPath, specFileName);
|
|
305
|
+
const customDescriptions = domainDescriptionsFileName ? loadDomainDescriptions((0, node_path_1.join)(projectPath, domainDescriptionsFileName)) : null;
|
|
306
|
+
const domains = (0, update_sdk_context_helpers_1.extractDomains)(spec, customDescriptions);
|
|
307
|
+
const packageJson = loadPackageJson(projectPath);
|
|
308
|
+
const packageName = packageJson.name || (0, node_path_1.basename)(projectPath);
|
|
309
|
+
logger.log(`Found ${domains.size} domains with ${Array.from(domains.values()).reduce((sum, d) => sum + d.operations.length, 0)} operations`);
|
|
310
|
+
let disambiguation = loadExistingDisambiguation(projectPath);
|
|
311
|
+
if (isInteractive) {
|
|
312
|
+
disambiguation = await promptForDisambiguation(domains, disambiguation, !!customDescriptions, projectPath, logger);
|
|
313
|
+
}
|
|
314
|
+
const contextContent = await generateContextFile(spec, domains, packageName, disambiguation);
|
|
315
|
+
const outputPath = (0, node_path_1.join)(projectPath, 'SDK_CONTEXT.md');
|
|
316
|
+
await node_fs_1.promises.writeFile(outputPath, contextContent, 'utf8');
|
|
317
|
+
logger.log(`
|
|
318
|
+
SDK context written to: ${outputPath}
|
|
319
|
+
--- Domain Summary ---
|
|
320
|
+
`);
|
|
321
|
+
domains.forEach((domain) => {
|
|
322
|
+
logger.log(`${domain.name}:`);
|
|
323
|
+
domain.operations.forEach((op) => {
|
|
324
|
+
logger.log(` - ${op.operationId}`);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
// Handle prepare script addition if requested
|
|
328
|
+
if (prepareScript) {
|
|
329
|
+
const targetPackageJsonPath = (0, node_path_1.join)(projectPath, 'package.json');
|
|
330
|
+
await addPrepareContextScript(targetPackageJsonPath, logger);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
exports.generateSdkContext = generateSdkContext;
|
|
334
|
+
//# sourceMappingURL=update-sdk-context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-sdk-context.cjs","sourceRoot":"","sources":["../../../cli/genai-context/update-sdk-context.cts"],"names":[],"mappings":";;;AAAA,2DAE4B;AAC5B,qCAIiB;AACjB,yCAKmB;AACnB,iDAEuB;AACvB,+CAE8B;AAC9B,gDAEyB;AACzB,qCAEiB;AAIjB,6EAIsC;AACtC,+EAEuC;AAWvC,MAAM,4BAA4B,GAAG,0BAA0B,CAAC;AAEhE;;;;;GAKG;AACH,SAAS,eAAe,CAAC,WAAmB,EAAE,YAAgC;IAC5E,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,QAAgB,CAAC;IACrB,IAAI,YAAY,EAAE,CAAC;QACjB,QAAQ,GAAG,IAAA,mBAAO,EAAC,W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AC,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC,kBAAkB,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IACrH,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;IAC7F,MAAM,UAAU,GAAG,IAAA,gBAAI,EAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;IAEvD,MAAM,kBAAE,CAAC,SAAS,CAAC,UAAU,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IACvD,MAAM,CAAC,GAAG,CAAC;8BACiB,UAAU;;GAErC,CAAC,CAAC;IACH,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QAC9B,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YAC/B,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,8CAA8C;IAC9C,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,qBAAqB,GAAG,IAAA,gBAAI,EAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAChE,MAAM,uBAAuB,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC,CAAC;AA5CW,QAAA,kBAAkB,sBA4C7B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Logger interface */
|
|
2
|
+
export type Logger = {
|
|
3
|
+
log: (message: string) => void;
|
|
4
|
+
error: (message: string) => void;
|
|
5
|
+
warn: (message: string) => void;
|
|
6
|
+
info: (message: string) => void;
|
|
7
|
+
debug: (message: string) => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Generate the SDK_CONTEXT.md file
|
|
11
|
+
* @param projectPath Path to the project root
|
|
12
|
+
* @param specFileName Name of the OpenAPI spec file
|
|
13
|
+
* @param domainDescriptionsFileName Name of the domain descriptions file
|
|
14
|
+
* @param isInteractive Whether to run in interactive mode
|
|
15
|
+
* @param prepareScript Whether to add a prepare:context script to package.json
|
|
16
|
+
* @param logger Logger instance
|
|
17
|
+
*/
|
|
18
|
+
export declare const generateSdkContext: (projectPath: string, specFileName: string | undefined, domainDescriptionsFileName: string | undefined, isInteractive: boolean, prepareScript: boolean | undefined, logger: Logger) => Promise<void>;
|
|
19
|
+
//# sourceMappingURL=update-sdk-context.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-sdk-context.d.cts","sourceRoot":"","sources":["../../../cli/genai-context/update-sdk-context.cts"],"names":[],"mappings":"AAsCA,uBAAuB;AACvB,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC,CAAC;AA4TF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAC7B,aAAa,MAAM,EACnB,cAAc,MAAM,GAAG,SAAS,EAChC,4BAA4B,MAAM,GAAG,SAAS,EAC9C,eAAe,OAAO,EACtB,eAAe,OAAO,GAAG,SAAS,EAClC,QAAQ,MAAM,kBAsCf,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
/** Supported OpenAPI document types */
|
|
3
|
+
export type OpenAPISpec = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
4
|
+
/**
|
|
5
|
+
* Represents a domain extracted from an OpenAPI specification
|
|
6
|
+
* A domain groups related API operations together
|
|
7
|
+
*/
|
|
8
|
+
export interface Domain {
|
|
9
|
+
/** Domain name (typically from OpenAPI tag) */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Human-readable description of the domain */
|
|
12
|
+
description: string;
|
|
13
|
+
/** List of operations belonging to this domain */
|
|
14
|
+
operations: {
|
|
15
|
+
/** Unique operation identifier */
|
|
16
|
+
operationId: string;
|
|
17
|
+
/** HTTP method (GET, POST, etc.) */
|
|
18
|
+
method: string;
|
|
19
|
+
/** Short description of the operation */
|
|
20
|
+
summary: string;
|
|
21
|
+
/** API endpoint path */
|
|
22
|
+
path: string;
|
|
23
|
+
}[];
|
|
24
|
+
/** Set of model names referenced by operations in this domain */
|
|
25
|
+
models: Set<string>;
|
|
26
|
+
}
|
|
27
|
+
/** Standard HTTP methods supported in OpenAPI specifications */
|
|
28
|
+
export declare const HTTP_METHODS: ["get", "post", "put", "delete", "patch", "options", "head"];
|
|
29
|
+
/**
|
|
30
|
+
* Extracts the model name from an OpenAPI $ref string
|
|
31
|
+
* @param ref The $ref string to extract from
|
|
32
|
+
* @returns The model name or null if not found
|
|
33
|
+
*/
|
|
34
|
+
export declare function extractRefModel(ref?: string): string | null;
|
|
35
|
+
/**
|
|
36
|
+
* Extracts all referenced model names from an OpenAPI operation
|
|
37
|
+
* @param operation The OpenAPI operation to extract models from
|
|
38
|
+
* @returns Array of model names
|
|
39
|
+
*/
|
|
40
|
+
export declare function extractModelsFromOperation(operation: OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Infers a domain name from an API path
|
|
43
|
+
* @param apiPath The API path to infer from
|
|
44
|
+
* @returns The inferred domain name or 'default'
|
|
45
|
+
*/
|
|
46
|
+
export declare function inferDomainFromPath(apiPath: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Extracts domains from an OpenAPI specification
|
|
49
|
+
* @param spec The OpenAPI specification to extract from
|
|
50
|
+
* @param customDescriptions Optional custom descriptions for domains
|
|
51
|
+
* @returns Map of domain names to Domain objects
|
|
52
|
+
*/
|
|
53
|
+
export declare function extractDomains(spec: OpenAPISpec, customDescriptions?: Record<string, string> | null): Map<string, Domain>;
|
|
54
|
+
//# sourceMappingURL=update-sdk-context.helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-sdk-context.helpers.d.ts","sourceRoot":"","sources":["../../../cli/genai-context/update-sdk-context.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACZ,MAAM,eAAe,CAAC;AAEvB,uCAAuC;AACvC,MAAM,MAAM,WAAW,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AAEzF;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,UAAU,EAAE;QACV,kCAAkC;QAClC,WAAW,EAAE,MAAM,CAAC;QACpB,oCAAoC;QACpC,MAAM,EAAE,MAAM,CAAC;QACf,yCAAyC;QACzC,OAAO,EAAE,MAAM,CAAC;QAChB,wBAAwB;QACxB,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;IACJ,iEAAiE;IACjE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACrB;AAED,gEAAgE;AAChE,eAAO,MAAM,YAAY,8DAA+G,CAAC;AAEzI;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM3D;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,SAAS,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,GAAG,MAAM,EAAE,CA0CvH;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAwDzH"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HTTP_METHODS = void 0;
|
|
4
|
+
exports.extractRefModel = extractRefModel;
|
|
5
|
+
exports.extractModelsFromOperation = extractModelsFromOperation;
|
|
6
|
+
exports.inferDomainFromPath = inferDomainFromPath;
|
|
7
|
+
exports.extractDomains = extractDomains;
|
|
8
|
+
/** Standard HTTP methods supported in OpenAPI specifications */
|
|
9
|
+
exports.HTTP_METHODS = ['get', 'post', 'put', 'delete', 'patch', 'options', 'head'];
|
|
10
|
+
/**
|
|
11
|
+
* Extracts the model name from an OpenAPI $ref string
|
|
12
|
+
* @param ref The $ref string to extract from
|
|
13
|
+
* @returns The model name or null if not found
|
|
14
|
+
*/
|
|
15
|
+
function extractRefModel(ref) {
|
|
16
|
+
if (!ref) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const match = ref.match(/#\/components\/schemas\/(\w+)/);
|
|
20
|
+
return match ? match[1] : null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extracts all referenced model names from an OpenAPI operation
|
|
24
|
+
* @param operation The OpenAPI operation to extract models from
|
|
25
|
+
* @returns Array of model names
|
|
26
|
+
*/
|
|
27
|
+
function extractModelsFromOperation(operation) {
|
|
28
|
+
const models = [];
|
|
29
|
+
const requestBody = operation.requestBody;
|
|
30
|
+
if (requestBody?.content) {
|
|
31
|
+
Object.values(requestBody.content).forEach((mediaType) => {
|
|
32
|
+
const { schema } = mediaType;
|
|
33
|
+
if (schema && '$ref' in schema) {
|
|
34
|
+
const model = extractRefModel(schema.$ref);
|
|
35
|
+
if (model) {
|
|
36
|
+
models.push(model);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (operation.responses) {
|
|
42
|
+
Object.values(operation.responses).forEach((responseOrRef) => {
|
|
43
|
+
const response = responseOrRef;
|
|
44
|
+
if (response.content) {
|
|
45
|
+
Object.values(response.content).forEach((mediaType) => {
|
|
46
|
+
const schema = mediaType.schema;
|
|
47
|
+
if (schema && '$ref' in schema) {
|
|
48
|
+
const model = extractRefModel(schema.$ref);
|
|
49
|
+
if (model) {
|
|
50
|
+
models.push(model);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (schema && 'items' in schema) {
|
|
54
|
+
const items = schema.items;
|
|
55
|
+
if (items && '$ref' in items) {
|
|
56
|
+
const itemModel = extractRefModel(items.$ref);
|
|
57
|
+
if (itemModel) {
|
|
58
|
+
models.push(itemModel);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return models;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Infers a domain name from an API path
|
|
70
|
+
* @param apiPath The API path to infer from
|
|
71
|
+
* @returns The inferred domain name or 'default'
|
|
72
|
+
*/
|
|
73
|
+
function inferDomainFromPath(apiPath) {
|
|
74
|
+
const segment = apiPath.split('/').find((s) => s && !s.startsWith('{'));
|
|
75
|
+
return segment || 'default';
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Extracts domains from an OpenAPI specification
|
|
79
|
+
* @param spec The OpenAPI specification to extract from
|
|
80
|
+
* @param customDescriptions Optional custom descriptions for domains
|
|
81
|
+
* @returns Map of domain names to Domain objects
|
|
82
|
+
*/
|
|
83
|
+
function extractDomains(spec, customDescriptions) {
|
|
84
|
+
const domains = new Map();
|
|
85
|
+
const isV3 = 'openapi' in spec;
|
|
86
|
+
if (spec.tags) {
|
|
87
|
+
spec.tags.forEach((tag) => {
|
|
88
|
+
const description = customDescriptions?.[tag.name] ?? tag.description ?? `Operations related to ${tag.name}`;
|
|
89
|
+
domains.set(tag.name, {
|
|
90
|
+
name: tag.name,
|
|
91
|
+
description,
|
|
92
|
+
operations: [],
|
|
93
|
+
models: new Set()
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (spec.paths) {
|
|
98
|
+
Object.entries(spec.paths).forEach(([apiPath, pathItemOrRef]) => {
|
|
99
|
+
if (!pathItemOrRef) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const pathObj = pathItemOrRef;
|
|
103
|
+
exports.HTTP_METHODS.forEach((method) => {
|
|
104
|
+
const operation = pathObj[method];
|
|
105
|
+
if (!operation) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const domainName = operation.tags && operation.tags.length > 0 ? operation.tags[0] : inferDomainFromPath(apiPath);
|
|
109
|
+
if (!domains.has(domainName)) {
|
|
110
|
+
domains.set(domainName, {
|
|
111
|
+
name: domainName,
|
|
112
|
+
description: customDescriptions?.[domainName] ?? `Operations for ${domainName} (inferred from path)`,
|
|
113
|
+
operations: [],
|
|
114
|
+
models: new Set()
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const domain = domains.get(domainName);
|
|
118
|
+
domain.operations.push({
|
|
119
|
+
operationId: operation.operationId || `${method}_${apiPath.replace(/[{}/]/g, '_')}`,
|
|
120
|
+
method: method.toUpperCase(),
|
|
121
|
+
summary: operation.summary || operation.description || 'No description',
|
|
122
|
+
path: apiPath
|
|
123
|
+
});
|
|
124
|
+
if (isV3) {
|
|
125
|
+
extractModelsFromOperation(operation).forEach((model) => domain.models.add(model));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return domains;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=update-sdk-context.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-sdk-context.helpers.js","sourceRoot":"","sources":["../../../cli/genai-context/update-sdk-context.helpers.ts"],"names":[],"mappings":";;;AAyCA,0CAMC;AAOD,gEA0CC;AAOD,kDAGC;AAQD,wCAwDC;AAzID,gEAAgE;AACnD,QAAA,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAiD,CAAC;AAEzI;;;;GAIG;AACH,SAAgB,eAAe,CAAC,GAAY;IAC1C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,SAAgB,0BAA0B,CAAC,SAAkE;IAC3G,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,MAAM,WAAW,GAAG,SAAS,CAAC,WAAsD,CAAC;IACrF,IAAI,WAAW,EAAE,OAAO,EAAE,CAAC;QACzB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YACvD,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;YAC7B,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;gBAC/B,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC3C,IAAI,KAAK,EAAE,CAAC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
/**
|
|
2
|
+
* Data required to render the SDK_CONTEXT.md template
|
|
3
|
+
*/
|
|
4
|
+
export interface SdkContextTemplateData {
|
|
5
|
+
/** The npm package name of the SDK */
|
|
6
|
+
packageName: string;
|
|
7
|
+
/** The OpenAPI specification version (e.g., '3.0.2') */
|
|
8
|
+
openApiVersion: string;
|
|
9
|
+
/** The API title from the OpenAPI spec */
|
|
10
|
+
apiTitle: string;
|
|
11
|
+
/** ASCII tree representation of domain folders */
|
|
12
|
+
domainTree: string;
|
|
13
|
+
/** Markdown content describing each domain and its operations */
|
|
14
|
+
domainsSection: string;
|
|
15
|
+
/** User-provided disambiguation notes, or null for default message */
|
|
16
|
+
disambiguation: string | null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generates the SDK_CONTEXT.md content from template data
|
|
20
|
+
* @param data The template data to populate
|
|
21
|
+
* @returns The generated markdown content
|
|
22
|
+
*/
|
|
23
|
+
export declare function renderSdkContextTemplate(data: SdkContextTemplateData): Promise<string>;
|
|
24
|
+
//# sourceMappingURL=update-sdk-context.template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-sdk-context.template.d.ts","sourceRoot":"","sources":["../../../cli/genai-context/update-sdk-context.template.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,cAAc,EAAE,MAAM,CAAC;IACvB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,cAAc,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderSdkContextTemplate = renderSdkContextTemplate;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const ejs_1 = require("ejs");
|
|
6
|
+
const templatePath = (0, node_path_1.join)(__dirname, 'templates', 'SDK_CONTEXT.md.template');
|
|
7
|
+
/**
|
|
8
|
+
* Generates the SDK_CONTEXT.md content from template data
|
|
9
|
+
* @param data The template data to populate
|
|
10
|
+
* @returns The generated markdown content
|
|
11
|
+
*/
|
|
12
|
+
function renderSdkContextTemplate(data) {
|
|
13
|
+
return (0, ejs_1.renderFile)(templatePath, data);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=update-sdk-context.template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-sdk-context.template.js","sourceRoot":"","sources":["../../../cli/genai-context/update-sdk-context.template.ts"],"names":[],"mappings":";;AAgCA,4DAEC;AAlCD,yCAEmB;AACnB,6BAEa;AAEb,MAAM,YAAY,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,WAAW,EAAE,yBAAyB,CAAC,CAAC;AAoB7E;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,IAA4B;IACnE,OAAO,IAAA,gBAAU,EAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
* Extract domains from OpenAPI specification and generate SDK_CONTEXT.md
|
|
5
|
+
* for AI tools to understand the SDK structure and avoid hallucinations.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const minimist = require("minimist");
|
|
10
|
+
const update_sdk_context_cjs_1 = require("./genai-context/update-sdk-context.cjs");
|
|
11
|
+
const argv = minimist(process.argv.slice(2));
|
|
12
|
+
const help = !!argv.help;
|
|
13
|
+
const quiet = !!argv.quiet;
|
|
14
|
+
const isInteractive = !!argv.interactive || !!argv.i;
|
|
15
|
+
const domainDescriptionsFile = argv['domain-descriptions'];
|
|
16
|
+
const specPathArg = argv['spec-path'];
|
|
17
|
+
const prepareScript = argv['prepare-script'];
|
|
18
|
+
const sdkPath = argv['sdk-path'];
|
|
19
|
+
const projectPath = sdkPath ? (0, node_path_1.resolve)(process.cwd(), sdkPath) : (0, node_path_1.resolve)(process.cwd());
|
|
20
|
+
const noop = () => { };
|
|
21
|
+
// eslint-disable-next-line no-console -- only logger available
|
|
22
|
+
const logger = quiet ? { error: console.error, warn: noop, log: noop, info: noop, debug: noop } : console;
|
|
23
|
+
const run = async () => {
|
|
24
|
+
await (0, update_sdk_context_cjs_1.generateSdkContext)(projectPath, specPathArg, domainDescriptionsFile, isInteractive, prepareScript, logger);
|
|
25
|
+
};
|
|
26
|
+
if (help) {
|
|
27
|
+
// eslint-disable-next-line no-console -- Help output should always be visible even with --quiet flag
|
|
28
|
+
console.log(`Extract domains from OpenAPI specification and generate SDK_CONTEXT.md for AI tools.
|
|
29
|
+
Usage: amasdk-update-sdk-context [options]
|
|
30
|
+
|
|
31
|
+
Options:
|
|
32
|
+
--interactive, -i Run in interactive mode to validate domains and add disambiguation notes
|
|
33
|
+
--domain-descriptions Path to JSON file with custom domain descriptions
|
|
34
|
+
Format: { "domainName": "description", ... }
|
|
35
|
+
Missing domains will fallback to OpenAPI tag descriptions
|
|
36
|
+
--spec-path Path to OpenAPI specification file (default: open-api.yaml or open-api.json in project root)
|
|
37
|
+
--prepare-script Add a prepare:context script to package.json that copies SDK_CONTEXT.md to dist folder
|
|
38
|
+
--sdk-path Path to SDK directory where SDK_CONTEXT.md will be created and package.json will be modified
|
|
39
|
+
(default: current directory)
|
|
40
|
+
--quiet Suppress non-essential output
|
|
41
|
+
--help Show this help message
|
|
42
|
+
`);
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
45
|
+
void (async () => {
|
|
46
|
+
let wrapper = (fn) => fn;
|
|
47
|
+
try {
|
|
48
|
+
const { createCliWithMetrics } = await Promise.resolve().then(() => require('@o3r/telemetry'));
|
|
49
|
+
wrapper = createCliWithMetrics;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Do not throw if `@o3r/telemetry` is not installed
|
|
53
|
+
}
|
|
54
|
+
await wrapper(run, '@ama-sdk/schematics:update-sdk-context')();
|
|
55
|
+
})();
|
|
56
|
+
//# sourceMappingURL=update-sdk-genai-context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-sdk-genai-context.cjs","sourceRoot":"","sources":["../../cli/update-sdk-genai-context.cts"],"names":[],"mappings":";;AAEA;;;GAGG;;AAEH,yCAEmB;AAInB,qCAAqC;AACrC,mFAEgD;AAEhD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7C,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;AACzB,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;AAC3B,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACrD,MAAM,sBAAsB,GAAG,IAAI,CAAC,qBAAqB,CAAuB,CAAC;AACjF,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAuB,CAAC;AAC5D,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAwB,CAAC;AACpE,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAuB,CAAC;AACvD,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,IAAA,mBAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAA,mBAAO,EAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AACvF,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AACtB,+DAA+D;AAC/D,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AAE1G,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;IACrB,MAAM,IAAA,2CAAkB,EAAC,WAAW,EAAE,WAAW,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AACnH,CAAC,CAAC;AACF,IAAI,IAAI,EAAE,CAAC;IACT,qGAAqG;IACrG,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;GAcX,CAAC,CAAC;IACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,IAAI,OAAO,GAAe,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,EAAE,oBAAoB,EAAE,GAAG,2CAAa,gBAAgB,EAAC,CAAC;QAChE,OAAO,GAAG,oBAAoB,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,oDAAoD;IACtD,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,EAAE,wCAAwC,CAAC,EAAE,CAAC;AACjE,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-sdk-genai-context.d.cts","sourceRoot":"","sources":["../../cli/update-sdk-genai-context.cts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ama-sdk/schematics",
|
|
3
|
-
"version": "14.1.0-prerelease.
|
|
3
|
+
"version": "14.1.0-prerelease.41",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"nx": "nx",
|
|
12
12
|
"ng": "yarn nx",
|
|
13
13
|
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' 'schematics/**/templates/**' 'schematics/**/*.jar' dist/schematics && yarn cpy '{package,collection,migration}.json' dist",
|
|
14
|
+
"copy:templates": "yarn cpy 'cli/**/*.template' dist/cli",
|
|
14
15
|
"build": "yarn nx build ama-sdk-schematics",
|
|
15
16
|
"postbuild": "patch-package-json-main",
|
|
16
17
|
"build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest",
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"bin": {
|
|
22
23
|
"amasdk-clear-index": "./cli/clear-index.cjs",
|
|
23
24
|
"amasdk-files-pack": "./cli/files-pack.cjs",
|
|
25
|
+
"amasdk-update-sdk-context": "./cli/update-sdk-genai-context.cjs",
|
|
24
26
|
"amasdk-update-spec-from-npm": "./cli/update-spec-from-npm.cjs"
|
|
25
27
|
},
|
|
26
28
|
"ng-update": {
|
|
@@ -61,12 +63,12 @@
|
|
|
61
63
|
}
|
|
62
64
|
},
|
|
63
65
|
"peerDependencies": {
|
|
64
|
-
"@ama-sdk/core": "~14.1.0-prerelease.
|
|
66
|
+
"@ama-sdk/core": "~14.1.0-prerelease.41",
|
|
65
67
|
"@angular-devkit/core": "^21.0.0",
|
|
66
68
|
"@angular-devkit/schematics-cli": "^21.0.0",
|
|
67
69
|
"@angular/cli": "^21.0.0",
|
|
68
|
-
"@o3r/schematics": "~14.1.0-prerelease.
|
|
69
|
-
"@o3r/telemetry": "~14.1.0-prerelease.
|
|
70
|
+
"@o3r/schematics": "~14.1.0-prerelease.41",
|
|
71
|
+
"@o3r/telemetry": "~14.1.0-prerelease.41",
|
|
70
72
|
"@openapitools/openapi-generator-cli": "^2.15.0",
|
|
71
73
|
"openapi-types": "^12.0.0",
|
|
72
74
|
"type-fest": "^5.3.1",
|
|
@@ -75,8 +77,9 @@
|
|
|
75
77
|
"dependencies": {
|
|
76
78
|
"@angular-devkit/core": "~21.1.0",
|
|
77
79
|
"@angular-devkit/schematics": "~21.1.0",
|
|
78
|
-
"@o3r/schematics": "~14.1.0-prerelease.
|
|
80
|
+
"@o3r/schematics": "~14.1.0-prerelease.41",
|
|
79
81
|
"chokidar": "~5.0.0",
|
|
82
|
+
"ejs": "~3.1.9",
|
|
80
83
|
"globby": "^11.1.0",
|
|
81
84
|
"js-yaml": "^4.1.1",
|
|
82
85
|
"minimatch": "~10.2.0",
|
|
@@ -86,19 +89,20 @@
|
|
|
86
89
|
"tslib": "^2.6.2"
|
|
87
90
|
},
|
|
88
91
|
"devDependencies": {
|
|
89
|
-
"@ama-sdk/core": "~14.1.0-prerelease.
|
|
92
|
+
"@ama-sdk/core": "~14.1.0-prerelease.41",
|
|
90
93
|
"@angular-devkit/schematics-cli": "~21.1.0",
|
|
91
94
|
"@angular/cli": "~21.1.0",
|
|
92
95
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
|
|
93
96
|
"@nx/eslint-plugin": "~22.5.0",
|
|
94
97
|
"@nx/jest": "~22.5.0",
|
|
95
|
-
"@o3r/build-helpers": "~14.1.0-prerelease.
|
|
96
|
-
"@o3r/eslint-plugin": "~14.1.0-prerelease.
|
|
97
|
-
"@o3r/telemetry": "~14.1.0-prerelease.
|
|
98
|
-
"@o3r/test-helpers": "~14.1.0-prerelease.
|
|
98
|
+
"@o3r/build-helpers": "~14.1.0-prerelease.41",
|
|
99
|
+
"@o3r/eslint-plugin": "~14.1.0-prerelease.41",
|
|
100
|
+
"@o3r/telemetry": "~14.1.0-prerelease.41",
|
|
101
|
+
"@o3r/test-helpers": "~14.1.0-prerelease.41",
|
|
99
102
|
"@openapitools/openapi-generator-cli": "~2.30.0",
|
|
100
103
|
"@schematics/angular": "~21.1.0",
|
|
101
104
|
"@stylistic/eslint-plugin": "~5.7.0",
|
|
105
|
+
"@types/ejs": "^3.1.2",
|
|
102
106
|
"@types/jest": "~30.0.0",
|
|
103
107
|
"@types/js-yaml": "^4.0.5",
|
|
104
108
|
"@types/minimist": "^1.2.2",
|
|
Binary file
|