@kapeta/local-cluster-service 0.57.0 → 0.58.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [0.58.0](https://github.com/kapetacom/local-cluster-service/compare/v0.57.0...v0.58.0) (2024-07-24)
2
+
3
+
4
+ ### Features
5
+
6
+ * add /ui/edit endpoint for Page edits ([#200](https://github.com/kapetacom/local-cluster-service/issues/200)) ([9ac81df](https://github.com/kapetacom/local-cluster-service/commit/9ac81dfaa200976a865a9d9387dc6d2ed58891b2))
7
+
1
8
  # [0.57.0](https://github.com/kapetacom/local-cluster-service/compare/v0.56.2...v0.57.0) (2024-07-22)
2
9
 
3
10
 
@@ -87,6 +87,38 @@ router.post('/:handle/ui', async (req, res) => {
87
87
  }
88
88
  }
89
89
  });
90
+ router.post('/ui/edit', async (req, res) => {
91
+ try {
92
+ const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
93
+ const aiRequest = JSON.parse(req.stringBody ?? '{}');
94
+ const editStream = await stormClient_1.stormClient.editPages(aiRequest.prompt, conversationId);
95
+ onRequestAborted(req, res, () => {
96
+ editStream.abort();
97
+ });
98
+ res.set('Content-Type', 'application/x-ndjson');
99
+ res.set('Access-Control-Expose-Headers', stormClient_1.ConversationIdHeader);
100
+ res.set(stormClient_1.ConversationIdHeader, editStream.getConversationId());
101
+ editStream.on('data', (data) => {
102
+ try {
103
+ sendEvent(res, data);
104
+ }
105
+ catch (e) {
106
+ console.error('Failed to process event', e);
107
+ }
108
+ });
109
+ await waitForStormStream(editStream);
110
+ if (editStream.isAborted()) {
111
+ return;
112
+ }
113
+ sendDone(res);
114
+ }
115
+ catch (err) {
116
+ sendError(err, res);
117
+ if (!res.closed) {
118
+ res.end();
119
+ }
120
+ }
121
+ });
90
122
  router.post('/:handle/all', async (req, res) => {
91
123
  const handle = req.params.handle;
92
124
  try {
@@ -9,6 +9,15 @@ interface UIPagePrompt {
9
9
  method: string;
10
10
  description: string;
11
11
  }
12
+ export interface UIPageEditPrompt {
13
+ planDescription: string;
14
+ blockDescription: string;
15
+ pages: {
16
+ filename: string;
17
+ content: string;
18
+ }[];
19
+ prompt: string;
20
+ }
12
21
  declare class StormClient {
13
22
  private readonly _baseUrl;
14
23
  constructor();
@@ -18,6 +27,7 @@ declare class StormClient {
18
27
  createUIPages(prompt: string, conversationId?: string): Promise<StormStream>;
19
28
  createUIUserJourneys(prompt: string, conversationId?: string): Promise<StormStream>;
20
29
  createUIPage(prompt: UIPagePrompt, conversationId?: string): Promise<StormStream>;
30
+ editPages(prompt: UIPageEditPrompt, conversationId?: string): Promise<StormStream>;
21
31
  listScreens(prompt: StormUIListPrompt, conversationId?: string): Promise<StormStream>;
22
32
  createUIImplementation(prompt: StormUIImplementationPrompt, conversationId?: string): Promise<StormStream>;
23
33
  createServiceImplementation(prompt: StormFileImplementationPrompt, conversationId?: string): Promise<StormStream>;
@@ -98,6 +98,12 @@ class StormClient {
98
98
  conversationId,
99
99
  });
100
100
  }
101
+ editPages(prompt, conversationId) {
102
+ return this.send('/v2/ui/edit', {
103
+ prompt: JSON.stringify(prompt),
104
+ conversationId,
105
+ });
106
+ }
101
107
  listScreens(prompt, conversationId) {
102
108
  return this.send('/v2/ui/list', {
103
109
  prompt,
@@ -87,6 +87,38 @@ router.post('/:handle/ui', async (req, res) => {
87
87
  }
88
88
  }
89
89
  });
90
+ router.post('/ui/edit', async (req, res) => {
91
+ try {
92
+ const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
93
+ const aiRequest = JSON.parse(req.stringBody ?? '{}');
94
+ const editStream = await stormClient_1.stormClient.editPages(aiRequest.prompt, conversationId);
95
+ onRequestAborted(req, res, () => {
96
+ editStream.abort();
97
+ });
98
+ res.set('Content-Type', 'application/x-ndjson');
99
+ res.set('Access-Control-Expose-Headers', stormClient_1.ConversationIdHeader);
100
+ res.set(stormClient_1.ConversationIdHeader, editStream.getConversationId());
101
+ editStream.on('data', (data) => {
102
+ try {
103
+ sendEvent(res, data);
104
+ }
105
+ catch (e) {
106
+ console.error('Failed to process event', e);
107
+ }
108
+ });
109
+ await waitForStormStream(editStream);
110
+ if (editStream.isAborted()) {
111
+ return;
112
+ }
113
+ sendDone(res);
114
+ }
115
+ catch (err) {
116
+ sendError(err, res);
117
+ if (!res.closed) {
118
+ res.end();
119
+ }
120
+ }
121
+ });
90
122
  router.post('/:handle/all', async (req, res) => {
91
123
  const handle = req.params.handle;
92
124
  try {
@@ -9,6 +9,15 @@ interface UIPagePrompt {
9
9
  method: string;
10
10
  description: string;
11
11
  }
12
+ export interface UIPageEditPrompt {
13
+ planDescription: string;
14
+ blockDescription: string;
15
+ pages: {
16
+ filename: string;
17
+ content: string;
18
+ }[];
19
+ prompt: string;
20
+ }
12
21
  declare class StormClient {
13
22
  private readonly _baseUrl;
14
23
  constructor();
@@ -18,6 +27,7 @@ declare class StormClient {
18
27
  createUIPages(prompt: string, conversationId?: string): Promise<StormStream>;
19
28
  createUIUserJourneys(prompt: string, conversationId?: string): Promise<StormStream>;
20
29
  createUIPage(prompt: UIPagePrompt, conversationId?: string): Promise<StormStream>;
30
+ editPages(prompt: UIPageEditPrompt, conversationId?: string): Promise<StormStream>;
21
31
  listScreens(prompt: StormUIListPrompt, conversationId?: string): Promise<StormStream>;
22
32
  createUIImplementation(prompt: StormUIImplementationPrompt, conversationId?: string): Promise<StormStream>;
23
33
  createServiceImplementation(prompt: StormFileImplementationPrompt, conversationId?: string): Promise<StormStream>;
@@ -98,6 +98,12 @@ class StormClient {
98
98
  conversationId,
99
99
  });
100
100
  }
101
+ editPages(prompt, conversationId) {
102
+ return this.send('/v2/ui/edit', {
103
+ prompt: JSON.stringify(prompt),
104
+ conversationId,
105
+ });
106
+ }
101
107
  listScreens(prompt, conversationId) {
102
108
  return this.send('/v2/ui/list', {
103
109
  prompt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.57.0",
3
+ "version": "0.58.0",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -12,7 +12,7 @@ import { corsHandler } from '../middleware/cors';
12
12
  import { stringBody } from '../middleware/stringBody';
13
13
  import { KapetaBodyRequest } from '../types';
14
14
  import { StormCodegenRequest, StormContextRequest, StormCreateBlockRequest, StormStream } from './stream';
15
- import { ConversationIdHeader, stormClient } from './stormClient';
15
+ import { ConversationIdHeader, stormClient, UIPageEditPrompt } from './stormClient';
16
16
  import { StormEvent, StormEventPhaseType } from './events';
17
17
  import {
18
18
  createPhaseEndEvent,
@@ -107,6 +107,45 @@ router.post('/:handle/ui', async (req: KapetaBodyRequest, res: Response) => {
107
107
  }
108
108
  });
109
109
 
110
+ router.post('/ui/edit', async (req: KapetaBodyRequest, res: Response) => {
111
+ try {
112
+ const conversationId = req.headers[ConversationIdHeader.toLowerCase()] as string | undefined;
113
+
114
+ const aiRequest: StormContextRequest<UIPageEditPrompt> = JSON.parse(req.stringBody ?? '{}');
115
+
116
+ const editStream = await stormClient.editPages(aiRequest.prompt, conversationId);
117
+
118
+ onRequestAborted(req, res, () => {
119
+ editStream.abort();
120
+ });
121
+
122
+ res.set('Content-Type', 'application/x-ndjson');
123
+ res.set('Access-Control-Expose-Headers', ConversationIdHeader);
124
+ res.set(ConversationIdHeader, editStream.getConversationId());
125
+
126
+ editStream.on('data', (data: StormEvent) => {
127
+ try {
128
+ sendEvent(res, data);
129
+ } catch (e) {
130
+ console.error('Failed to process event', e);
131
+ }
132
+ });
133
+
134
+ await waitForStormStream(editStream);
135
+
136
+ if (editStream.isAborted()) {
137
+ return;
138
+ }
139
+
140
+ sendDone(res);
141
+ } catch (err: any) {
142
+ sendError(err, res);
143
+ if (!res.closed) {
144
+ res.end();
145
+ }
146
+ }
147
+ });
148
+
110
149
  router.post('/:handle/all', async (req: KapetaBodyRequest, res: Response) => {
111
150
  const handle = req.params.handle as string;
112
151
 
@@ -29,6 +29,16 @@ interface UIPagePrompt {
29
29
  description: string;
30
30
  }
31
31
 
32
+ export interface UIPageEditPrompt {
33
+ planDescription: string;
34
+ blockDescription: string;
35
+ pages: {
36
+ filename: string;
37
+ content: string;
38
+ }[];
39
+ prompt: string;
40
+ }
41
+
32
42
  class StormClient {
33
43
  private readonly _baseUrl: string;
34
44
 
@@ -143,6 +153,13 @@ class StormClient {
143
153
  });
144
154
  }
145
155
 
156
+ public editPages(prompt: UIPageEditPrompt, conversationId?: string) {
157
+ return this.send('/v2/ui/edit', {
158
+ prompt: JSON.stringify(prompt),
159
+ conversationId,
160
+ });
161
+ }
162
+
146
163
  public listScreens(prompt: StormUIListPrompt, conversationId?: string) {
147
164
  return this.send('/v2/ui/list', {
148
165
  prompt,