@adminide-stack/form-builder-core 5.1.4-alpha.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +21 -0
  3. package/lib/index.d.ts +6 -0
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.js +1 -0
  6. package/lib/index.js.map +1 -0
  7. package/lib/inngest/generateFunctionCode.d.ts +9 -0
  8. package/lib/inngest/generateFunctionCode.d.ts.map +1 -0
  9. package/lib/inngest/generateFunctionCode.js +166 -0
  10. package/lib/inngest/generateFunctionCode.js.map +1 -0
  11. package/lib/inngest/interfaces/index.d.ts +2 -0
  12. package/lib/inngest/interfaces/index.d.ts.map +1 -0
  13. package/lib/inngest/interfaces/types.d.ts +48 -0
  14. package/lib/inngest/interfaces/types.d.ts.map +1 -0
  15. package/lib/inngest/monacoAutocompleteIntegration.d.ts +48 -0
  16. package/lib/inngest/monacoAutocompleteIntegration.d.ts.map +1 -0
  17. package/lib/inngest/monacoAutocompleteIntegration.js +341 -0
  18. package/lib/inngest/monacoAutocompleteIntegration.js.map +1 -0
  19. package/lib/inngest/stepGenerator.d.ts +67 -0
  20. package/lib/inngest/stepGenerator.d.ts.map +1 -0
  21. package/lib/inngest/stepGenerator.js +243 -0
  22. package/lib/inngest/stepGenerator.js.map +1 -0
  23. package/lib/utils/json.d.ts +3 -0
  24. package/lib/utils/json.d.ts.map +1 -0
  25. package/lib/utils/json.js +43 -0
  26. package/lib/utils/json.js.map +1 -0
  27. package/package.json +28 -0
  28. package/rollup.config.mjs +33 -0
  29. package/src/index.ts +5 -0
  30. package/src/inngest/MONACO_INTEGRATION_EXAMPLE.md +406 -0
  31. package/src/inngest/README_AUTOCOMPLETE.md +380 -0
  32. package/src/inngest/generateFunctionCode.ts +248 -0
  33. package/src/inngest/interfaces/index.ts +1 -0
  34. package/src/inngest/interfaces/types.ts +63 -0
  35. package/src/inngest/monacoAutocompleteIntegration.ts +432 -0
  36. package/src/inngest/stepGenerator.ts +538 -0
  37. package/src/utils/json.ts +50 -0
  38. package/tsconfig.json +14 -0
@@ -0,0 +1,341 @@
1
+ import {getStepCompletionContext,getStepTypeDefinitions}from'./stepGenerator.js';/**
2
+ * Monaco Editor Integration for JavaScript Autocomplete
3
+ *
4
+ * Integrates with the js-autocomplete-extension via command execution
5
+ * to provide intelligent code completions in step function editors.
6
+ */
7
+ /**
8
+ * Setup JavaScript autocomplete for Monaco Editor using extension commands
9
+ *
10
+ * @param monaco Monaco editor instance
11
+ * @param options Configuration options
12
+ * @param commandService Service for executing extension commands
13
+ */
14
+ async function setupMonacoAutocomplete(monaco, options = {}, commandService) {
15
+ const {
16
+ enableInngestContext = true,
17
+ customScope = [],
18
+ enableHoverInfo = true
19
+ } = options;
20
+ const commands = commandService || options.commandService;
21
+ if (!commands) {
22
+ console.warn('No command service provided, autocomplete will not be available');
23
+ return;
24
+ }
25
+ // Build scope context
26
+ const scope = [...customScope];
27
+ if (enableInngestContext) {
28
+ scope.push('step', 'event', 'run', 'sleep', 'sendEvent', 'waitForEvent');
29
+ }
30
+ // Configure TypeScript/JavaScript compiler options to prevent worker errors
31
+ const compilerOptions = {
32
+ target: monaco.languages.typescript.ScriptTarget.ES2020,
33
+ allowNonTsExtensions: true,
34
+ moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
35
+ module: monaco.languages.typescript.ModuleKind.CommonJS,
36
+ noEmit: true,
37
+ esModuleInterop: true,
38
+ allowJs: true,
39
+ checkJs: false,
40
+ noSemanticValidation: false,
41
+ noSyntaxValidation: false
42
+ };
43
+ // Set compiler options for both JavaScript and TypeScript
44
+ monaco.languages.typescript.javascriptDefaults.setCompilerOptions(compilerOptions);
45
+ monaco.languages.typescript.typescriptDefaults.setCompilerOptions(compilerOptions);
46
+ // Configure diagnostics options to prevent unnecessary worker calls
47
+ monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
48
+ noSemanticValidation: false,
49
+ noSyntaxValidation: false,
50
+ diagnosticCodesToIgnore: [1108] // Ignore "A 'return' statement can only be used within a function body"
51
+ });
52
+ monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
53
+ noSemanticValidation: false,
54
+ noSyntaxValidation: false
55
+ });
56
+ // Disable eager model sync to prevent worker trying to access non-existent models
57
+ monaco.languages.typescript.javascriptDefaults.setEagerModelSync(false);
58
+ monaco.languages.typescript.typescriptDefaults.setEagerModelSync(false);
59
+ // Register completion provider for JavaScript
60
+ monaco.languages.registerCompletionItemProvider('javascript', {
61
+ triggerCharacters: ['.', ' '],
62
+ provideCompletionItems: async (model, position) => {
63
+ try {
64
+ const text = model.getValue();
65
+ const offset = model.getOffsetAt(position);
66
+ // Call the autocomplete extension command
67
+ const result = await commands.executeCommand({
68
+ command: 'jsAutocomplete.getCompletions',
69
+ arguments: [text, offset, scope.length > 0 ? scope : undefined]
70
+ });
71
+ if (!result || !result.completions) {
72
+ return {
73
+ suggestions: []
74
+ };
75
+ }
76
+ // Convert to Monaco completion items
77
+ const suggestions = result.completions.map(completion => ({
78
+ label: completion.name,
79
+ kind: determineCompletionKind(completion.type, monaco),
80
+ documentation: formatDocumentation(completion),
81
+ insertText: completion.name,
82
+ detail: completion.type || 'any',
83
+ sortText: getSortText(completion)
84
+ }));
85
+ return {
86
+ suggestions,
87
+ incomplete: result.isIncomplete || false
88
+ };
89
+ } catch (error) {
90
+ console.error('Autocomplete error:', error);
91
+ return {
92
+ suggestions: []
93
+ };
94
+ }
95
+ },
96
+ resolveCompletionItem: async item => {
97
+ if (!enableHoverInfo) {
98
+ return item;
99
+ }
100
+ try {
101
+ // Get detailed type info for the completion
102
+ const typeInfo = await commands.executeCommand({
103
+ command: 'jsAutocomplete.getTypeInfo',
104
+ arguments: [item.label, scope.length > 0 ? scope : undefined]
105
+ });
106
+ if (typeInfo) {
107
+ item.documentation = {
108
+ value: formatDetailedDocumentation(item.label, typeInfo),
109
+ isTrusted: true
110
+ };
111
+ }
112
+ } catch (error) {
113
+ console.error('Type info resolution error:', error);
114
+ }
115
+ return item;
116
+ }
117
+ });
118
+ // Register completion provider for TypeScript
119
+ monaco.languages.registerCompletionItemProvider('typescript', {
120
+ triggerCharacters: ['.', ' '],
121
+ provideCompletionItems: async (model, position) => {
122
+ try {
123
+ const text = model.getValue();
124
+ const offset = model.getOffsetAt(position);
125
+ // Call the autocomplete extension command
126
+ const result = await commands.executeCommand({
127
+ command: 'jsAutocomplete.getCompletions',
128
+ arguments: [text, offset, scope.length > 0 ? scope : undefined]
129
+ });
130
+ if (!result || !result.completions) {
131
+ return {
132
+ suggestions: []
133
+ };
134
+ }
135
+ // Convert to Monaco completion items
136
+ const suggestions = result.completions.map(completion => ({
137
+ label: completion.name,
138
+ kind: determineCompletionKind(completion.type, monaco),
139
+ documentation: formatDocumentation(completion),
140
+ insertText: completion.name,
141
+ detail: completion.type || 'any',
142
+ sortText: getSortText(completion)
143
+ }));
144
+ return {
145
+ suggestions,
146
+ incomplete: result.isIncomplete || false
147
+ };
148
+ } catch (error) {
149
+ console.error('TypeScript autocomplete error:', error);
150
+ return {
151
+ suggestions: []
152
+ };
153
+ }
154
+ }
155
+ });
156
+ // Register hover provider for type information
157
+ if (enableHoverInfo) {
158
+ monaco.languages.registerHoverProvider('javascript', {
159
+ provideHover: async (model, position) => {
160
+ try {
161
+ const word = model.getWordAtPosition(position);
162
+ if (!word) {
163
+ return null;
164
+ }
165
+ // Get type info via extension command
166
+ const typeInfo = await commands.executeCommand({
167
+ command: 'jsAutocomplete.getTypeInfo',
168
+ arguments: [word.word, scope.length > 0 ? scope : undefined]
169
+ });
170
+ if (!typeInfo) {
171
+ return null;
172
+ }
173
+ return {
174
+ range: new monaco.Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn),
175
+ contents: [{
176
+ value: `**${word.word}**: \`${typeInfo.type || 'any'}\``
177
+ }, {
178
+ value: typeInfo.doc || 'No documentation available'
179
+ }]
180
+ };
181
+ } catch (error) {
182
+ console.error('Hover provider error:', error);
183
+ return null;
184
+ }
185
+ }
186
+ });
187
+ monaco.languages.registerHoverProvider('typescript', {
188
+ provideHover: async (model, position) => {
189
+ try {
190
+ const word = model.getWordAtPosition(position);
191
+ if (!word) {
192
+ return null;
193
+ }
194
+ const typeInfo = await commands.executeCommand({
195
+ command: 'jsAutocomplete.getTypeInfo',
196
+ arguments: [word.word, scope.length > 0 ? scope : undefined]
197
+ });
198
+ if (!typeInfo) {
199
+ return null;
200
+ }
201
+ return {
202
+ range: new monaco.Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn),
203
+ contents: [{
204
+ value: `**${word.word}**: \`${typeInfo.type || 'any'}\``
205
+ }, {
206
+ value: typeInfo.doc || 'No documentation available'
207
+ }]
208
+ };
209
+ } catch (error) {
210
+ console.error('TypeScript hover provider error:', error);
211
+ return null;
212
+ }
213
+ }
214
+ });
215
+ }
216
+ console.log('Monaco autocomplete integration setup complete');
217
+ }
218
+ /**
219
+ * Setup autocomplete for a specific Inngest step
220
+ * Provides step-specific context and completions
221
+ */
222
+ async function setupStepAutocomplete(monaco, step, code, commandService) {
223
+ const context = getStepCompletionContext(step, code);
224
+ await setupMonacoAutocomplete(monaco, {
225
+ enableInngestContext: true,
226
+ customScope: [...context.scope, ...context.variables],
227
+ enableHoverInfo: true,
228
+ commandService
229
+ }, commandService);
230
+ // Add step-specific type definitions
231
+ const typeDefinitions = getStepTypeDefinitions();
232
+ monaco.languages.typescript.javascriptDefaults.addExtraLib(typeDefinitions, 'file:///inngest-step-types.d.ts');
233
+ }
234
+ /**
235
+ * Install a library for autocomplete
236
+ */
237
+ async function installLibraryForAutocomplete(commandService, url, accessors) {
238
+ try {
239
+ await commandService.executeCommand({
240
+ command: 'jsAutocomplete.installLibrary',
241
+ arguments: [url, accessors]
242
+ });
243
+ console.log(`Library installed: ${accessors.join(', ')}`);
244
+ return true;
245
+ } catch (error) {
246
+ console.error('Failed to install library:', error);
247
+ return false;
248
+ }
249
+ }
250
+ /**
251
+ * Update autocomplete configuration
252
+ */
253
+ async function updateAutocompleteConfig(commandService, config) {
254
+ try {
255
+ await commandService.executeCommand({
256
+ command: 'jsAutocomplete.updateConfig',
257
+ arguments: [config]
258
+ });
259
+ console.log('Autocomplete config updated');
260
+ return true;
261
+ } catch (error) {
262
+ console.error('Failed to update autocomplete config:', error);
263
+ return false;
264
+ }
265
+ }
266
+ /**
267
+ * Get available type definitions
268
+ */
269
+ async function getAvailableDefinitions(commandService) {
270
+ try {
271
+ const definitions = await commandService.executeCommand({
272
+ command: 'jsAutocomplete.getAvailableDefinitions',
273
+ arguments: []
274
+ });
275
+ return definitions || [];
276
+ } catch (error) {
277
+ console.error('Failed to get available definitions:', error);
278
+ return [];
279
+ }
280
+ }
281
+ // Helper functions
282
+ function determineCompletionKind(type, monaco) {
283
+ if (!type) {
284
+ return monaco.languages.CompletionItemKind.Variable;
285
+ }
286
+ if (type.includes('fn(') || type.includes('=>')) {
287
+ return monaco.languages.CompletionItemKind.Function;
288
+ }
289
+ if (type.startsWith('class ') || type.includes('{}')) {
290
+ return monaco.languages.CompletionItemKind.Class;
291
+ }
292
+ if (type.includes('[]')) {
293
+ return monaco.languages.CompletionItemKind.Field;
294
+ }
295
+ if (type === 'number' || type === 'string' || type === 'boolean') {
296
+ return monaco.languages.CompletionItemKind.Keyword;
297
+ }
298
+ return monaco.languages.CompletionItemKind.Variable;
299
+ }
300
+ function formatDocumentation(completion) {
301
+ const parts = [];
302
+ if (completion.type) {
303
+ parts.push(`\`${completion.type}\``);
304
+ }
305
+ if (completion.doc) {
306
+ parts.push(completion.doc);
307
+ }
308
+ if (completion.url) {
309
+ parts.push(`[Documentation](${completion.url})`);
310
+ }
311
+ return parts.join('\n\n') || completion.name;
312
+ }
313
+ function formatDetailedDocumentation(name, typeInfo) {
314
+ const parts = [];
315
+ parts.push(`## ${name}`);
316
+ parts.push('');
317
+ if (typeInfo.type) {
318
+ parts.push('```typescript');
319
+ parts.push(typeInfo.type);
320
+ parts.push('```');
321
+ parts.push('');
322
+ }
323
+ if (typeInfo.doc) {
324
+ parts.push(typeInfo.doc);
325
+ parts.push('');
326
+ }
327
+ if (typeInfo.url) {
328
+ parts.push(`[View Documentation](${typeInfo.url})`);
329
+ }
330
+ return parts.join('\n');
331
+ }
332
+ function getSortText(completion) {
333
+ // Prioritize functions and commonly used types
334
+ if (completion.type?.includes('fn(') || completion.type?.includes('=>')) {
335
+ return `0_${completion.name}`;
336
+ }
337
+ if (completion.type?.startsWith('class ')) {
338
+ return `1_${completion.name}`;
339
+ }
340
+ return `2_${completion.name}`;
341
+ }export{getAvailableDefinitions,installLibraryForAutocomplete,setupMonacoAutocomplete,setupStepAutocomplete,updateAutocompleteConfig};//# sourceMappingURL=monacoAutocompleteIntegration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monacoAutocompleteIntegration.js","sources":["../../src/inngest/monacoAutocompleteIntegration.ts"],"sourcesContent":[null],"names":[],"mappings":"iFAAA;;;;;AAKG;AAKH;;;;AAII;;;AAGA,eAAA,uBAAA,CAAA,MAAA,EAAA,OAAuD,GAAA,EAAA,EAAA,cAAA,EAAA;QACvD;AACH,IAAA,oBAAA,GAAA,IAAA;AAED,IAAA,WAAA,GAAA,EAAA;;;;;;AAMG,IAAA;AACH,EAAA;AA8OA;;;AAGG,IAAA,KAAA,CAAA,IAAA,CAAA,MAAA,EAAA,OAAA,EAAA,KAAA,EAAA,OAAA,EAAA,WAAA,EAAA,cAAA,CAAA;AACH,EAAA;AAmBA;;AAEG,IAAA,MAAA,EAAA,MAAA,CAAA,SAAA,CAAA,UAAA,CAAA,YAAA,CAAA,MAAA;AACH,IAAA,oBAAsB;AAkBtB,IAAA,gBAAA,EAAA,MAAA,CAAA,SAAA,CAAA,UAAA,CAAA,oBAAA,CAAA,MAAA;;AAEG,IAAA,MAAA,EAAA,IAAA;AACH,IAAA,eAAA,EAAA;IAGQ,OAAA,EAAA,IAAA;IACA,OAAA,EAAA,KAAA;IACA,oBAAA,EAAsB,KAAG;AACzB,IAAA,kBAAkB,EAAE;AACvB,GAAA;AAeL;;AAEG,EAAA,MAAA,CAAA,SAAA,CAAA,UAAA,CAAA,kBAAA,CAAA,kBAAA,CAAA,eAAA,CAAA;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,67 @@
1
+ import type { InngestStep, ExtractedFunction } from './interfaces/types';
2
+ export type { ExtractedFunction } from './interfaces/types';
3
+ /**
4
+ * Step function generation utilities for unified code generation
5
+ * Used by both browser editor and server execution
6
+ *
7
+ * Integrates with js-autocomplete-extension for intelligent code completion
8
+ */
9
+ /**
10
+ * Get scope context for code completion in step functions
11
+ * Returns available variables and their types for autocomplete
12
+ */
13
+ export declare function getStepCompletionScope(): string[];
14
+ /**
15
+ * Get type definitions for step function context
16
+ * Used by Monaco editor for enhanced IntelliSense
17
+ */
18
+ export declare function getStepTypeDefinitions(): string;
19
+ /**
20
+ * Get autocomplete suggestions for a specific step type
21
+ * Returns context-specific completions based on step type
22
+ */
23
+ export declare function getStepTypeCompletions(stepType: string): Array<{
24
+ name: string;
25
+ snippet: string;
26
+ doc: string;
27
+ }>;
28
+ /**
29
+ * Extract variable names from step code for completion context
30
+ * Returns all declared variables in the step function
31
+ */
32
+ export declare function extractVariablesFromCode(code: string): string[];
33
+ /**
34
+ * Get completion context for a step at a specific position
35
+ * Used by Monaco editor to provide context-aware completions
36
+ */
37
+ export interface CompletionContext {
38
+ scope: string[];
39
+ typeDefinitions: string;
40
+ snippets: Array<{
41
+ name: string;
42
+ snippet: string;
43
+ doc: string;
44
+ }>;
45
+ variables: string[];
46
+ }
47
+ export declare function getStepCompletionContext(step: InngestStep, code: string): CompletionContext;
48
+ export declare function cleanStepCode(code: string): string;
49
+ export declare function extractStepVarName(code: string): string | null;
50
+ export declare function generateDefaultStepFunction(stepVar: string, stepType: string): string;
51
+ export declare function generateStepFunction(step: InngestStep | ExtractedFunction, index: number): {
52
+ code: string;
53
+ varName: string;
54
+ };
55
+ export declare function extractFunctionBody(code: string): string | null;
56
+ export declare function transformStepForExecution(stepFunction: {
57
+ code: string;
58
+ varName: string;
59
+ }, stepType: string, stepLabel: string): string;
60
+ export declare function generateInngestFunctionFromSteps(stepFunctions: Array<{
61
+ code: string;
62
+ varName: string;
63
+ type?: string;
64
+ label?: string;
65
+ }>): string;
66
+ export declare function generateFromExtractedFunctions(extractedFunctions: ExtractedFunction[]): string;
67
+ //# sourceMappingURL=stepGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stepGenerator.d.ts","sourceRoot":"","sources":["../../src/inngest/stepGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGzE,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;;;;GAKG;AAEH;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAejD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CA+C/C;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAsD9G;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAmB/D;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAS3F;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAGD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG9D;AAGD,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA4FrF;AAGD,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,WAAW,GAAG,iBAAiB,EACrC,KAAK,EAAE,MAAM,GACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAYnC;AAGD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA0E/D;AAED,wBAAgB,yBAAyB,CACrC,YAAY,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAC/C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAClB,MAAM,CAsER;AAGD,wBAAgB,gCAAgC,CAC5C,aAAa,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GACvF,MAAM,CAgCR;AAGD,wBAAgB,8BAA8B,CAAC,kBAAkB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CA6B9F"}
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Step function generation utilities for unified code generation
3
+ * Used by both browser editor and server execution
4
+ *
5
+ * Integrates with js-autocomplete-extension for intelligent code completion
6
+ */
7
+ /**
8
+ * Get scope context for code completion in step functions
9
+ * Returns available variables and their types for autocomplete
10
+ */
11
+ function getStepCompletionScope() {
12
+ return ['step', 'event', 'run', 'sleep', 'sendEvent', 'waitForEvent', 'Promise', 'console', 'Date', 'JSON', 'Array', 'Object'];
13
+ }
14
+ /**
15
+ * Get type definitions for step function context
16
+ * Used by Monaco editor for enhanced IntelliSense
17
+ */
18
+ function getStepTypeDefinitions() {
19
+ return `
20
+ // Inngest Step API
21
+ declare const step: {
22
+ run<T>(id: string, fn: (event: any, step: any) => Promise<T> | T): Promise<T>;
23
+ sendEvent(id: string, input: { name: string; data?: any }): Promise<void>;
24
+ waitForEvent<T = any>(id: string, opts: { event: string; timeout?: string | number }): Promise<T>;
25
+ sleep(id: string, ms: string | number): Promise<void>;
26
+ };
27
+
28
+ // Event context
29
+ declare const event: {
30
+ data: any;
31
+ id: string;
32
+ name: string;
33
+ ts: number;
34
+ user?: any;
35
+ };
36
+
37
+ // Common utilities available in step functions
38
+ declare const console: {
39
+ log(...args: any[]): void;
40
+ error(...args: any[]): void;
41
+ warn(...args: any[]): void;
42
+ info(...args: any[]): void;
43
+ };
44
+
45
+ // Promise and async utilities
46
+ declare class Promise<T> {
47
+ then<TResult>(onfulfilled?: (value: T) => TResult | Promise<TResult>): Promise<TResult>;
48
+ catch<TResult>(onrejected?: (reason: any) => TResult | Promise<TResult>): Promise<TResult>;
49
+ finally(onfinally?: () => void): Promise<T>;
50
+ static all<T>(promises: Promise<T>[]): Promise<T[]>;
51
+ static race<T>(promises: Promise<T>[]): Promise<T>;
52
+ static resolve<T>(value: T): Promise<T>;
53
+ static reject(reason?: any): Promise<never>;
54
+ }
55
+
56
+ // Date utilities
57
+ declare class Date {
58
+ constructor();
59
+ constructor(value: number | string);
60
+ toISOString(): string;
61
+ getTime(): number;
62
+ static now(): number;
63
+ }
64
+ `;
65
+ }
66
+ /**
67
+ * Get autocomplete suggestions for a specific step type
68
+ * Returns context-specific completions based on step type
69
+ */
70
+ function getStepTypeCompletions(stepType) {
71
+ const completions = {
72
+ sleep: [{
73
+ name: 'step.sleep',
74
+ snippet: "await step.sleep('${1:step-id}', '${2:5s}');",
75
+ doc: 'Sleep for a specified duration. Accepts time strings like "5s", "1m", "1h"'
76
+ }],
77
+ sendEvent: [{
78
+ name: 'step.sendEvent',
79
+ snippet: `await step.sendEvent('\${1:step-id}', {
80
+ name: '\${2:event.name}',
81
+ data: {
82
+ \${3:key}: \${4:value}
83
+ }
84
+ });`,
85
+ doc: 'Send an event to trigger other workflows'
86
+ }],
87
+ waitForEvent: [{
88
+ name: 'step.waitForEvent',
89
+ snippet: `const \${1:result} = await step.waitForEvent('\${2:step-id}', {
90
+ event: '\${3:event.name}',
91
+ timeout: '\${4:60s}'
92
+ });`,
93
+ doc: 'Wait for a specific event before continuing'
94
+ }],
95
+ run: [{
96
+ name: 'step.run',
97
+ snippet: `const \${1:result} = await step.run('\${2:step-id}', async () => {
98
+ \${3:// Your logic here}
99
+ return { success: true };
100
+ });`,
101
+ doc: 'Run a unit of work with automatic retries and error handling'
102
+ }],
103
+ parallel: [{
104
+ name: 'Promise.all',
105
+ snippet: `const results = await Promise.all([
106
+ \${1:step.run('step-1', async () => { return 1; })},
107
+ \${2:step.run('step-2', async () => { return 2; })}
108
+ ]);`,
109
+ doc: 'Execute multiple steps in parallel'
110
+ }]
111
+ };
112
+ return completions[stepType] || completions.run;
113
+ }
114
+ /**
115
+ * Extract variable names from step code for completion context
116
+ * Returns all declared variables in the step function
117
+ */
118
+ function extractVariablesFromCode(code) {
119
+ const variables = [];
120
+ // Match const/let/var declarations
121
+ const declRegex = /(?:const|let|var)\s+(\w+)/g;
122
+ let match;
123
+ while ((match = declRegex.exec(code)) !== null) {
124
+ variables.push(match[1]);
125
+ }
126
+ // Match function parameters
127
+ const paramRegex = /(?:async\s+)?\(([^)]*)\)\s*=>/g;
128
+ while ((match = paramRegex.exec(code)) !== null) {
129
+ const params = match[1].split(',').map(p => p.trim().split(/\s+/)[0]);
130
+ variables.push(...params.filter(p => p && p !== ''));
131
+ }
132
+ return [...new Set(variables)]; // Remove duplicates
133
+ }
134
+ function getStepCompletionContext(step, code) {
135
+ const stepType = step.type || 'run';
136
+ return {
137
+ scope: getStepCompletionScope(),
138
+ typeDefinitions: getStepTypeDefinitions(),
139
+ snippets: getStepTypeCompletions(stepType),
140
+ variables: extractVariablesFromCode(code)
141
+ };
142
+ }
143
+ // Pass through code without any cleaning/validation
144
+ function cleanStepCode(code) {
145
+ return code;
146
+ }
147
+ // Extract step variable name from code
148
+ function extractStepVarName(code) {
149
+ const match = code.match(/const\s+(\w+)\s*=/);
150
+ return match ? match[1] : null;
151
+ }
152
+ // Extract function body from step function code
153
+ function extractFunctionBody(code) {
154
+ // Find the opening brace after the arrow or function keyword
155
+ const arrowIndex = code.indexOf('=>');
156
+ const functionIndex = code.indexOf('function');
157
+ let startIndex = -1;
158
+ if (arrowIndex !== -1) {
159
+ // Find opening brace after =>
160
+ const openBraceIndex = code.indexOf('{', arrowIndex);
161
+ if (openBraceIndex !== -1) {
162
+ startIndex = openBraceIndex + 1;
163
+ }
164
+ } else if (functionIndex !== -1) {
165
+ // Find opening brace after function declaration
166
+ const openBraceIndex = code.indexOf('{', functionIndex);
167
+ if (openBraceIndex !== -1) {
168
+ startIndex = openBraceIndex + 1;
169
+ }
170
+ }
171
+ if (startIndex === -1) {
172
+ // FALLBACK: If we can't find function wrapper, return the whole code
173
+ console.warn('Could not extract function body, returning full code');
174
+ return code;
175
+ }
176
+ // Find the matching closing brace by counting braces
177
+ let braceCount = 1;
178
+ let endIndex = startIndex;
179
+ let inString = false;
180
+ let stringChar = '';
181
+ let inTemplate = false;
182
+ while (endIndex < code.length && braceCount > 0) {
183
+ const char = code[endIndex];
184
+ const prevChar = endIndex > 0 ? code[endIndex - 1] : '';
185
+ // Handle string literals
186
+ if ((char === '"' || char === "'") && prevChar !== '\\') {
187
+ if (!inString) {
188
+ inString = true;
189
+ stringChar = char;
190
+ } else if (char === stringChar) {
191
+ inString = false;
192
+ }
193
+ }
194
+ // Handle template literals
195
+ if (char === '`' && prevChar !== '\\') {
196
+ inTemplate = !inTemplate;
197
+ }
198
+ // Only count braces outside of strings
199
+ if (!inString && !inTemplate) {
200
+ if (char === '{') {
201
+ braceCount++;
202
+ } else if (char === '}') {
203
+ braceCount--;
204
+ }
205
+ }
206
+ if (braceCount > 0) {
207
+ endIndex++;
208
+ }
209
+ }
210
+ if (braceCount === 0) {
211
+ return code.substring(startIndex, endIndex).trim();
212
+ }
213
+ // FALLBACK: Return full code if brace matching fails
214
+ console.warn('Brace matching failed, returning full code');
215
+ return code;
216
+ }
217
+ // Convert ExtractedFunction array to step functions and generate Inngest function
218
+ function generateFromExtractedFunctions(extractedFunctions) {
219
+ if (extractedFunctions.length === 0) {
220
+ return 'return { success: false, error: "No functions to execute" };';
221
+ }
222
+ // For functions that are complete workflow steps (like step_416),
223
+ // just return the code body directly without extraction
224
+ const func = extractedFunctions[0];
225
+ // Check if this is a complete function (has async function signature)
226
+ if (func.code && func.code.includes('async function')) {
227
+ // Extract just the body, preserving all helper functions and logic
228
+ const bodyMatch = func.code.match(/async function[^{]*\{([\s\S]*)\}[\s]*$/);
229
+ if (bodyMatch) {
230
+ return bodyMatch[1].trim();
231
+ }
232
+ }
233
+ // Check if code has arrow function format: const x = async (event, step) => { ... }
234
+ if (func.code && func.code.includes('async') && func.code.includes('=>')) {
235
+ const arrowBodyMatch = func.code.match(/=>\s*\{([\s\S]*)\}[\s]*;?[\s]*$/);
236
+ if (arrowBodyMatch) {
237
+ return arrowBodyMatch[1].trim();
238
+ }
239
+ }
240
+ // Fallback: return the code as-is if we can't parse it
241
+ console.warn('Could not parse function format, returning code as-is');
242
+ return func.code || 'return { success: false, error: "No code available" };';
243
+ }export{cleanStepCode,extractFunctionBody,extractStepVarName,extractVariablesFromCode,generateFromExtractedFunctions,getStepCompletionContext,getStepCompletionScope,getStepTypeCompletions,getStepTypeDefinitions};//# sourceMappingURL=stepGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stepGenerator.js","sources":["../../src/inngest/stepGenerator.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AAGA;AAEA;;;;;AAKG;AAEH;;;AAGG,EAAA,OAAA,CAAA,MAAA,EAAA,OAAA,EAAA,KAAA,EAAA,OAAA,EAAA,WAAA,EAAA,cAAA,EAAA,SAAA,EAAA,SAAA,EAAA,MAAA,EAAA,MAAA,EAAA,OAAA,EAAA,QAAA,CAAA;AACH;AAiBA;;;AAGG;AACH,SAAA,sBAAgB,GAAA;AAiDhB,EAAA,OAAA;;;AAGG;AACH;;;;;AAwDA;;;AAGG;AACH;AAqBA;;;;AAIA;;;;;;;;;AAKC;AAED;AAYA;AAKA;AAMA;AA+FA;;;;;AA8FA;;;;AA6EA;;;;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ export declare function flatten(obj: Record<string, unknown>, parentKey?: string, res?: Record<string, unknown>): Record<string, unknown>;
2
+ export declare function unflatten(obj: Record<string, unknown>): {};
3
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,SAAK,EAAE,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,2BAoBtG;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,MA2BrD"}