@kapeta/local-cluster-service 0.48.4 → 0.49.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/.vscode/launch.json +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/cjs/src/assetManager.d.ts +1 -1
- package/dist/cjs/src/assetManager.js +5 -3
- package/dist/cjs/src/filesystem/routes.js +10 -0
- package/dist/cjs/src/storm/codegen.d.ts +9 -1
- package/dist/cjs/src/storm/codegen.js +111 -8
- package/dist/cjs/src/storm/event-parser.d.ts +1 -1
- package/dist/cjs/src/storm/event-parser.js +3 -1
- package/dist/cjs/src/storm/events.d.ts +32 -1
- package/dist/cjs/src/storm/routes.js +26 -1
- package/dist/cjs/src/storm/stormClient.d.ts +3 -1
- package/dist/cjs/src/storm/stormClient.js +12 -0
- package/dist/cjs/src/storm/stream.d.ts +6 -0
- package/dist/esm/src/assetManager.d.ts +1 -1
- package/dist/esm/src/assetManager.js +5 -3
- package/dist/esm/src/filesystem/routes.js +10 -0
- package/dist/esm/src/storm/codegen.d.ts +9 -1
- package/dist/esm/src/storm/codegen.js +111 -8
- package/dist/esm/src/storm/event-parser.d.ts +1 -1
- package/dist/esm/src/storm/event-parser.js +3 -1
- package/dist/esm/src/storm/events.d.ts +32 -1
- package/dist/esm/src/storm/routes.js +26 -1
- package/dist/esm/src/storm/stormClient.d.ts +3 -1
- package/dist/esm/src/storm/stormClient.js +12 -0
- package/dist/esm/src/storm/stream.d.ts +6 -0
- package/package.json +1 -1
- package/src/assetManager.ts +6 -4
- package/src/filesystem/routes.ts +10 -0
- package/src/storm/codegen.ts +132 -12
- package/src/storm/event-parser.ts +4 -2
- package/src/storm/events.ts +38 -1
- package/src/storm/routes.ts +39 -2
- package/src/storm/stormClient.ts +13 -1
- package/src/storm/stream.ts +7 -0
package/src/storm/events.ts
CHANGED
@@ -127,6 +127,28 @@ export interface StormEventError {
|
|
127
127
|
};
|
128
128
|
}
|
129
129
|
|
130
|
+
export interface StormEventErrorClassifier {
|
131
|
+
type: 'ERROR_CLASSIFIER';
|
132
|
+
reason: string;
|
133
|
+
created: number;
|
134
|
+
payload: StormEventErrorClassifierInfo;
|
135
|
+
}
|
136
|
+
|
137
|
+
export interface StormEventCodeFix {
|
138
|
+
type: 'CODE_FIX';
|
139
|
+
reason: string;
|
140
|
+
created: number;
|
141
|
+
payload: {
|
142
|
+
filename: string;
|
143
|
+
content: string;
|
144
|
+
};
|
145
|
+
}
|
146
|
+
export interface StormEventErrorClassifierInfo {
|
147
|
+
error: string;
|
148
|
+
filename: string;
|
149
|
+
potentialFix: string;
|
150
|
+
}
|
151
|
+
|
130
152
|
export interface ScreenTemplate {
|
131
153
|
name: string;
|
132
154
|
template: string;
|
@@ -174,6 +196,18 @@ export interface StormEventFile {
|
|
174
196
|
};
|
175
197
|
}
|
176
198
|
|
199
|
+
export interface StormEventBlockReady {
|
200
|
+
type: 'BLOCK_READY';
|
201
|
+
reason: string;
|
202
|
+
created: number;
|
203
|
+
payload: {
|
204
|
+
path: string;
|
205
|
+
blockName: string;
|
206
|
+
blockRef: string;
|
207
|
+
instanceId: string;
|
208
|
+
};
|
209
|
+
}
|
210
|
+
|
177
211
|
export interface StormEventDone {
|
178
212
|
type: 'DONE';
|
179
213
|
created: number;
|
@@ -199,4 +233,7 @@ export type StormEvent =
|
|
199
233
|
| StormEventScreenCandidate
|
200
234
|
| StormEventFile
|
201
235
|
| StormEventDone
|
202
|
-
| StormEventDefinitionChange
|
236
|
+
| StormEventDefinitionChange
|
237
|
+
| StormEventErrorClassifier
|
238
|
+
| StormEventCodeFix
|
239
|
+
| StormEventBlockReady;
|
package/src/storm/routes.ts
CHANGED
@@ -4,15 +4,19 @@
|
|
4
4
|
*/
|
5
5
|
|
6
6
|
import Router from 'express-promise-router';
|
7
|
+
import FS from 'fs-extra';
|
7
8
|
import { Response } from 'express';
|
8
9
|
import { corsHandler } from '../middleware/cors';
|
9
10
|
import { stringBody } from '../middleware/stringBody';
|
10
11
|
import { KapetaBodyRequest } from '../types';
|
11
|
-
import { StormContextRequest,
|
12
|
+
import { StormContextRequest, StormCreateBlockRequest, StormStream } from './stream';
|
12
13
|
import { ConversationIdHeader, stormClient } from './stormClient';
|
13
14
|
import { StormEvent } from './events';
|
14
15
|
import { resolveOptions, StormDefinitions, StormEventParser } from './event-parser';
|
15
16
|
import { StormCodegen } from './codegen';
|
17
|
+
import { assetManager } from '../assetManager';
|
18
|
+
import Path from 'path';
|
19
|
+
import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
16
20
|
|
17
21
|
const router = Router();
|
18
22
|
|
@@ -62,7 +66,12 @@ router.post('/:handle/all', async (req: KapetaBodyRequest, res: Response) => {
|
|
62
66
|
sendDefinitions(res, result);
|
63
67
|
|
64
68
|
if (!req.query.skipCodegen) {
|
65
|
-
const stormCodegen = new StormCodegen(
|
69
|
+
const stormCodegen = new StormCodegen(
|
70
|
+
metaStream.getConversationId(),
|
71
|
+
aiRequest.prompt,
|
72
|
+
result.blocks,
|
73
|
+
eventParser.getEvents()
|
74
|
+
);
|
66
75
|
|
67
76
|
const codegenPromise = streamStormPartialResponse(stormCodegen.getStream(), res);
|
68
77
|
|
@@ -78,6 +87,34 @@ router.post('/:handle/all', async (req: KapetaBodyRequest, res: Response) => {
|
|
78
87
|
}
|
79
88
|
});
|
80
89
|
|
90
|
+
router.post('/block/create', async (req: KapetaBodyRequest, res: Response) => {
|
91
|
+
const createRequest: StormCreateBlockRequest = JSON.parse(req.stringBody ?? '{}');
|
92
|
+
|
93
|
+
try {
|
94
|
+
const ymlPath = Path.join(createRequest.newPath, 'kapeta.yml');
|
95
|
+
|
96
|
+
console.log('Creating block at', ymlPath);
|
97
|
+
|
98
|
+
const [asset] = await assetManager.createAsset(ymlPath, createRequest.definition);
|
99
|
+
|
100
|
+
if (await FS.pathExists(createRequest.tmpPath)) {
|
101
|
+
console.log('Moving block from', createRequest.tmpPath, 'to', createRequest.newPath);
|
102
|
+
|
103
|
+
await FS.move(createRequest.tmpPath, createRequest.newPath, {
|
104
|
+
overwrite: true,
|
105
|
+
});
|
106
|
+
|
107
|
+
console.log('Updating asset', asset.ref);
|
108
|
+
|
109
|
+
res.send(await assetManager.updateAsset(asset.ref, createRequest.definition));
|
110
|
+
} else {
|
111
|
+
res.send(asset);
|
112
|
+
}
|
113
|
+
} catch (err: any) {
|
114
|
+
res.status(500).send({ error: err.message });
|
115
|
+
}
|
116
|
+
});
|
117
|
+
|
81
118
|
function sendDefinitions(res: Response, result: StormDefinitions) {
|
82
119
|
sendEvent(res, {
|
83
120
|
type: 'DEFINITION_CHANGE',
|
package/src/storm/stormClient.ts
CHANGED
@@ -10,7 +10,6 @@ import {
|
|
10
10
|
ConversationItem,
|
11
11
|
StormContextRequest,
|
12
12
|
StormFileImplementationPrompt,
|
13
|
-
StormFileInfo,
|
14
13
|
StormStream,
|
15
14
|
StormUIImplementationPrompt,
|
16
15
|
} from './stream';
|
@@ -111,6 +110,19 @@ class StormClient {
|
|
111
110
|
conversationId,
|
112
111
|
});
|
113
112
|
}
|
113
|
+
|
114
|
+
public createErrorClassification(prompt: string, history?: ConversationItem[], conversationId?: string) {
|
115
|
+
return this.send('/v2/code/errorclassifier', {
|
116
|
+
conversationId: conversationId,
|
117
|
+
prompt,
|
118
|
+
});
|
119
|
+
}
|
120
|
+
public createCodeFix(prompt: string, history?: ConversationItem[], conversationId?: string) {
|
121
|
+
return this.send('/v2/code/fix', {
|
122
|
+
conversationId: conversationId,
|
123
|
+
prompt,
|
124
|
+
});
|
125
|
+
}
|
114
126
|
}
|
115
127
|
|
116
128
|
export const stormClient = new StormClient();
|
package/src/storm/stream.ts
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
import { EventEmitter } from 'node:events';
|
6
6
|
import { StormEvent } from './events';
|
7
7
|
import { AIFileTypes, GeneratedFile } from '@kapeta/codegen';
|
8
|
+
import { BlockDefinition } from '@kapeta/schemas';
|
8
9
|
|
9
10
|
export class StormStream extends EventEmitter {
|
10
11
|
private conversationId: string = '';
|
@@ -73,6 +74,12 @@ export interface StormContextRequest<T = string> {
|
|
73
74
|
prompt: T;
|
74
75
|
}
|
75
76
|
|
77
|
+
export interface StormCreateBlockRequest {
|
78
|
+
definition: BlockDefinition;
|
79
|
+
tmpPath: string;
|
80
|
+
newPath: string;
|
81
|
+
}
|
82
|
+
|
76
83
|
export interface StormFileInfo extends GeneratedFile {
|
77
84
|
type: AIFileTypes;
|
78
85
|
}
|