@kapeta/local-cluster-service 0.63.0 → 0.64.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,17 @@
1
+ # [0.64.0](https://github.com/kapetacom/local-cluster-service/compare/v0.63.1...v0.64.0) (2024-08-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * Allow skip prompt improvement ([#220](https://github.com/kapetacom/local-cluster-service/issues/220)) ([f75847c](https://github.com/kapetacom/local-cluster-service/commit/f75847cd10549e730d2ea7efb1caa59ea0610865))
7
+
8
+ ## [0.63.1](https://github.com/kapetacom/local-cluster-service/compare/v0.63.0...v0.63.1) (2024-08-20)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * handle port conflict and hanging response on close ([#219](https://github.com/kapetacom/local-cluster-service/issues/219)) ([e4f3b26](https://github.com/kapetacom/local-cluster-service/commit/e4f3b268fec9958aa315a186a306d2350354452b))
14
+
1
15
  # [0.63.0](https://github.com/kapetacom/local-cluster-service/compare/v0.62.2...v0.63.0) (2024-08-15)
2
16
 
3
17
 
@@ -1,4 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { Server } from 'http';
1
3
  import { StormEventPage } from './events';
4
+ declare module 'express-serve-static-core' {
5
+ interface Application {
6
+ listen(port: number, callback?: (err?: Error) => void): Server;
7
+ }
8
+ }
2
9
  export declare class UIServer {
3
10
  private readonly express;
4
11
  private readonly systemId;
@@ -29,11 +29,16 @@ class UIServer {
29
29
  window.sessionStorage.clear();
30
30
  </script>`);
31
31
  });
32
- this.express.all('/*', async (req, res) => {
32
+ this.express.all('/*', (req, res) => {
33
33
  (0, page_utils_1.readPageFromDisk)(this.systemId, req.params[0], req.method, res);
34
34
  });
35
- return new Promise((resolve) => {
36
- this.server = this.express.listen(this.port, () => {
35
+ return new Promise((resolve, reject) => {
36
+ this.server = this.express.listen(this.port, (err) => {
37
+ if (err) {
38
+ console.error('Failed to start UI server', err);
39
+ reject(err);
40
+ return;
41
+ }
37
42
  console.log(`UI Server started on port ${this.port}`);
38
43
  resolve();
39
44
  });
@@ -100,13 +100,14 @@ router.delete('/:handle/ui', async (req, res) => {
100
100
  server.close();
101
101
  delete UI_SERVERS[conversationId];
102
102
  }
103
+ res.status(200).json({ status: 'ok' });
103
104
  });
104
105
  router.post('/:handle/ui/iterative', async (req, res) => {
105
106
  const handle = req.params.handle;
106
107
  try {
107
108
  const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
108
109
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
109
- const landingPagesStream = await stormClient_1.stormClient.createUILandingPages(aiRequest.prompt, conversationId);
110
+ const landingPagesStream = await stormClient_1.stormClient.createUILandingPages(aiRequest, conversationId);
110
111
  onRequestAborted(req, res, () => {
111
112
  landingPagesStream.abort();
112
113
  });
@@ -179,7 +180,7 @@ router.post('/:handle/ui', async (req, res) => {
179
180
  const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
180
181
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
181
182
  // Get user journeys
182
- const userJourneysStream = await stormClient_1.stormClient.createUIUserJourneys(aiRequest.prompt, conversationId);
183
+ const userJourneysStream = await stormClient_1.stormClient.createUIUserJourneys(aiRequest, conversationId);
183
184
  const outerConversationId = userJourneysStream.getConversationId();
184
185
  onRequestAborted(req, res, () => {
185
186
  userJourneysStream.abort();
@@ -364,7 +365,7 @@ router.post('/:handle/all', async (req, res) => {
364
365
  const eventParser = new event_parser_1.StormEventParser(stormOptions);
365
366
  const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
366
367
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
367
- const metaStream = await stormClient_1.stormClient.createMetadata(aiRequest.prompt, conversationId);
368
+ const metaStream = await stormClient_1.stormClient.createMetadata(aiRequest, conversationId);
368
369
  onRequestAborted(req, res, () => {
369
370
  metaStream.abort();
370
371
  });
@@ -38,16 +38,20 @@ export interface UIPageEditRequest {
38
38
  pages: StormEventPageUrl['payload'][];
39
39
  prompt: string;
40
40
  }
41
+ export interface BasePromptRequest {
42
+ prompt: string;
43
+ skipImprovement?: boolean;
44
+ }
41
45
  declare class StormClient {
42
46
  private readonly _baseUrl;
43
47
  constructor();
44
48
  private createOptions;
45
49
  private send;
46
- createMetadata(prompt: string, conversationId?: string): Promise<StormStream>;
50
+ createMetadata(prompt: BasePromptRequest, conversationId?: string): Promise<StormStream>;
47
51
  createUIPages(prompt: string, conversationId?: string): Promise<StormStream>;
48
- createUIUserJourneys(prompt: string, conversationId?: string): Promise<StormStream>;
52
+ createUIUserJourneys(prompt: BasePromptRequest, conversationId?: string): Promise<StormStream>;
49
53
  createUIShells(prompt: UIShellsPrompt, conversationId?: string): Promise<StormStream>;
50
- createUILandingPages(prompt: string, conversationId?: string): Promise<StormStream>;
54
+ createUILandingPages(prompt: BasePromptRequest, conversationId?: string): Promise<StormStream>;
51
55
  createUIPage(prompt: UIPagePrompt, conversationId?: string, history?: ConversationItem[]): Promise<StormStream>;
52
56
  classifyUIReferences(prompt: string, conversationId?: string): Promise<StormStream>;
53
57
  editPages(prompt: UIPageEditPrompt, conversationId?: string): Promise<StormStream>;
@@ -1,4 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { Server } from 'http';
1
3
  import { StormEventPage } from './events';
4
+ declare module 'express-serve-static-core' {
5
+ interface Application {
6
+ listen(port: number, callback?: (err?: Error) => void): Server;
7
+ }
8
+ }
2
9
  export declare class UIServer {
3
10
  private readonly express;
4
11
  private readonly systemId;
@@ -29,11 +29,16 @@ class UIServer {
29
29
  window.sessionStorage.clear();
30
30
  </script>`);
31
31
  });
32
- this.express.all('/*', async (req, res) => {
32
+ this.express.all('/*', (req, res) => {
33
33
  (0, page_utils_1.readPageFromDisk)(this.systemId, req.params[0], req.method, res);
34
34
  });
35
- return new Promise((resolve) => {
36
- this.server = this.express.listen(this.port, () => {
35
+ return new Promise((resolve, reject) => {
36
+ this.server = this.express.listen(this.port, (err) => {
37
+ if (err) {
38
+ console.error('Failed to start UI server', err);
39
+ reject(err);
40
+ return;
41
+ }
37
42
  console.log(`UI Server started on port ${this.port}`);
38
43
  resolve();
39
44
  });
@@ -100,13 +100,14 @@ router.delete('/:handle/ui', async (req, res) => {
100
100
  server.close();
101
101
  delete UI_SERVERS[conversationId];
102
102
  }
103
+ res.status(200).json({ status: 'ok' });
103
104
  });
104
105
  router.post('/:handle/ui/iterative', async (req, res) => {
105
106
  const handle = req.params.handle;
106
107
  try {
107
108
  const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
108
109
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
109
- const landingPagesStream = await stormClient_1.stormClient.createUILandingPages(aiRequest.prompt, conversationId);
110
+ const landingPagesStream = await stormClient_1.stormClient.createUILandingPages(aiRequest, conversationId);
110
111
  onRequestAborted(req, res, () => {
111
112
  landingPagesStream.abort();
112
113
  });
@@ -179,7 +180,7 @@ router.post('/:handle/ui', async (req, res) => {
179
180
  const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
180
181
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
181
182
  // Get user journeys
182
- const userJourneysStream = await stormClient_1.stormClient.createUIUserJourneys(aiRequest.prompt, conversationId);
183
+ const userJourneysStream = await stormClient_1.stormClient.createUIUserJourneys(aiRequest, conversationId);
183
184
  const outerConversationId = userJourneysStream.getConversationId();
184
185
  onRequestAborted(req, res, () => {
185
186
  userJourneysStream.abort();
@@ -364,7 +365,7 @@ router.post('/:handle/all', async (req, res) => {
364
365
  const eventParser = new event_parser_1.StormEventParser(stormOptions);
365
366
  const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
366
367
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
367
- const metaStream = await stormClient_1.stormClient.createMetadata(aiRequest.prompt, conversationId);
368
+ const metaStream = await stormClient_1.stormClient.createMetadata(aiRequest, conversationId);
368
369
  onRequestAborted(req, res, () => {
369
370
  metaStream.abort();
370
371
  });
@@ -38,16 +38,20 @@ export interface UIPageEditRequest {
38
38
  pages: StormEventPageUrl['payload'][];
39
39
  prompt: string;
40
40
  }
41
+ export interface BasePromptRequest {
42
+ prompt: string;
43
+ skipImprovement?: boolean;
44
+ }
41
45
  declare class StormClient {
42
46
  private readonly _baseUrl;
43
47
  constructor();
44
48
  private createOptions;
45
49
  private send;
46
- createMetadata(prompt: string, conversationId?: string): Promise<StormStream>;
50
+ createMetadata(prompt: BasePromptRequest, conversationId?: string): Promise<StormStream>;
47
51
  createUIPages(prompt: string, conversationId?: string): Promise<StormStream>;
48
- createUIUserJourneys(prompt: string, conversationId?: string): Promise<StormStream>;
52
+ createUIUserJourneys(prompt: BasePromptRequest, conversationId?: string): Promise<StormStream>;
49
53
  createUIShells(prompt: UIShellsPrompt, conversationId?: string): Promise<StormStream>;
50
- createUILandingPages(prompt: string, conversationId?: string): Promise<StormStream>;
54
+ createUILandingPages(prompt: BasePromptRequest, conversationId?: string): Promise<StormStream>;
51
55
  createUIPage(prompt: UIPagePrompt, conversationId?: string, history?: ConversationItem[]): Promise<StormStream>;
52
56
  classifyUIReferences(prompt: string, conversationId?: string): Promise<StormStream>;
53
57
  editPages(prompt: UIPageEditPrompt, conversationId?: string): Promise<StormStream>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.63.0",
3
+ "version": "0.64.0",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -8,6 +8,15 @@ import { clusterService } from '../clusterService';
8
8
  import { Server } from 'http';
9
9
  import { StormEventPage } from './events';
10
10
 
11
+ declare module 'express-serve-static-core' {
12
+ interface Application {
13
+ // Adds error callback support
14
+ // From the docs:
15
+ // All the forms of Node’s http.Server.listen() method are in fact actually supported.
16
+ listen(port: number, callback?: (err?: Error) => void): Server;
17
+ }
18
+ }
19
+
11
20
  export class UIServer {
12
21
  private readonly express: Express;
13
22
  private readonly systemId: string;
@@ -33,12 +42,17 @@ export class UIServer {
33
42
  );
34
43
  });
35
44
 
36
- this.express.all('/*', async (req: Request, res: Response) => {
45
+ this.express.all('/*', (req: Request, res: Response) => {
37
46
  readPageFromDisk(this.systemId, req.params[0], req.method, res);
38
47
  });
39
48
 
40
- return new Promise<void>((resolve) => {
41
- this.server = this.express.listen(this.port, () => {
49
+ return new Promise<void>((resolve, reject) => {
50
+ this.server = this.express.listen(this.port, (err) => {
51
+ if (err) {
52
+ console.error('Failed to start UI server', err);
53
+ reject(err);
54
+ return;
55
+ }
42
56
  console.log(`UI Server started on port ${this.port}`);
43
57
  resolve();
44
58
  });
@@ -19,9 +19,9 @@ import {
19
19
  UIPagePrompt,
20
20
  UIPageEditPrompt,
21
21
  UIPageEditRequest,
22
- UIPageSamplePrompt,
22
+ BasePromptRequest,
23
23
  } from './stormClient';
24
- import { Page, StormEvent, StormEventPage, StormEventPhaseType, UIShell, UserJourneyScreen } from './events';
24
+ import { Page, StormEvent, StormEventPage, StormEventPhaseType, UserJourneyScreen } from './events';
25
25
 
26
26
  import {
27
27
  createPhaseEndEvent,
@@ -33,18 +33,9 @@ import {
33
33
  import { StormCodegen } from './codegen';
34
34
  import { assetManager } from '../assetManager';
35
35
  import uuid from 'node-uuid';
36
- import { PromiseQueue } from './PromiseQueue';
37
- import {
38
- readConversationFromFile,
39
- readPageFromDisk,
40
- readPageFromDiskAsString,
41
- SystemIdHeader,
42
- writeConversationToFile,
43
- writePageToDisk,
44
- } from './page-utils';
36
+ import { readPageFromDisk, readPageFromDiskAsString, SystemIdHeader, writePageToDisk } from './page-utils';
45
37
  import { UIServer } from './UIServer';
46
38
  import { PageQueue } from './PageGenerator';
47
- import FSExtra from 'fs-extra';
48
39
 
49
40
  const UI_SERVERS: { [key: string]: UIServer } = {};
50
41
  const router = Router();
@@ -140,6 +131,7 @@ router.delete('/:handle/ui', async (req: KapetaBodyRequest, res: Response) => {
140
131
  server.close();
141
132
  delete UI_SERVERS[conversationId];
142
133
  }
134
+ res.status(200).json({ status: 'ok' });
143
135
  });
144
136
 
145
137
  router.post('/:handle/ui/iterative', async (req: KapetaBodyRequest, res: Response) => {
@@ -147,9 +139,9 @@ router.post('/:handle/ui/iterative', async (req: KapetaBodyRequest, res: Respons
147
139
  try {
148
140
  const conversationId = req.headers[ConversationIdHeader.toLowerCase()] as string | undefined;
149
141
 
150
- const aiRequest: StormContextRequest = JSON.parse(req.stringBody ?? '{}');
142
+ const aiRequest: BasePromptRequest = JSON.parse(req.stringBody ?? '{}');
151
143
 
152
- const landingPagesStream = await stormClient.createUILandingPages(aiRequest.prompt, conversationId);
144
+ const landingPagesStream = await stormClient.createUILandingPages(aiRequest, conversationId);
153
145
 
154
146
  onRequestAborted(req, res, () => {
155
147
  landingPagesStream.abort();
@@ -234,10 +226,10 @@ router.post('/:handle/ui', async (req: KapetaBodyRequest, res: Response) => {
234
226
  try {
235
227
  const conversationId = req.headers[ConversationIdHeader.toLowerCase()] as string | undefined;
236
228
 
237
- const aiRequest: StormContextRequest = JSON.parse(req.stringBody ?? '{}');
229
+ const aiRequest: BasePromptRequest = JSON.parse(req.stringBody ?? '{}');
238
230
 
239
231
  // Get user journeys
240
- const userJourneysStream = await stormClient.createUIUserJourneys(aiRequest.prompt, conversationId);
232
+ const userJourneysStream = await stormClient.createUIUserJourneys(aiRequest, conversationId);
241
233
  const outerConversationId = userJourneysStream.getConversationId();
242
234
 
243
235
  onRequestAborted(req, res, () => {
@@ -465,8 +457,8 @@ router.post('/:handle/all', async (req: KapetaBodyRequest, res: Response) => {
465
457
 
466
458
  const conversationId = req.headers[ConversationIdHeader.toLowerCase()] as string | undefined;
467
459
 
468
- const aiRequest: StormContextRequest = JSON.parse(req.stringBody ?? '{}');
469
- const metaStream = await stormClient.createMetadata(aiRequest.prompt, conversationId);
460
+ const aiRequest: BasePromptRequest = JSON.parse(req.stringBody ?? '{}');
461
+ const metaStream = await stormClient.createMetadata(aiRequest, conversationId);
470
462
 
471
463
  onRequestAborted(req, res, () => {
472
464
  metaStream.abort();
@@ -62,6 +62,11 @@ export interface UIPageEditRequest {
62
62
  prompt: string;
63
63
  }
64
64
 
65
+ export interface BasePromptRequest {
66
+ prompt: string;
67
+ skipImprovement?: boolean;
68
+ }
69
+
65
70
  class StormClient {
66
71
  private readonly _baseUrl: string;
67
72
 
@@ -148,7 +153,7 @@ class StormClient {
148
153
  return out;
149
154
  }
150
155
 
151
- public createMetadata(prompt: string, conversationId?: string) {
156
+ public createMetadata(prompt: BasePromptRequest, conversationId?: string) {
152
157
  return this.send('/v2/all', {
153
158
  prompt: prompt,
154
159
  conversationId,
@@ -162,7 +167,7 @@ class StormClient {
162
167
  });
163
168
  }
164
169
 
165
- public createUIUserJourneys(prompt: string, conversationId?: string) {
170
+ public createUIUserJourneys(prompt: BasePromptRequest, conversationId?: string) {
166
171
  return this.send('/v2/ui/user-journeys', {
167
172
  prompt: prompt,
168
173
  conversationId,
@@ -175,7 +180,7 @@ class StormClient {
175
180
  });
176
181
  }
177
182
 
178
- public createUILandingPages(prompt: string, conversationId?: string) {
183
+ public createUILandingPages(prompt: BasePromptRequest, conversationId?: string) {
179
184
  return this.send('/v2/ui/landing-pages', {
180
185
  prompt: prompt,
181
186
  conversationId,