@kapeta/local-cluster-service 0.76.2 → 0.76.4
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 +14 -0
- package/dist/cjs/src/storm/routes.js +2 -2
- package/dist/cjs/src/storm/stormClient.js +26 -10
- package/dist/esm/src/storm/routes.js +2 -2
- package/dist/esm/src/storm/stormClient.js +26 -10
- package/package.json +1 -1
- package/src/storm/routes.ts +3 -3
- package/src/storm/stormClient.ts +32 -12
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [0.76.4](https://github.com/kapetacom/local-cluster-service/compare/v0.76.3...v0.76.4) (2024-10-01)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* more headers for logging including handle ([0cadb9a](https://github.com/kapetacom/local-cluster-service/commit/0cadb9abae8575bf486567bb1401dcaa69866bdd))
|
7
|
+
|
8
|
+
## [0.76.3](https://github.com/kapetacom/local-cluster-service/compare/v0.76.2...v0.76.3) (2024-10-01)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* Catch errors and return empty HTMPPage array ([01f780e](https://github.com/kapetacom/local-cluster-service/commit/01f780e0e808c9d2e26c44f9330df75dda09a6f5))
|
14
|
+
|
1
15
|
## [0.76.2](https://github.com/kapetacom/local-cluster-service/compare/v0.76.1...v0.76.2) (2024-09-30)
|
2
16
|
|
3
17
|
|
@@ -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(
|
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(
|
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,26 @@ class StormClient {
|
|
148
148
|
}
|
149
149
|
async replaceMockWithAPICall(prompt) {
|
150
150
|
const u = `${this._baseUrl}/v2/ui/implement-api-clients-all`;
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
headers
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
151
|
+
try {
|
152
|
+
const headers = {};
|
153
|
+
headers[exports.HandleHeader] = this._handle;
|
154
|
+
headers[exports.ConversationIdHeader] = this._systemId;
|
155
|
+
headers[exports.SystemIdHeader] = this._systemId;
|
156
|
+
const response = await fetch(u, {
|
157
|
+
method: 'POST',
|
158
|
+
body: JSON.stringify(prompt.pages),
|
159
|
+
headers: headers,
|
160
|
+
});
|
161
|
+
if (!response.ok) {
|
162
|
+
console.error('Failed to implement api clients', response.status, await response.text());
|
163
|
+
return [];
|
164
|
+
}
|
165
|
+
return (await response.json());
|
166
|
+
}
|
167
|
+
catch (error) {
|
168
|
+
console.error('Failed to implement api clients', error);
|
169
|
+
return [];
|
170
|
+
}
|
160
171
|
}
|
161
172
|
async generatePrompt(pages) {
|
162
173
|
const u = `${this._baseUrl}/v2/ui/prompt`;
|
@@ -170,11 +181,16 @@ class StormClient {
|
|
170
181
|
}
|
171
182
|
async createSimpleBackend(handle, systemId, input) {
|
172
183
|
const u = `${this._baseUrl}/v2/create-simple-backend/${handle}/${systemId}`;
|
184
|
+
const headers = {};
|
185
|
+
headers[exports.HandleHeader] = this._handle;
|
186
|
+
headers[exports.ConversationIdHeader] = this._systemId;
|
187
|
+
headers[exports.SystemIdHeader] = this._systemId;
|
173
188
|
const response = await fetch(u, {
|
174
189
|
method: 'POST',
|
175
190
|
body: JSON.stringify({
|
176
191
|
pages: input.pages,
|
177
192
|
}),
|
193
|
+
headers: headers,
|
178
194
|
});
|
179
195
|
if (!response.ok) {
|
180
196
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
@@ -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(
|
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(
|
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,26 @@ class StormClient {
|
|
148
148
|
}
|
149
149
|
async replaceMockWithAPICall(prompt) {
|
150
150
|
const u = `${this._baseUrl}/v2/ui/implement-api-clients-all`;
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
headers
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
151
|
+
try {
|
152
|
+
const headers = {};
|
153
|
+
headers[exports.HandleHeader] = this._handle;
|
154
|
+
headers[exports.ConversationIdHeader] = this._systemId;
|
155
|
+
headers[exports.SystemIdHeader] = this._systemId;
|
156
|
+
const response = await fetch(u, {
|
157
|
+
method: 'POST',
|
158
|
+
body: JSON.stringify(prompt.pages),
|
159
|
+
headers: headers,
|
160
|
+
});
|
161
|
+
if (!response.ok) {
|
162
|
+
console.error('Failed to implement api clients', response.status, await response.text());
|
163
|
+
return [];
|
164
|
+
}
|
165
|
+
return (await response.json());
|
166
|
+
}
|
167
|
+
catch (error) {
|
168
|
+
console.error('Failed to implement api clients', error);
|
169
|
+
return [];
|
170
|
+
}
|
160
171
|
}
|
161
172
|
async generatePrompt(pages) {
|
162
173
|
const u = `${this._baseUrl}/v2/ui/prompt`;
|
@@ -170,11 +181,16 @@ class StormClient {
|
|
170
181
|
}
|
171
182
|
async createSimpleBackend(handle, systemId, input) {
|
172
183
|
const u = `${this._baseUrl}/v2/create-simple-backend/${handle}/${systemId}`;
|
184
|
+
const headers = {};
|
185
|
+
headers[exports.HandleHeader] = this._handle;
|
186
|
+
headers[exports.ConversationIdHeader] = this._systemId;
|
187
|
+
headers[exports.SystemIdHeader] = this._systemId;
|
173
188
|
const response = await fetch(u, {
|
174
189
|
method: 'POST',
|
175
190
|
body: JSON.stringify({
|
176
191
|
pages: input.pages,
|
177
192
|
}),
|
193
|
+
headers: headers,
|
178
194
|
});
|
179
195
|
if (!response.ok) {
|
180
196
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
package/package.json
CHANGED
package/src/storm/routes.ts
CHANGED
@@ -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(
|
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(
|
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) {
|
package/src/storm/stormClient.ts
CHANGED
@@ -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,28 @@ 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
|
-
|
256
|
-
|
257
|
-
|
258
|
-
headers
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
255
|
+
try {
|
256
|
+
const headers: { [key: string]: any } = {};
|
257
|
+
headers[HandleHeader] = this._handle;
|
258
|
+
headers[ConversationIdHeader] = this._systemId;
|
259
|
+
headers[SystemIdHeader] = this._systemId;
|
260
|
+
|
261
|
+
const response = await fetch(u, {
|
262
|
+
method: 'POST',
|
263
|
+
body: JSON.stringify(prompt.pages),
|
264
|
+
headers: headers,
|
265
|
+
});
|
266
|
+
|
267
|
+
if (!response.ok) {
|
268
|
+
console.error('Failed to implement api clients', response.status, await response.text());
|
269
|
+
return [];
|
270
|
+
}
|
271
|
+
|
272
|
+
return (await response.json()) as HTMLPage[];
|
273
|
+
} catch (error) {
|
274
|
+
console.error('Failed to implement api clients', error);
|
275
|
+
return [];
|
276
|
+
}
|
264
277
|
}
|
265
278
|
|
266
279
|
public async generatePrompt(pages: string[]): Promise<string> {
|
@@ -276,11 +289,18 @@ export class StormClient {
|
|
276
289
|
|
277
290
|
public async createSimpleBackend(handle: string, systemId: string, input: CreateSimpleBackendRequest) {
|
278
291
|
const u = `${this._baseUrl}/v2/create-simple-backend/${handle}/${systemId}`;
|
292
|
+
|
293
|
+
const headers: { [key: string]: any } = {};
|
294
|
+
headers[HandleHeader] = this._handle;
|
295
|
+
headers[ConversationIdHeader] = this._systemId;
|
296
|
+
headers[SystemIdHeader] = this._systemId;
|
297
|
+
|
279
298
|
const response = await fetch(u, {
|
280
299
|
method: 'POST',
|
281
300
|
body: JSON.stringify({
|
282
301
|
pages: input.pages,
|
283
302
|
}),
|
303
|
+
headers: headers,
|
284
304
|
});
|
285
305
|
if (!response.ok) {
|
286
306
|
throw new Error(`HTTP error! Status: ${response.status}`);
|