@aexol/axolotl 1.0.6 → 2.0.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/lib/codegen/ai.js DELETED
@@ -1,90 +0,0 @@
1
- import chalk from 'chalk';
2
- import { readFileSync } from 'fs';
3
- import openai from 'openai';
4
- import clipboard from 'clipboardy';
5
- import { config } from '@aexol/axolotl-config';
6
- import * as path from 'path';
7
- import { vaildateChatModel } from "./utils.js";
8
- import { oraPromise } from 'ora';
9
- export const aiCommand = (program) => {
10
- program
11
- .command('ai')
12
- .argument('<schemaPath>')
13
- .argument('<type>')
14
- .argument('<field>')
15
- .argument('<prompt>')
16
- .argument('[existing_resolver_path]', 'path to the file containing existing implementation of resolver')
17
- .description(`${chalk.greenBright('Axolotl ai')} - resolvers creator`)
18
- .action(createResolverFile);
19
- };
20
- export const createResolverFile = async (schemaPath, type, field, prompt, existing_resolver_path) => {
21
- const cfg = config.get();
22
- let extra_prompt_info = cfg.prompt_info;
23
- const agent_model = vaildateChatModel(cfg.agent_model || 'gpt-4.1');
24
- if (extra_prompt_info?.endsWith('.txt')) {
25
- extra_prompt_info = readFileSync(path.join(process.cwd(), extra_prompt_info), 'utf-8');
26
- }
27
- const system = `You create resolvers in typescript for the following schema:
28
- \`\`\`graphql
29
- ${readFileSync(schemaPath, 'utf-8')}
30
- \`\`\`
31
-
32
- To create resolvers using axolotl use the following format for typescript code:
33
-
34
- \`\`\`typescript
35
- import { createResolvers } from '@src/axolotl.js';
36
-
37
-
38
- export default createResolvers({
39
- TYPE_NAME:{
40
- FIELD_NAME: async (YOGA, ARGS) => {
41
- RESOLVER_CODE
42
- return FIELD_RETURN
43
- }
44
- }
45
- })
46
- \`\`\`
47
-
48
- where TYPE_NAME is the user provided GraphQL Type name
49
- FIELD_NAME is the user provided field of the provided GraphQL type
50
- RESOLVER_CODE is the resolver code
51
- and FIELD_RETURN is what is returned from the resolver.
52
- ARGS are the same type as in GraphQL
53
- YOGA is of type [SOURCE,any,CTX]
54
- where SOURCE is the type passed from previous resolver. It has to be casted manually
55
- CTX is the context of yoga resolver
56
-
57
- ${extra_prompt_info ? `Also take into account that: \n${extra_prompt_info}\n` : ''}
58
-
59
- User provides graphql type and name of the field and you return the typescript resolver code and the PROMPT telling what resolver should do. Also return just the typescript code. If you want to add documentation add it in TypeScript. Don't return markdown.
60
-
61
- ${existing_resolver_path ? `Please change that in the following existing resolver code: ${readFileSync(path.join(process.cwd(), existing_resolver_path), 'utf-8')}` : ''}
62
- `;
63
- const user = `TYPE_NAME=${type}, FIELD_NAME=${field}, PROMPT=${prompt}`;
64
- const apiKey = process.env.OPEN_AI_API_KEY;
65
- if (!apiKey)
66
- throw new Error('Please provide OPEN_AI_API_KEY env variable');
67
- const ai = new openai({ apiKey: process.env.OPEN_AI_API_KEY });
68
- await oraPromise(ai.chat.completions
69
- .create({
70
- model: agent_model,
71
- messages: [
72
- {
73
- role: 'system',
74
- content: system,
75
- },
76
- {
77
- role: 'user',
78
- content: user,
79
- },
80
- ],
81
- })
82
- .then((response) => {
83
- const res = response.choices.at(0)?.message.content;
84
- if (res) {
85
- clipboard.writeSync(res);
86
- }
87
- console.log(`Generated resolver has been copied to clipboard`);
88
- }), { spinner: 'binary', text: 'Thinking' });
89
- };
90
- //# sourceMappingURL=ai.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai.js","sourceRoot":"","sources":["../../codegen/ai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,mBAA2B;AACvD,OAAO,EAAE,UAAU,EAAE,MA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CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;GACvK,CAAC;IACF,MAAM,IAAI,GAAG,aAAa,IAAI,gBAAgB,KAAK,YAAY,MAAM,EAAE,CAAC;IACxE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IAC3C,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC5E,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC;IAC/D,MAAM,UAAU,CACd,EAAE,CAAC,IAAI,CAAC,WAAW;SAChB,MAAM,CAAC;QACN,KAAK,EAAE,WAAW;QAClB,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,MAAM;aAChB;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,IAAI;aACd;SACF;KACF,CAAC;SACD,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;QACjB,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC;QACpD,IAAI,GAAG,EAAE,CAAC;YACR,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;IACjE,CAAC,CAAC,EACJ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,CACxC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const caiCommand: (program: Command) => void;
3
- export declare const createResolverFile: (schemaPath: string, prompt: string, existing_resolver_path?: string) => Promise<void>;
@@ -1,64 +0,0 @@
1
- import chalk from 'chalk';
2
- import { readFileSync } from 'fs';
3
- import openai from 'openai';
4
- import clipboard from 'clipboardy';
5
- import { config } from '@aexol/axolotl-config';
6
- import * as path from 'path';
7
- import { vaildateChatModel } from "./utils.js";
8
- import { oraPromise } from 'ora';
9
- export const caiCommand = (program) => {
10
- program
11
- .command('cai')
12
- .argument('<schemaPath>')
13
- .argument('<prompt>')
14
- .argument('[existing_resolver_path]', 'path to the file containing existing implementation of webhook')
15
- .description(`${chalk.greenBright('Axolotl ai')} - webhooks creator`)
16
- .action(createResolverFile);
17
- };
18
- export const createResolverFile = async (schemaPath, prompt, existing_resolver_path) => {
19
- const cfg = config.get();
20
- let extra_prompt_info = cfg.code_prompt_info;
21
- const agent_model = vaildateChatModel(cfg.agent_model || 'gpt-4.1');
22
- if (extra_prompt_info?.endsWith('.txt')) {
23
- extra_prompt_info = readFileSync(path.join(process.cwd(), extra_prompt_info), 'utf-8');
24
- }
25
- const system = `You create code taking into account the following schema:
26
- \`\`\`graphql
27
- ${readFileSync(schemaPath, 'utf-8')}
28
- \`\`\`
29
-
30
-
31
- ${extra_prompt_info ? `Also take into account that: \n${extra_prompt_info}\n` : ''}
32
-
33
- User provides the PROMPT telling what code should do. Also return just the typescript code. If you want to add documentation add it in TypeScript. Don't return markdown.
34
-
35
- ${existing_resolver_path ? `Please change that in the following existing code: ${readFileSync(path.join(process.cwd(), existing_resolver_path), 'utf-8')}` : ''}
36
- `;
37
- const user = `PROMPT=${prompt}`;
38
- const apiKey = process.env.OPEN_AI_API_KEY;
39
- if (!apiKey)
40
- throw new Error('Please provide OPEN_AI_API_KEY env variable');
41
- const ai = new openai({ apiKey: process.env.OPEN_AI_API_KEY });
42
- await oraPromise(ai.chat.completions
43
- .create({
44
- model: agent_model,
45
- messages: [
46
- {
47
- role: 'system',
48
- content: system,
49
- },
50
- {
51
- role: 'user',
52
- content: user,
53
- },
54
- ],
55
- })
56
- .then((response) => {
57
- const res = response.choices.at(0)?.message.content;
58
- if (res) {
59
- clipboard.writeSync(res);
60
- }
61
- console.log(`Generated code has been copied to clipboard`);
62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AC,6CAA6C,CAAC,CAAC;IAC7D,CAAC,CAAC,EACJ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,CACxC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const caiContextCommand: (program: Command) => void;
@@ -1,76 +0,0 @@
1
- import * as ts from 'typescript';
2
- import * as path from 'path';
3
- import { promises as fs } from 'fs';
4
- import chalk from 'chalk';
5
- const TSCONFIG_FILENAME = 'tsconfig.json';
6
- const OUTPUT_FILENAME = 'axolotl.txt';
7
- export const caiContextCommand = (program) => {
8
- program
9
- .command('cai-context')
10
- .description(`${chalk.greenBright('Axolotl ai')} - webhooks creator`)
11
- .action(main);
12
- };
13
- function getEntryPoints(parsedConfig) {
14
- if (Array.isArray(parsedConfig.fileNames) && parsedConfig.fileNames.length > 0) {
15
- return parsedConfig.fileNames.filter((f) => f.endsWith('.ts') || f.endsWith('.tsx'));
16
- }
17
- return [path.resolve(process.cwd(), 'src/index.ts')];
18
- }
19
- async function main() {
20
- const projectDir = process.cwd();
21
- const tsconfigPath = path.join(projectDir, TSCONFIG_FILENAME);
22
- console.log(`Reading file at: ${tsconfigPath}`);
23
- const readResult = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
24
- if (readResult.error) {
25
- throw new Error(ts.formatDiagnosticsWithColorAndContext([readResult.error], {
26
- getCanonicalFileName: (f) => f,
27
- getCurrentDirectory: process.cwd,
28
- getNewLine: () => '\n',
29
- }));
30
- }
31
- const parsedConfig = ts.parseJsonConfigFileContent(readResult.config, ts.sys, path.dirname(tsconfigPath));
32
- const entryPoints = getEntryPoints(parsedConfig);
33
- const visited = new Set();
34
- const queue = [...entryPoints];
35
- while (queue.length > 0) {
36
- const file = queue.pop();
37
- const realPath = await fs.realpath(file).catch(() => '');
38
- if (!realPath || visited.has(realPath))
39
- continue;
40
- visited.add(realPath);
41
- const content = await fs.readFile(realPath, 'utf-8').catch(() => '');
42
- if (!content)
43
- continue;
44
- const sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
45
- sourceFile.forEachChild((node) => {
46
- if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
47
- const moduleSpec = node.moduleSpecifier?.text;
48
- if (moduleSpec && !moduleSpec.startsWith('.') && !moduleSpec.startsWith('/')) {
49
- return;
50
- }
51
- if (moduleSpec) {
52
- const importedFile = ts.resolveModuleName(moduleSpec, file, parsedConfig.options, ts.sys).resolvedModule
53
- ?.resolvedFileName;
54
- if (importedFile &&
55
- (importedFile.endsWith('.ts') || importedFile.endsWith('.tsx')) &&
56
- !importedFile.includes('node_modules') &&
57
- !importedFile.endsWith('.d.ts')) {
58
- queue.push(importedFile);
59
- }
60
- }
61
- }
62
- });
63
- }
64
- const parts = [];
65
- for (const file of visited) {
66
- const relPath = path.relative(projectDir, file);
67
- const content = await fs.readFile(file, 'utf-8').catch(() => '');
68
- if (!content)
69
- continue;
70
- parts.push(`// ==== File: ${relPath} ====\n${content}\n`);
71
- }
72
- const allCode = parts.join('\n');
73
- await fs.writeFile(OUTPUT_FILENAME, allCode, 'utf-8');
74
- console.log(`Wrote ${visited.size} files (entry = ${entryPoints.join(', ')}) to "${OUTPUT_FILENAME}"`);
75
- }
76
- //# sourceMappingURL=context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../codegen/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAC1C,MAAM,eAAe,GAAG,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACpD,OAAO;SACJ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D,OAAO,CAAC,GAAG,CAAC,SAAS,OAAO,CAAC,IAAI,mBAAmB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,eAAe,GAAG,CAAC,CAAC;AACzG,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const frontendAiCommand: (program: Command) => void;
3
- export declare const createResolverFile: (schemaPath: string, prompt: string, existing_path?: string) => Promise<void>;
@@ -1,289 +0,0 @@
1
- import chalk from 'chalk';
2
- import { readFileSync } from 'fs';
3
- import openai from 'openai';
4
- import clipboard from 'clipboardy';
5
- import { config } from '@aexol/axolotl-config';
6
- import * as path from 'path';
7
- import { vaildateChatModel } from "./utils.js";
8
- import { oraPromise } from 'ora';
9
- export const frontendAiCommand = (program) => {
10
- program
11
- .command('fai')
12
- .argument('<schemaPath>')
13
- .argument('<prompt>')
14
- .argument('[existing_path]', 'path to the file containing existing implementation')
15
- .description(`${chalk.greenBright('Axolotl frontend ai')} - react components and views creator`)
16
- .action(createResolverFile);
17
- };
18
- export const createResolverFile = async (schemaPath, prompt, existing_path) => {
19
- const cfg = config.get();
20
- let extra_prompt_info = cfg.frontend_prompt_info;
21
- const agent_model = vaildateChatModel(cfg.agent_model || 'gpt-4.1');
22
- if (extra_prompt_info?.endsWith('.txt')) {
23
- extra_prompt_info = readFileSync(path.join(process.cwd(), extra_prompt_info), 'utf-8');
24
- }
25
- const system = `You create react components and views in typescript for the following schema:
26
- \`\`\`graphql
27
- ${readFileSync(schemaPath, 'utf-8')}
28
- \`\`\`
29
-
30
- You create them using tailwindV4 if you need any additional components import them from @radix/ui libraries
31
- Ensure typescript safety
32
- Use GraphQL Zeus to fetch. Here is the specification of graphql-zeus
33
-
34
- GraphQL Zeus Spec:
35
-
36
- To return the promise of type query for data object:
37
-
38
- PROMISE_RETURNING_OBJECT = Chain.[OPERATION_NAME]({
39
- ...FUNCTION_FIELD_PARAMS
40
- })(
41
- ...QUERY_OBJECT
42
- ).then ( RESPONSE_OBJECT => RESPONSE_OBJECT[OPERATION_FIELD] )
43
-
44
- FUNCTION_FIELD_PARAMS = {
45
- KEY: VALUE
46
- }
47
-
48
- QUERY_OBJECT = {
49
- ...RETURN_PARAMS
50
- }
51
-
52
- Return params is an object containing RETURN_KEY - true if it is a scalar, RETURN_PARAMS if type. Otherwise it is a function where you pass field params and type return params.
53
-
54
- RETURN_PARAMS = {
55
- RETURN_KEY: true,
56
- RETURN_KEY: {
57
- ...RETURN_PARAMS
58
- },
59
- RETURN_FUNCTION_KEY:[
60
- {
61
- ...FUNCTION_FIELD_PARAMS
62
- },
63
- {
64
- ...RETURN_PARAMS
65
- }
66
- ]
67
- }
68
-
69
- Aliases
70
- RETURN_PARAMS = {
71
- __alias: RETURN_PARAMS
72
- }
73
-
74
- Example:
75
- Given the following schema:
76
- \`\`\`graphql
77
- interface Nameable{
78
- name: String!
79
- }
80
-
81
- type Query{
82
- cardById(
83
- cardId: String
84
- ): Card
85
- """
86
- Draw a card<br>
87
- """
88
- drawCard: Card!
89
- drawChangeCard: ChangeCard!
90
- """
91
- list All Cards availble<br>
92
- """
93
- listCards: [Card!]!
94
- myStacks: [CardStack!]
95
- nameables: [Nameable!]!
96
- }
97
-
98
- """
99
- create card inputs<br>
100
- """
101
- input createCard{
102
- """
103
- The name of a card<br>
104
- """
105
- name: String!
106
- """
107
- Description of a card<br>
108
- """
109
- description: String!
110
- }
111
-
112
- """
113
- Stack of cards
114
- """
115
- type CardStack implements Nameable{
116
- cards: [Card!]
117
- name: String!
118
- }
119
-
120
- """
121
- Card used in card game<br>
122
- """
123
- type Card implements Nameable{
124
- """
125
- Attack other cards on the table , returns Cards after attack<br>
126
- """
127
- attack(
128
- """
129
- Attacked card/card ids<br>
130
- """
131
- cardID: [String!]!
132
- ): [Card!]
133
- """
134
- Description of a card<br>
135
- """
136
- description: String!
137
- id: ID!
138
- """
139
- The name of a card<br>
140
- """
141
- name: String!
142
- }
143
-
144
- type SpecialCard implements Nameable{
145
- effect: String!
146
- name: String!
147
- }
148
-
149
- type EffectCard implements Nameable{
150
- effectSize: Float!
151
- name: String!
152
- }
153
-
154
- type Mutation{
155
- """
156
- add Card to Cards database<br>
157
- """
158
- addCard(
159
- card: createCard!
160
- ): Card!
161
- }
162
-
163
- union ChangeCard = SpecialCard | EffectCard
164
-
165
- type Subscription{
166
- deck: [Card!]
167
- }
168
-
169
- schema{
170
- query: Query
171
- mutation: Mutation
172
- subscription: Subscription
173
- }
174
-
175
- \`\`\`
176
- For example to use zeus generated file located in zeus folder:
177
-
178
- \`\`\`typescript
179
- import { Chain } from './zeus';
180
-
181
- // Create a Chain client instance with the endpoint
182
- const chain = Chain('https://faker.graphqleditor.com/a-team/olympus/graphql');
183
-
184
- // Query the endpoint with Typescript autocomplete for arguments and response fields
185
- const listCardsAndDraw = await chain('query')({
186
- cardById: [
187
- {
188
- cardId: 'da21ce0a-40a0-43ba-85c2-6eec2bf1ae21',
189
- },
190
- {
191
- name: true,
192
- description: true,
193
- },
194
- ],
195
- listCards: {
196
- name: true,
197
- attack: [
198
- {
199
- cardID: [
200
- '66c1af53-7d5e-4d89-94b5-1ebf593508f6',
201
- 'fc0e5757-4d8a-4f6a-a23b-356ce167f873',
202
- ],
203
- },
204
- {
205
- name: true,
206
- },
207
- ],
208
- },
209
- drawCard: {
210
- name: true,
211
- },
212
- });
213
- \`\`\`
214
-
215
- To declare RETURN_TYPE you can also use Selector function imported from zeus. There is also FromSelector function that can convert Selector to a type which is useful to hold returned objects in state. The Selector syntax looks like that:
216
- \`\`\`typescript
217
- import { Chain, Selector } from './zeus';
218
-
219
- // Create a Chain client instance with the endpoint
220
- const chain = Chain('https://faker.graphqleditor.com/a-team/olympus/graphql');
221
-
222
- const Card = Selector('Card')({
223
- name: true,
224
- description: true,
225
- id: true
226
- })
227
-
228
- type CardType = FromSelector<typeof Card, 'Card'>
229
-
230
- // Query the endpoint with Typescript autocomplete for arguments and response fields
231
- const draw = await chain('query')({
232
- drawCard: {
233
- name: true,
234
- description: true,
235
- id: true
236
- },
237
- });
238
- \`\`\`
239
-
240
- use zeus Selector and FromSelector to construct types and ZEUS RETURN_TYPE
241
- To insert headers into Chain the syntax is following
242
-
243
- \`\`\`typescript
244
- Chain(API_URL,{
245
- headers:{
246
- HEADER_KEY:HEADER_VALUE
247
- }
248
- });
249
- \`\`\`
250
-
251
- use optional chaining for zeus response if the returned fields are optional.
252
- \`\`\`
253
-
254
-
255
-
256
- ${extra_prompt_info ? `Also take into account that: \n${extra_prompt_info}\n` : ''}
257
-
258
- User provides PROMPT telling what code should do. Also return just the typescript code. If you want to add documentation add it in TypeScript. Don't return markdown.
259
-
260
- ${existing_path ? `Please change that in the following existing code: ${readFileSync(path.join(process.cwd(), existing_path), 'utf-8')}` : ''}
261
- `;
262
- const user = `PROMPT=${prompt}`;
263
- const apiKey = process.env.OPEN_AI_API_KEY;
264
- if (!apiKey)
265
- throw new Error('Please provide OPEN_AI_API_KEY env variable');
266
- const ai = new openai({ apiKey: process.env.OPEN_AI_API_KEY });
267
- await oraPromise(ai.chat.completions
268
- .create({
269
- model: agent_model,
270
- messages: [
271
- {
272
- role: 'system',
273
- content: system,
274
- },
275
- {
276
- role: 'user',
277
- content: user,
278
- },
279
- ],
280
- })
281
- .then((response) => {
282
- const res = response.choices.at(0)?.message.content;
283
- if (res) {
284
- clipboard.writeSync(res);
285
- }
286
- console.log(`Generated code has been copied to clipboard`);
287
- }), { spinner: 'binary', text: 'Thinking' });
288
- };
289
- //# sourceMappingURL=frontendAi.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"frontendAi.js","sourceRoot":"","sources":["../../codegen/frontendAi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,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AU,EAAE,CACxC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const graphqlAiCommand: (program: Command) => void;
3
- export declare const createResolverFile: (prompt: string, existing_schema_path?: string) => Promise<void>;