@kapeta/local-cluster-service 0.76.2 → 0.76.3

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.76.3](https://github.com/kapetacom/local-cluster-service/compare/v0.76.2...v0.76.3) (2024-10-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Catch errors and return empty HTMPPage array ([01f780e](https://github.com/kapetacom/local-cluster-service/commit/01f780e0e808c9d2e26c44f9330df75dda09a6f5))
7
+
1
8
  ## [0.76.2](https://github.com/kapetacom/local-cluster-service/compare/v0.76.1...v0.76.2) (2024-09-30)
2
9
 
3
10
 
@@ -607,7 +607,7 @@ router.post('/ui/vote', async (req, res) => {
607
607
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
608
608
  const { topic, vote, mainConversationId } = aiRequest;
609
609
  try {
610
- const stormClient = new stormClient_1.StormClient("", mainConversationId);
610
+ const stormClient = new stormClient_1.StormClient('', mainConversationId);
611
611
  await stormClient.voteUIPage(topic, conversationId, vote, mainConversationId);
612
612
  }
613
613
  catch (e) {
@@ -619,7 +619,7 @@ router.post('/ui/get-vote', async (req, res) => {
619
619
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
620
620
  const { topic, mainConversationId } = aiRequest;
621
621
  try {
622
- const stormClient = new stormClient_1.StormClient("", mainConversationId);
622
+ const stormClient = new stormClient_1.StormClient('', mainConversationId);
623
623
  const vote = await stormClient.getVoteUIPage(topic, conversationId, mainConversationId);
624
624
  res.send({ vote });
625
625
  }
@@ -25,7 +25,7 @@ class StormClient {
25
25
  _handle;
26
26
  constructor(handle, systemId) {
27
27
  this._baseUrl = (0, utils_1.getRemoteUrl)('ai-service', 'https://ai.kapeta.com');
28
- this._systemId = systemId || "";
28
+ this._systemId = systemId || '';
29
29
  this._handle = handle;
30
30
  }
31
31
  async createOptions(path, method, body) {
@@ -148,15 +148,25 @@ class StormClient {
148
148
  }
149
149
  async replaceMockWithAPICall(prompt) {
150
150
  const u = `${this._baseUrl}/v2/ui/implement-api-clients-all`;
151
- const response = await fetch(u, {
152
- method: 'POST',
153
- body: JSON.stringify(prompt.pages),
154
- headers: {
155
- 'systemId': prompt.systemId,
156
- 'conversationId': prompt.systemId,
157
- },
158
- });
159
- return (await response.json());
151
+ try {
152
+ const response = await fetch(u, {
153
+ method: 'POST',
154
+ body: JSON.stringify(prompt.pages),
155
+ headers: {
156
+ systemId: prompt.systemId,
157
+ conversationId: prompt.systemId,
158
+ },
159
+ });
160
+ if (!response.ok) {
161
+ console.error('Failed to implement api clients', response.status, await response.text());
162
+ return [];
163
+ }
164
+ return (await response.json());
165
+ }
166
+ catch (error) {
167
+ console.error('Failed to implement api clients', error);
168
+ return [];
169
+ }
160
170
  }
161
171
  async generatePrompt(pages) {
162
172
  const u = `${this._baseUrl}/v2/ui/prompt`;
@@ -607,7 +607,7 @@ router.post('/ui/vote', async (req, res) => {
607
607
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
608
608
  const { topic, vote, mainConversationId } = aiRequest;
609
609
  try {
610
- const stormClient = new stormClient_1.StormClient("", mainConversationId);
610
+ const stormClient = new stormClient_1.StormClient('', mainConversationId);
611
611
  await stormClient.voteUIPage(topic, conversationId, vote, mainConversationId);
612
612
  }
613
613
  catch (e) {
@@ -619,7 +619,7 @@ router.post('/ui/get-vote', async (req, res) => {
619
619
  const aiRequest = JSON.parse(req.stringBody ?? '{}');
620
620
  const { topic, mainConversationId } = aiRequest;
621
621
  try {
622
- const stormClient = new stormClient_1.StormClient("", mainConversationId);
622
+ const stormClient = new stormClient_1.StormClient('', mainConversationId);
623
623
  const vote = await stormClient.getVoteUIPage(topic, conversationId, mainConversationId);
624
624
  res.send({ vote });
625
625
  }
@@ -25,7 +25,7 @@ class StormClient {
25
25
  _handle;
26
26
  constructor(handle, systemId) {
27
27
  this._baseUrl = (0, utils_1.getRemoteUrl)('ai-service', 'https://ai.kapeta.com');
28
- this._systemId = systemId || "";
28
+ this._systemId = systemId || '';
29
29
  this._handle = handle;
30
30
  }
31
31
  async createOptions(path, method, body) {
@@ -148,15 +148,25 @@ class StormClient {
148
148
  }
149
149
  async replaceMockWithAPICall(prompt) {
150
150
  const u = `${this._baseUrl}/v2/ui/implement-api-clients-all`;
151
- const response = await fetch(u, {
152
- method: 'POST',
153
- body: JSON.stringify(prompt.pages),
154
- headers: {
155
- 'systemId': prompt.systemId,
156
- 'conversationId': prompt.systemId,
157
- },
158
- });
159
- return (await response.json());
151
+ try {
152
+ const response = await fetch(u, {
153
+ method: 'POST',
154
+ body: JSON.stringify(prompt.pages),
155
+ headers: {
156
+ systemId: prompt.systemId,
157
+ conversationId: prompt.systemId,
158
+ },
159
+ });
160
+ if (!response.ok) {
161
+ console.error('Failed to implement api clients', response.status, await response.text());
162
+ return [];
163
+ }
164
+ return (await response.json());
165
+ }
166
+ catch (error) {
167
+ console.error('Failed to implement api clients', error);
168
+ return [];
169
+ }
160
170
  }
161
171
  async generatePrompt(pages) {
162
172
  const u = `${this._baseUrl}/v2/ui/prompt`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.76.2",
3
+ "version": "0.76.3",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -163,7 +163,7 @@ router.post('/ui/create-system/:handle/:systemId', async (req: KapetaBodyRequest
163
163
  sendEvent(res, createPhaseStartEvent(StormEventPhaseType.IMPLEMENT_APIS));
164
164
 
165
165
  const pagesFromDisk = readFilesAndContent(srcDir);
166
- const client = new StormClient(handle, systemId)
166
+ const client = new StormClient(handle, systemId);
167
167
  const pagesWithImplementation = await client.replaceMockWithAPICall({
168
168
  pages: pagesFromDisk,
169
169
  systemId: systemId,
@@ -756,7 +756,7 @@ router.post('/ui/vote', async (req: KapetaBodyRequest, res: Response) => {
756
756
  const aiRequest: UIPageVoteRequest = JSON.parse(req.stringBody ?? '{}');
757
757
  const { topic, vote, mainConversationId } = aiRequest;
758
758
  try {
759
- const stormClient = new StormClient("", mainConversationId);
759
+ const stormClient = new StormClient('', mainConversationId);
760
760
  await stormClient.voteUIPage(topic, conversationId, vote, mainConversationId);
761
761
  } catch (e: any) {
762
762
  res.status(500).send({ error: e.message });
@@ -768,7 +768,7 @@ router.post('/ui/get-vote', async (req: KapetaBodyRequest, res: Response) => {
768
768
  const aiRequest: UIPageGetVoteRequest = JSON.parse(req.stringBody ?? '{}');
769
769
  const { topic, mainConversationId } = aiRequest;
770
770
  try {
771
- const stormClient = new StormClient("", mainConversationId);
771
+ const stormClient = new StormClient('', mainConversationId);
772
772
  const vote = await stormClient.getVoteUIPage(topic, conversationId, mainConversationId);
773
773
  res.send({ vote });
774
774
  } catch (e: any) {
@@ -93,7 +93,7 @@ export class StormClient {
93
93
  private readonly _handle: string;
94
94
  constructor(handle: string, systemId?: string) {
95
95
  this._baseUrl = getRemoteUrl('ai-service', 'https://ai.kapeta.com');
96
- this._systemId = systemId || "";
96
+ this._systemId = systemId || '';
97
97
  this._handle = handle;
98
98
  }
99
99
 
@@ -116,10 +116,10 @@ export class StormClient {
116
116
  headers[ConversationIdHeader] = body.conversationId;
117
117
  }
118
118
  if (this._systemId) {
119
- headers[SystemIdHeader] = this._systemId
119
+ headers[SystemIdHeader] = this._systemId;
120
120
  }
121
121
  if (this._handle) {
122
- headers[HandleHeader] = this._handle
122
+ headers[HandleHeader] = this._handle;
123
123
  }
124
124
  return {
125
125
  url,
@@ -252,15 +252,26 @@ export class StormClient {
252
252
 
253
253
  public async replaceMockWithAPICall(prompt: ImplementAPIClients): Promise<HTMLPage[]> {
254
254
  const u = `${this._baseUrl}/v2/ui/implement-api-clients-all`;
255
- const response = await fetch(u, {
256
- method: 'POST',
257
- body: JSON.stringify(prompt.pages),
258
- headers: {
259
- 'systemId': prompt.systemId,
260
- 'conversationId': prompt.systemId,
261
- },
262
- });
263
- return (await response.json()) as HTMLPage[];
255
+ try {
256
+ const response = await fetch(u, {
257
+ method: 'POST',
258
+ body: JSON.stringify(prompt.pages),
259
+ headers: {
260
+ systemId: prompt.systemId,
261
+ conversationId: prompt.systemId,
262
+ },
263
+ });
264
+
265
+ if (!response.ok) {
266
+ console.error('Failed to implement api clients', response.status, await response.text());
267
+ return [];
268
+ }
269
+
270
+ return (await response.json()) as HTMLPage[];
271
+ } catch (error) {
272
+ console.error('Failed to implement api clients', error);
273
+ return [];
274
+ }
264
275
  }
265
276
 
266
277
  public async generatePrompt(pages: string[]): Promise<string> {