@kapeta/local-cluster-service 0.60.2 → 0.61.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.
@@ -280,6 +280,7 @@ export interface Page {
280
280
  method: string;
281
281
  conversationId: string;
282
282
  prompt: string;
283
+ shellPage?: string;
283
284
  }
284
285
  export interface StormEventPage {
285
286
  type: 'PAGE';
@@ -323,5 +324,23 @@ export interface StormEventUserJourney {
323
324
  created: number;
324
325
  payload: UserJourney;
325
326
  }
326
- export type StormEvent = StormEventCreateBlock | StormEventCreateConnection | StormEventCreatePlanProperties | StormEventInvalidResponse | StormEventPlanRetry | StormEventCreateDSL | StormEventCreateDSLResource | StormEventError | StormEventScreen | StormEventScreenCandidate | StormEventFileLogical | StormEventFileState | StormEventFileDone | StormEventFileFailed | StormEventFileChunk | StormEventDone | StormEventDefinitionChange | StormEventErrorClassifier | StormEventCodeFix | StormEventErrorDetails | StormEventBlockReady | StormEventPhases | StormEventBlockStatus | StormEventCreateDSLRetry | StormEventUserJourney | StormEventPage | StormEventPageUrl;
327
+ export interface UIShell {
328
+ name: string;
329
+ content: string;
330
+ screens: string[];
331
+ }
332
+ export interface StormEventUIShell {
333
+ type: 'UI_SHELL';
334
+ reason: string;
335
+ created: number;
336
+ payload: UIShell;
337
+ }
338
+ export interface StormEventPromptImprove {
339
+ type: 'PROMPT_IMPROVE';
340
+ reason: string;
341
+ payload: {
342
+ prompt: string;
343
+ };
344
+ }
345
+ export type StormEvent = StormEventCreateBlock | StormEventCreateConnection | StormEventCreatePlanProperties | StormEventInvalidResponse | StormEventPlanRetry | StormEventCreateDSL | StormEventCreateDSLResource | StormEventError | StormEventScreen | StormEventScreenCandidate | StormEventFileLogical | StormEventFileState | StormEventFileDone | StormEventFileFailed | StormEventFileChunk | StormEventDone | StormEventDefinitionChange | StormEventErrorClassifier | StormEventCodeFix | StormEventErrorDetails | StormEventBlockReady | StormEventPhases | StormEventBlockStatus | StormEventCreateDSLRetry | StormEventUserJourney | StormEventUIShell | StormEventPage | StormEventPageUrl | StormEventPromptImprove;
327
346
  export {};
@@ -110,24 +110,18 @@ router.post('/:handle/ui', async (req, res) => {
110
110
  try {
111
111
  const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
112
112
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
113
+ // Get user journeys
113
114
  const userJourneysStream = await stormClient_1.stormClient.createUIUserJourneys(aiRequest.prompt, conversationId);
115
+ const outerConversationId = userJourneysStream.getConversationId();
114
116
  onRequestAborted(req, res, () => {
115
117
  userJourneysStream.abort();
116
118
  });
117
119
  res.set('Content-Type', 'application/x-ndjson');
118
120
  res.set('Access-Control-Expose-Headers', stormClient_1.ConversationIdHeader);
119
- res.set(stormClient_1.ConversationIdHeader, userJourneysStream.getConversationId());
120
- const promises = {};
121
- const queue = new PromiseQueue_1.PromiseQueue(5);
122
- onRequestAborted(req, res, () => {
123
- queue.cancel();
124
- });
125
- const systemId = userJourneysStream.getConversationId();
126
- UI_SERVERS[systemId] = new UIServer_1.UIServer(systemId);
127
- await UI_SERVERS[systemId].start();
128
- userJourneysStream.on('data', async (data) => {
121
+ res.set(stormClient_1.ConversationIdHeader, outerConversationId);
122
+ const uniqueUserJourneyScreens = {};
123
+ userJourneysStream.on('data', (data) => {
129
124
  try {
130
- console.log('Processing user journey event', data);
131
125
  sendEvent(res, data);
132
126
  if (data.type !== 'USER_JOURNEY') {
133
127
  return;
@@ -136,48 +130,109 @@ router.post('/:handle/ui', async (req, res) => {
136
130
  return;
137
131
  }
138
132
  data.payload.screens.forEach((screen) => {
139
- if (screen.name in promises) {
140
- return;
133
+ if (!uniqueUserJourneyScreens[screen.name]) {
134
+ uniqueUserJourneyScreens[screen.name] = screen;
141
135
  }
142
- promises[screen.name] = queue.add(() => new Promise(async (resolve, reject) => {
143
- try {
144
- const innerConversationId = node_uuid_1.default.v4();
145
- const screenStream = await stormClient_1.stormClient.createUIPage({
146
- prompt: screen.requirements,
147
- method: screen.method,
148
- path: screen.path,
149
- description: screen.requirements,
150
- name: screen.name,
151
- title: screen.title,
152
- filename: screen.filename,
153
- storage_prefix: userJourneysStream.getConversationId() + '_',
154
- }, innerConversationId);
155
- const promises = [];
156
- screenStream.on('data', (screenData) => {
157
- if (screenData.type === 'PAGE') {
158
- screenData.payload.conversationId = innerConversationId;
159
- promises.push(sendPageEvent(userJourneysStream.getConversationId(), screenData, res));
160
- }
161
- else {
162
- sendEvent(res, screenData);
163
- }
164
- });
165
- screenStream.on('end', () => {
166
- Promise.allSettled(promises).finally(resolve);
167
- });
168
- }
169
- catch (e) {
170
- console.error('Failed to process screen', e);
171
- reject(e);
172
- }
173
- }));
174
136
  });
175
137
  }
176
138
  catch (e) {
177
139
  console.error('Failed to process event', e);
178
140
  }
179
141
  });
142
+ userJourneysStream.on('error', (error) => {
143
+ console.error('Error on userJourneysStream', error);
144
+ userJourneysStream.abort();
145
+ sendError(error, res);
146
+ });
180
147
  await waitForStormStream(userJourneysStream);
148
+ // Get the UI shells
149
+ const shellsStream = await stormClient_1.stormClient.createUIShells({
150
+ pages: Object.values(uniqueUserJourneyScreens).map((screen) => ({
151
+ name: screen.name,
152
+ title: screen.title,
153
+ filename: screen.filename,
154
+ path: screen.path,
155
+ method: screen.method,
156
+ requirements: screen.requirements,
157
+ })),
158
+ }, conversationId);
159
+ onRequestAborted(req, res, () => {
160
+ shellsStream.abort();
161
+ });
162
+ const uiShells = [];
163
+ shellsStream.on('data', (data) => {
164
+ console.log('Processing shell event', data);
165
+ sendEvent(res, data);
166
+ if (data.type !== 'UI_SHELL') {
167
+ return;
168
+ }
169
+ if (shellsStream.isAborted()) {
170
+ return;
171
+ }
172
+ uiShells.push(data.payload);
173
+ });
174
+ shellsStream.on('error', (error) => {
175
+ console.error('Error on shellsStream', error);
176
+ shellsStream.abort();
177
+ sendError(error, res);
178
+ });
179
+ await waitForStormStream(shellsStream);
180
+ UI_SERVERS[outerConversationId] = new UIServer_1.UIServer(outerConversationId);
181
+ await UI_SERVERS[outerConversationId].start();
182
+ // Get the pages (5 at a time)
183
+ const queue = new PromiseQueue_1.PromiseQueue(5);
184
+ onRequestAborted(req, res, () => {
185
+ queue.cancel();
186
+ });
187
+ for (const screen of Object.values(uniqueUserJourneyScreens)) {
188
+ await queue.add(() => new Promise(async (resolve, reject) => {
189
+ try {
190
+ const innerConversationId = node_uuid_1.default.v4();
191
+ const screenStream = await stormClient_1.stormClient.createUIPage({
192
+ prompt: screen.requirements,
193
+ method: screen.method,
194
+ path: screen.path,
195
+ description: screen.requirements,
196
+ name: screen.name,
197
+ title: screen.title,
198
+ filename: screen.filename,
199
+ storage_prefix: outerConversationId + '_',
200
+ shell_page: uiShells.find((shell) => shell.screens.includes(screen.name))?.content,
201
+ }, innerConversationId);
202
+ const promiseList = [];
203
+ screenStream.on('data', (screenData) => {
204
+ if (screenData.type === 'PAGE') {
205
+ promiseList.push(sendPageEvent(outerConversationId, {
206
+ ...screenData,
207
+ payload: {
208
+ ...screenData.payload,
209
+ conversationId: innerConversationId,
210
+ },
211
+ }, res));
212
+ }
213
+ else {
214
+ sendEvent(res, screenData);
215
+ }
216
+ });
217
+ screenStream.on('end', async () => {
218
+ try {
219
+ await Promise.allSettled(promiseList).finally(() => resolve(true));
220
+ }
221
+ catch (error) {
222
+ console.error('Failed to process screen', error);
223
+ }
224
+ });
225
+ screenStream.on('error', (error) => {
226
+ console.error('Error on screenStream', error);
227
+ screenStream.abort();
228
+ });
229
+ }
230
+ catch (e) {
231
+ console.error('Failed to process screen', e);
232
+ reject(e);
233
+ }
234
+ }));
235
+ }
181
236
  await queue.wait();
182
237
  if (userJourneysStream.isAborted()) {
183
238
  return;
@@ -2,6 +2,16 @@ import { ConversationItem, StormFileImplementationPrompt, StormStream, StormUIIm
2
2
  import { Page, StormEventPageUrl } from './events';
3
3
  export declare const STORM_ID = "storm";
4
4
  export declare const ConversationIdHeader = "Conversation-Id";
5
+ export interface UIShellsPrompt {
6
+ pages: {
7
+ name: string;
8
+ title: string;
9
+ filename: string;
10
+ path: string;
11
+ method: string;
12
+ requirements: string;
13
+ }[];
14
+ }
5
15
  export interface UIPagePrompt {
6
16
  name: string;
7
17
  title: string;
@@ -11,6 +21,7 @@ export interface UIPagePrompt {
11
21
  method: string;
12
22
  description: string;
13
23
  storage_prefix: string;
24
+ shell_page?: string;
14
25
  }
15
26
  export interface UIPageEditPrompt {
16
27
  planDescription: string;
@@ -32,6 +43,7 @@ declare class StormClient {
32
43
  createMetadata(prompt: string, conversationId?: string): Promise<StormStream>;
33
44
  createUIPages(prompt: string, conversationId?: string): Promise<StormStream>;
34
45
  createUIUserJourneys(prompt: string, conversationId?: string): Promise<StormStream>;
46
+ createUIShells(prompt: UIShellsPrompt, conversationId?: string): Promise<StormStream>;
35
47
  createUIPage(prompt: UIPagePrompt, conversationId?: string): Promise<StormStream>;
36
48
  editPages(prompt: UIPageEditPrompt, conversationId?: string): Promise<StormStream>;
37
49
  listScreens(prompt: StormUIListPrompt, conversationId?: string): Promise<StormStream>;
@@ -92,6 +92,12 @@ class StormClient {
92
92
  conversationId,
93
93
  });
94
94
  }
95
+ createUIShells(prompt, conversationId) {
96
+ return this.send('/v2/ui/shells', {
97
+ prompt: JSON.stringify(prompt),
98
+ conversationId,
99
+ });
100
+ }
95
101
  createUIPage(prompt, conversationId) {
96
102
  return this.send('/v2/ui/page', {
97
103
  prompt: prompt,
@@ -0,0 +1,143 @@
1
+ [
2
+ {
3
+ "type": "CREATE_BLOCK",
4
+ "reason": "Block updated",
5
+ "payload": {
6
+ "archetype": "",
7
+ "description": "Handles traffic from the backend services.",
8
+ "name": "api-gateway",
9
+ "resources": [
10
+ {
11
+ "description": "",
12
+ "name": "posts",
13
+ "to": "post-service",
14
+ "type": "CLIENT"
15
+ },
16
+ {
17
+ "description": "",
18
+ "name": "comments",
19
+ "to": "comment-service",
20
+ "type": "CLIENT"
21
+ }
22
+ ],
23
+ "type": "GATEWAY",
24
+ "blockRef": "kapeta://kapeta/api-gateway:local",
25
+ "instanceId": "6b247f30-dec4-5960-a8a0-f300caa95226"
26
+ },
27
+ "created": 1720784242064
28
+ },
29
+ {
30
+ "type": "CREATE_BLOCK",
31
+ "reason": "Block updated",
32
+ "payload": {
33
+ "archetype": "",
34
+ "description": "Manages the creation, editing, and deletion of blog posts.",
35
+ "name": "post-service",
36
+ "resources": [
37
+ {
38
+ "description": "The posts API provides endpoints for managing blog posts. It includes functionality for creating, editing, and deleting posts, as well as retrieving and searching for posts. The API is designed to be secure and follows best practices for authentication and authorization.",
39
+ "name": "posts",
40
+ "type": "API"
41
+ }
42
+ ],
43
+ "type": "BACKEND",
44
+ "blockRef": "kapeta://kapeta/post-service:local",
45
+ "instanceId": "4e002962-ca24-5b8b-bcea-395b9bbf7c26"
46
+ },
47
+ "created": 1720784243137
48
+ },
49
+ {
50
+ "type": "CREATE_BLOCK",
51
+ "reason": "Block updated",
52
+ "payload": {
53
+ "archetype": "",
54
+ "description": "Manages the creation, editing, and deletion of comments on blog posts.",
55
+ "name": "comment-service",
56
+ "resources": [
57
+ {
58
+ "description": "The comments API provides endpoints for managing comments on blog posts. It includes functionality for creating, editing, and deleting comments, as well as retrieving and searching for comments. The API is designed to be secure and follows best practices for authentication and authorization.",
59
+ "name": "comments",
60
+ "type": "API"
61
+ }
62
+ ],
63
+ "type": "BACKEND",
64
+ "blockRef": "kapeta://kapeta/comment-service:local",
65
+ "instanceId": "d4215220-f552-5a6d-9429-bef1c40c4d7c"
66
+ },
67
+ "created": 1720784243141
68
+ },
69
+ {
70
+ "type": "CREATE_TYPE",
71
+ "reason": "Create type for post-service",
72
+ "payload": {
73
+ "blockName": "post-service",
74
+ "content": "enum Status {\n NEW,\n ARCHIVED\n}\n\ntype Result {\n status: Status\n}\n\ntype User {\n id: string\n}",
75
+ "blockRef": "kapeta://kapeta/post-service:local",
76
+ "instanceId": "4e002962-ca24-5b8b-bcea-395b9bbf7c26"
77
+ },
78
+ "created": 1720784233286
79
+ },
80
+ {
81
+ "type": "CREATE_API",
82
+ "reason": "Create API for post-service",
83
+ "payload": {
84
+ "blockName": "post-service",
85
+ "content": "@GET(\"/status\")\ngetStatus(): Result",
86
+ "blockRef": "kapeta://kapeta/post-service:local",
87
+ "instanceId": "4e002962-ca24-5b8b-bcea-395b9bbf7c26"
88
+ },
89
+ "created": 1720784233290
90
+ },
91
+ {
92
+ "type": "CREATE_TYPE",
93
+ "reason": "Create type for comment-service",
94
+ "payload": {
95
+ "blockName": "comment-service",
96
+ "content": "enum Status {\n NEW,\n APPROVED\n}\n\ntype Result {\n status: Status\n}\n\ntype User {\n id: string\n}",
97
+ "blockRef": "kapeta://kapeta/comment-service:local",
98
+ "instanceId": "d4215220-f552-5a6d-9429-bef1c40c4d7c"
99
+ },
100
+ "created": 1720784241000
101
+ },
102
+ {
103
+ "type": "CREATE_API",
104
+ "reason": "Create API for comment-service",
105
+ "payload": {
106
+ "blockName": "comment-service",
107
+ "content": "@GET(\"/status\")\ngetStatus(): Result",
108
+ "blockRef": "kapeta://kapeta/comment-service:local",
109
+ "instanceId": "d4215220-f552-5a6d-9429-bef1c40c4d7c"
110
+ },
111
+ "created": 1720784241002
112
+ },
113
+ {
114
+ "type": "CREATE_CONNECTION",
115
+ "reason": "api-gateway needs to be able to serve the posts API from the post-service",
116
+ "payload": {
117
+ "fromComponent": "post-service",
118
+ "fromResource": "posts",
119
+ "fromResourceType": "API",
120
+ "toComponent": "api-gateway",
121
+ "toResource": "posts",
122
+ "toResourceType": "CLIENT",
123
+ "fromBlockId": "4e002962-ca24-5b8b-bcea-395b9bbf7c26",
124
+ "toBlockId": "6b247f30-dec4-5960-a8a0-f300caa95226"
125
+ },
126
+ "created": 1720784243173
127
+ },
128
+ {
129
+ "type": "CREATE_CONNECTION",
130
+ "reason": "api-gateway needs to be able to serve the comments API from the comment-service",
131
+ "payload": {
132
+ "fromComponent": "comment-service",
133
+ "fromResource": "comments",
134
+ "fromResourceType": "API",
135
+ "toComponent": "api-gateway",
136
+ "toResource": "comments",
137
+ "toResourceType": "CLIENT",
138
+ "fromBlockId": "d4215220-f552-5a6d-9429-bef1c40c4d7c",
139
+ "toBlockId": "6b247f30-dec4-5960-a8a0-f300caa95226"
140
+ },
141
+ "created": 1720784243174
142
+ }
143
+ ]
@@ -12,6 +12,8 @@ const event_parser_1 = require("../../src/storm/event-parser");
12
12
  const simple_blog_events_json_1 = __importDefault(require("./simple-blog-events.json"));
13
13
  const predefined_user_events_json_1 = __importDefault(require("./predefined-user-events.json"));
14
14
  const blog_events_json_1 = __importDefault(require("./blog-events.json"));
15
+ const duplicate_entities_events_json_1 = __importDefault(require("./duplicate-entities-events.json"));
16
+ const kaplang_core_1 = require("@kapeta/kaplang-core");
15
17
  exports.parserOptions = {
16
18
  serviceKind: 'kapeta/block-service:local',
17
19
  serviceLanguage: 'kapeta/language-target-java-spring-boot:local',
@@ -217,4 +219,33 @@ describe('event-parser', () => {
217
219
  const safeName = event_parser_1.StormEventParser.toSafeArtifactName('Browser-based CRM Application');
218
220
  expect(safeName).toBe('browserbasedcrmapplication');
219
221
  });
222
+ it('rename duplicate entity names', async () => {
223
+ const events = duplicate_entities_events_json_1.default;
224
+ const parser = new event_parser_1.StormEventParser(exports.parserOptions);
225
+ for (const event of events) {
226
+ await parser.processEvent('kapeta', event);
227
+ }
228
+ const result = await parser.toResult('kapeta');
229
+ const apiGateway = result.blocks.find((block) => block.aiName === 'api-gateway');
230
+ expect(apiGateway).toBeDefined();
231
+ const dataTypes = kaplang_core_1.DSLDataTypeParser.parse(apiGateway.content.spec.entities.source.value, {
232
+ ignoreSemantics: true,
233
+ });
234
+ expect(dataTypes.map((type) => type.name)).toStrictEqual(['Status', 'Result', 'User', 'Status_1', 'Result_1']);
235
+ const conflictingType = dataTypes.find((type) => type.name === 'Result_1');
236
+ expect(conflictingType).toBeDefined();
237
+ const dataType = conflictingType;
238
+ expect(dataType.properties?.length).toBe(1);
239
+ const dslDataTypeProperty = dataType.properties[0];
240
+ expect(dslDataTypeProperty.type).toBe('Status_1');
241
+ const commentsClient = apiGateway?.content.spec.consumers?.find((resource) => resource.metadata.name === 'comments');
242
+ expect(commentsClient).toBeDefined();
243
+ const methods = kaplang_core_1.DSLAPIParser.parse(commentsClient.spec.source.value, {
244
+ ignoreSemantics: true,
245
+ });
246
+ expect(methods).toBeDefined();
247
+ expect(methods.length).toBe(1);
248
+ const method = methods[0];
249
+ expect(method.returnType).toBe('Result_1');
250
+ });
220
251
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.60.2",
3
+ "version": "0.61.0",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -24,12 +24,16 @@ import {
24
24
  import { KapetaURI, normalizeKapetaUri, parseKapetaUri } from '@kapeta/nodejs-utils';
25
25
  import {
26
26
  DSLAPIParser,
27
+ DSLCompatibilityHelper,
27
28
  DSLController,
28
29
  DSLConverters,
30
+ DSLData,
29
31
  DSLDataTypeParser,
30
32
  DSLEntityType,
31
33
  DSLMethod,
32
34
  DSLParser,
35
+ DSLReferenceResolver,
36
+ DSLTypeHelper,
33
37
  KAPLANG_ID,
34
38
  KAPLANG_VERSION,
35
39
  KaplangWriter,
@@ -413,13 +417,11 @@ export class StormEventParser {
413
417
  return;
414
418
  }
415
419
 
416
- const apiResource = apiProviderBlock.content.spec.providers?.find(
417
- (p) => {
418
- const pKind = normalizeKapetaUri(p.kind);
419
- const apiKind = normalizeKapetaUri(this.options.apiKind);
420
- return pKind === apiKind && p.metadata.name === apiConnection.fromResource
421
- }
422
- );
420
+ const apiResource = apiProviderBlock.content.spec.providers?.find((p) => {
421
+ const pKind = normalizeKapetaUri(p.kind);
422
+ const apiKind = normalizeKapetaUri(this.options.apiKind);
423
+ return pKind === apiKind && p.metadata.name === apiConnection.fromResource;
424
+ });
423
425
 
424
426
  if (!apiResource) {
425
427
  if (warn) {
@@ -454,6 +456,8 @@ export class StormEventParser {
454
456
  return;
455
457
  }
456
458
 
459
+ const renamedEntities: { [from: string]: string } = {};
460
+
457
461
  if (apiProviderBlock.content.spec.entities?.source?.value) {
458
462
  if (!clientConsumerBlock.content.spec.entities) {
459
463
  clientConsumerBlock.content.spec.entities = {
@@ -473,19 +477,99 @@ export class StormEventParser {
473
477
  const apiTypes = DSLDataTypeParser.parse(apiProviderBlock.content.spec.entities?.source?.value, {
474
478
  ignoreSemantics: true,
475
479
  });
480
+ const newTypes: DSLData[] = [];
481
+
482
+ const clientTypeExists = function (apiType: DSLData): boolean {
483
+ const clientType = clientTypes.find((t) => t.name === apiType.name);
484
+ return clientType != undefined;
485
+ };
486
+
487
+ const clientTypeIsCompatible = function (apiType: DSLData): boolean {
488
+ const clientType = clientTypes.find((t) => t.name === apiType.name);
489
+ return (
490
+ clientType != undefined &&
491
+ DSLCompatibilityHelper.isDataCompatible(apiType, clientType, apiTypes, clientTypes)
492
+ );
493
+ };
476
494
 
477
495
  apiTypes.forEach((apiType) => {
478
- if (clientTypes.some((clientType) => clientType.name === apiType.name)) {
479
- // Already exists
496
+ if (!clientTypeExists(apiType)) {
497
+ newTypes.push(apiType);
480
498
  return;
481
499
  }
482
- clientTypes.push(apiType);
500
+
501
+ if (clientTypeIsCompatible(apiType)) {
502
+ return;
503
+ }
504
+
505
+ const originalName = apiType.name;
506
+ const toEntity = _.cloneDeep(apiType);
507
+ let conflictCount = 1;
508
+
509
+ while (clientTypeExists(toEntity) && !clientTypeIsCompatible(toEntity)) {
510
+ toEntity.name = `${originalName}_${conflictCount}`;
511
+ conflictCount++;
512
+ }
513
+
514
+ newTypes.push(toEntity);
515
+ renamedEntities[originalName] = toEntity.name;
516
+ });
517
+
518
+ Object.entries(renamedEntities).forEach(([from, to]) => {
519
+ newTypes.forEach((newType) => {
520
+ if (newType.type !== DSLEntityType.DATATYPE) {
521
+ return;
522
+ }
523
+
524
+ if (!newType.properties) {
525
+ return;
526
+ }
527
+
528
+ newType.properties.forEach((property) => {
529
+ const type = DSLTypeHelper.asType(property.type);
530
+
531
+ if (from !== type.name) {
532
+ return;
533
+ }
534
+
535
+ type.name = to;
536
+ property.type = type;
537
+ });
538
+ });
483
539
  });
484
540
 
485
- clientConsumerBlock.content.spec.entities.source!.value = KaplangWriter.write(clientTypes);
541
+ clientConsumerBlock.content.spec.entities.source!.value = KaplangWriter.write([
542
+ ...clientTypes,
543
+ ...newTypes,
544
+ ]);
486
545
  }
546
+
487
547
  clientResource.spec.methods = apiResource.spec.methods;
488
- clientResource.spec.source = apiResource.spec.source;
548
+
549
+ if (Object.keys(renamedEntities).length == 0) {
550
+ clientResource.spec.source = apiResource.spec.source;
551
+ } else {
552
+ // entities were renamed - rename references as well
553
+ const targetSource = _.cloneDeep(apiResource.spec.source);
554
+ const methods = DSLAPIParser.parse(targetSource.value, {
555
+ ignoreSemantics: true,
556
+ });
557
+
558
+ const resolver = new DSLReferenceResolver();
559
+ resolver.visitReferences(methods, (name) => {
560
+ const type = DSLTypeHelper.asType(name);
561
+
562
+ if (renamedEntities[type.name]) {
563
+ type.name = renamedEntities[type.name];
564
+ return type;
565
+ }
566
+
567
+ return name;
568
+ });
569
+
570
+ targetSource.value = KaplangWriter.write(methods);
571
+ clientResource.spec.source = targetSource;
572
+ }
489
573
  });
490
574
 
491
575
  const connections: Connection[] = this.connections.map((connection) => {
@@ -802,13 +886,11 @@ export class StormEventParser {
802
886
  return;
803
887
  }
804
888
 
805
- const apiResource = apiProviderBlock.content.spec.providers?.find(
806
- (p) => {
807
- const pKind = normalizeKapetaUri(p.kind);
808
- const apiKind = normalizeKapetaUri(this.options.apiKind);
809
- return pKind === apiKind && p.metadata.name === connection.fromResource
810
- }
811
- );
889
+ const apiResource = apiProviderBlock.content.spec.providers?.find((p) => {
890
+ const pKind = normalizeKapetaUri(p.kind);
891
+ const apiKind = normalizeKapetaUri(this.options.apiKind);
892
+ return pKind === apiKind && p.metadata.name === connection.fromResource;
893
+ });
812
894
 
813
895
  if (!apiResource) {
814
896
  if (warn) {
@@ -332,6 +332,7 @@ export interface Page {
332
332
  method: string;
333
333
  conversationId: string;
334
334
  prompt: string;
335
+ shellPage?: string;
335
336
  }
336
337
 
337
338
  // Event for creating a page
@@ -384,6 +385,27 @@ export interface StormEventUserJourney {
384
385
  payload: UserJourney;
385
386
  }
386
387
 
388
+ export interface UIShell {
389
+ name: string;
390
+ content: string;
391
+ screens: string[];
392
+ }
393
+
394
+ export interface StormEventUIShell {
395
+ type: 'UI_SHELL';
396
+ reason: string;
397
+ created: number;
398
+ payload: UIShell;
399
+ }
400
+
401
+ export interface StormEventPromptImprove {
402
+ type: 'PROMPT_IMPROVE';
403
+ reason: string;
404
+ payload: {
405
+ prompt: string;
406
+ };
407
+ }
408
+
387
409
  export type StormEvent =
388
410
  | StormEventCreateBlock
389
411
  | StormEventCreateConnection
@@ -410,5 +432,7 @@ export type StormEvent =
410
432
  | StormEventBlockStatus
411
433
  | StormEventCreateDSLRetry
412
434
  | StormEventUserJourney
435
+ | StormEventUIShell
413
436
  | StormEventPage
414
- | StormEventPageUrl;
437
+ | StormEventPageUrl
438
+ | StormEventPromptImprove;