@kapeta/local-cluster-service 0.47.2 → 0.47.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 +7 -0
- package/dist/cjs/src/storm/routes.js +11 -5
- package/dist/cjs/src/storm/stormClient.d.ts +5 -4
- package/dist/cjs/src/storm/stormClient.js +14 -10
- package/dist/cjs/src/storm/stream.d.ts +3 -3
- package/dist/cjs/src/storm/stream.js +6 -11
- package/dist/esm/src/storm/routes.js +11 -5
- package/dist/esm/src/storm/stormClient.d.ts +5 -4
- package/dist/esm/src/storm/stormClient.js +14 -10
- package/dist/esm/src/storm/stream.d.ts +3 -3
- package/dist/esm/src/storm/stream.js +6 -11
- package/package.json +1 -1
- package/src/storm/codegen.ts +1 -4
- package/src/storm/routes.ts +13 -6
- package/src/storm/stormClient.ts +16 -10
- package/src/storm/stream.ts +7 -12
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.47.3](https://github.com/kapetacom/local-cluster-service/compare/v0.47.2...v0.47.3) (2024-05-31)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Correctly handle conversation id ([#152](https://github.com/kapetacom/local-cluster-service/issues/152)) ([54a4722](https://github.com/kapetacom/local-cluster-service/commit/54a4722af823699afc37059561fb9e862ea6fa84))
|
7
|
+
|
1
8
|
## [0.47.2](https://github.com/kapetacom/local-cluster-service/compare/v0.47.1...v0.47.2) (2024-05-30)
|
2
9
|
|
3
10
|
|
@@ -21,9 +21,13 @@ router.post('/:handle/all', async (req, res) => {
|
|
21
21
|
try {
|
22
22
|
const stormOptions = await (0, event_parser_1.resolveOptions)();
|
23
23
|
const eventParser = new event_parser_1.StormEventParser(stormOptions);
|
24
|
+
const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
|
24
25
|
const aiRequest = JSON.parse(req.stringBody ?? '{}');
|
25
|
-
const metaStream = await stormClient_1.stormClient.createMetadata(aiRequest.prompt,
|
26
|
+
const metaStream = await stormClient_1.stormClient.createMetadata(aiRequest.prompt, conversationId);
|
26
27
|
res.set('Content-Type', 'application/x-ndjson');
|
28
|
+
res.set('Access-Control-Expose-Headers', stormClient_1.ConversationIdHeader);
|
29
|
+
res.set(stormClient_1.ConversationIdHeader, metaStream.getConversationId());
|
30
|
+
console.log('metaStream.getConversationId()', metaStream.getConversationId());
|
27
31
|
metaStream.on('data', (data) => {
|
28
32
|
const result = eventParser.addEvent(req.params.handle, data);
|
29
33
|
sendDefinitions(res, result);
|
@@ -42,10 +46,12 @@ router.post('/:handle/all', async (req, res) => {
|
|
42
46
|
}
|
43
47
|
const result = eventParser.toResult(handle);
|
44
48
|
sendDefinitions(res, result);
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
if (!req.query.skipCodegen) {
|
50
|
+
const stormCodegen = new codegen_1.StormCodegen(aiRequest.prompt, result.blocks, eventParser.getEvents());
|
51
|
+
const codegenPromise = streamStormPartialResponse(stormCodegen.getStream(), res);
|
52
|
+
await stormCodegen.process();
|
53
|
+
await codegenPromise;
|
54
|
+
}
|
49
55
|
sendDone(res);
|
50
56
|
}
|
51
57
|
catch (err) {
|
@@ -1,13 +1,14 @@
|
|
1
|
-
import {
|
1
|
+
import { StormFileImplementationPrompt, StormStream, StormUIImplementationPrompt } from './stream';
|
2
2
|
export declare const STORM_ID = "storm";
|
3
|
+
export declare const ConversationIdHeader = "Conversation-Id";
|
3
4
|
declare class StormClient {
|
4
5
|
private readonly _baseUrl;
|
5
6
|
constructor();
|
6
7
|
private createOptions;
|
7
8
|
private send;
|
8
|
-
createMetadata(prompt: string,
|
9
|
-
createUIImplementation(prompt: StormUIImplementationPrompt,
|
10
|
-
createServiceImplementation(prompt: StormFileImplementationPrompt,
|
9
|
+
createMetadata(prompt: string, conversationId?: string): Promise<StormStream>;
|
10
|
+
createUIImplementation(prompt: StormUIImplementationPrompt, conversationId?: string): Promise<StormStream>;
|
11
|
+
createServiceImplementation(prompt: StormFileImplementationPrompt, conversationId?: string): Promise<StormStream>;
|
11
12
|
}
|
12
13
|
export declare const stormClient: StormClient;
|
13
14
|
export {};
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.stormClient = exports.STORM_ID = void 0;
|
6
|
+
exports.stormClient = exports.ConversationIdHeader = exports.STORM_ID = void 0;
|
7
7
|
/**
|
8
8
|
* Copyright 2023 Kapeta Inc.
|
9
9
|
* SPDX-License-Identifier: BUSL-1.1
|
@@ -14,6 +14,7 @@ const promises_1 = __importDefault(require("node:readline/promises"));
|
|
14
14
|
const node_stream_1 = require("node:stream");
|
15
15
|
const stream_1 = require("./stream");
|
16
16
|
exports.STORM_ID = 'storm';
|
17
|
+
exports.ConversationIdHeader = 'Conversation-Id';
|
17
18
|
class StormClient {
|
18
19
|
_baseUrl;
|
19
20
|
constructor() {
|
@@ -29,7 +30,8 @@ class StormClient {
|
|
29
30
|
//headers['Authorization'] = `Bearer ${api.getAccessToken()}`; //TODO: Enable authentication
|
30
31
|
}
|
31
32
|
if (body.conversationId) {
|
32
|
-
headers[
|
33
|
+
headers[exports.ConversationIdHeader] = body.conversationId;
|
34
|
+
console.log('Setting ConversationIdHeader', headers[exports.ConversationIdHeader]);
|
33
35
|
}
|
34
36
|
return {
|
35
37
|
url,
|
@@ -42,13 +44,15 @@ class StormClient {
|
|
42
44
|
const stringPrompt = typeof body.prompt === 'string' ? body.prompt : JSON.stringify(body.prompt);
|
43
45
|
const options = this.createOptions(path, method, {
|
44
46
|
prompt: stringPrompt,
|
45
|
-
|
47
|
+
conversationId: body.conversationId,
|
46
48
|
});
|
47
|
-
const out = new stream_1.StormStream(stringPrompt, body.history);
|
48
49
|
const response = await fetch(options.url, options);
|
49
50
|
if (response.status !== 200) {
|
50
51
|
throw new Error(`Got error response from ${options.url}: ${response.status}\nContent: ${await response.text()}`);
|
51
52
|
}
|
53
|
+
const conversationId = response.headers.get(exports.ConversationIdHeader);
|
54
|
+
console.log('Received conversationId', conversationId);
|
55
|
+
const out = new stream_1.StormStream(stringPrompt, conversationId);
|
52
56
|
const jsonLStream = promises_1.default.createInterface(node_stream_1.Readable.fromWeb(response.body));
|
53
57
|
jsonLStream.on('line', (line) => {
|
54
58
|
out.addJSONLine(line);
|
@@ -61,22 +65,22 @@ class StormClient {
|
|
61
65
|
});
|
62
66
|
return out;
|
63
67
|
}
|
64
|
-
createMetadata(prompt,
|
68
|
+
createMetadata(prompt, conversationId) {
|
65
69
|
return this.send('/v2/all', {
|
66
|
-
history: history ?? [],
|
67
70
|
prompt: prompt,
|
71
|
+
conversationId,
|
68
72
|
});
|
69
73
|
}
|
70
|
-
createUIImplementation(prompt,
|
74
|
+
createUIImplementation(prompt, conversationId) {
|
71
75
|
return this.send('/v2/ui/merge', {
|
72
|
-
history: history ?? [],
|
73
76
|
prompt,
|
77
|
+
conversationId,
|
74
78
|
});
|
75
79
|
}
|
76
|
-
createServiceImplementation(prompt,
|
80
|
+
createServiceImplementation(prompt, conversationId) {
|
77
81
|
return this.send('/v2/services/merge', {
|
78
|
-
history: history ?? [],
|
79
82
|
prompt,
|
83
|
+
conversationId,
|
80
84
|
});
|
81
85
|
}
|
82
86
|
}
|
@@ -7,9 +7,10 @@ import { EventEmitter } from 'node:events';
|
|
7
7
|
import { StormEvent } from './events';
|
8
8
|
import { AIFileTypes, GeneratedFile } from '@kapeta/codegen';
|
9
9
|
export declare class StormStream extends EventEmitter {
|
10
|
-
private
|
10
|
+
private conversationId;
|
11
11
|
private lines;
|
12
|
-
constructor(prompt?: string,
|
12
|
+
constructor(prompt?: string, conversationId?: string | null);
|
13
|
+
getConversationId(): string;
|
13
14
|
addJSONLine(line: string): void;
|
14
15
|
end(): void;
|
15
16
|
on(event: 'end', listener: () => void): this;
|
@@ -25,7 +26,6 @@ export interface ConversationItem {
|
|
25
26
|
content: string;
|
26
27
|
}
|
27
28
|
export interface StormContextRequest<T = string> {
|
28
|
-
history?: ConversationItem[];
|
29
29
|
conversationId?: string;
|
30
30
|
prompt: T;
|
31
31
|
}
|
@@ -7,15 +7,14 @@ exports.StormStream = void 0;
|
|
7
7
|
*/
|
8
8
|
const node_events_1 = require("node:events");
|
9
9
|
class StormStream extends node_events_1.EventEmitter {
|
10
|
-
|
10
|
+
conversationId = '';
|
11
11
|
lines = [];
|
12
|
-
constructor(prompt = '',
|
12
|
+
constructor(prompt = '', conversationId) {
|
13
13
|
super();
|
14
|
-
this.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
});
|
14
|
+
this.conversationId = conversationId || '';
|
15
|
+
}
|
16
|
+
getConversationId() {
|
17
|
+
return this.conversationId;
|
19
18
|
}
|
20
19
|
addJSONLine(line) {
|
21
20
|
try {
|
@@ -31,10 +30,6 @@ class StormStream extends node_events_1.EventEmitter {
|
|
31
30
|
}
|
32
31
|
}
|
33
32
|
end() {
|
34
|
-
this.history.push({
|
35
|
-
role: 'model',
|
36
|
-
content: this.lines.join('\n'),
|
37
|
-
});
|
38
33
|
this.emit('end');
|
39
34
|
}
|
40
35
|
on(event, listener) {
|
@@ -21,9 +21,13 @@ router.post('/:handle/all', async (req, res) => {
|
|
21
21
|
try {
|
22
22
|
const stormOptions = await (0, event_parser_1.resolveOptions)();
|
23
23
|
const eventParser = new event_parser_1.StormEventParser(stormOptions);
|
24
|
+
const conversationId = req.headers[stormClient_1.ConversationIdHeader.toLowerCase()];
|
24
25
|
const aiRequest = JSON.parse(req.stringBody ?? '{}');
|
25
|
-
const metaStream = await stormClient_1.stormClient.createMetadata(aiRequest.prompt,
|
26
|
+
const metaStream = await stormClient_1.stormClient.createMetadata(aiRequest.prompt, conversationId);
|
26
27
|
res.set('Content-Type', 'application/x-ndjson');
|
28
|
+
res.set('Access-Control-Expose-Headers', stormClient_1.ConversationIdHeader);
|
29
|
+
res.set(stormClient_1.ConversationIdHeader, metaStream.getConversationId());
|
30
|
+
console.log('metaStream.getConversationId()', metaStream.getConversationId());
|
27
31
|
metaStream.on('data', (data) => {
|
28
32
|
const result = eventParser.addEvent(req.params.handle, data);
|
29
33
|
sendDefinitions(res, result);
|
@@ -42,10 +46,12 @@ router.post('/:handle/all', async (req, res) => {
|
|
42
46
|
}
|
43
47
|
const result = eventParser.toResult(handle);
|
44
48
|
sendDefinitions(res, result);
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
if (!req.query.skipCodegen) {
|
50
|
+
const stormCodegen = new codegen_1.StormCodegen(aiRequest.prompt, result.blocks, eventParser.getEvents());
|
51
|
+
const codegenPromise = streamStormPartialResponse(stormCodegen.getStream(), res);
|
52
|
+
await stormCodegen.process();
|
53
|
+
await codegenPromise;
|
54
|
+
}
|
49
55
|
sendDone(res);
|
50
56
|
}
|
51
57
|
catch (err) {
|
@@ -1,13 +1,14 @@
|
|
1
|
-
import {
|
1
|
+
import { StormFileImplementationPrompt, StormStream, StormUIImplementationPrompt } from './stream';
|
2
2
|
export declare const STORM_ID = "storm";
|
3
|
+
export declare const ConversationIdHeader = "Conversation-Id";
|
3
4
|
declare class StormClient {
|
4
5
|
private readonly _baseUrl;
|
5
6
|
constructor();
|
6
7
|
private createOptions;
|
7
8
|
private send;
|
8
|
-
createMetadata(prompt: string,
|
9
|
-
createUIImplementation(prompt: StormUIImplementationPrompt,
|
10
|
-
createServiceImplementation(prompt: StormFileImplementationPrompt,
|
9
|
+
createMetadata(prompt: string, conversationId?: string): Promise<StormStream>;
|
10
|
+
createUIImplementation(prompt: StormUIImplementationPrompt, conversationId?: string): Promise<StormStream>;
|
11
|
+
createServiceImplementation(prompt: StormFileImplementationPrompt, conversationId?: string): Promise<StormStream>;
|
11
12
|
}
|
12
13
|
export declare const stormClient: StormClient;
|
13
14
|
export {};
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.stormClient = exports.STORM_ID = void 0;
|
6
|
+
exports.stormClient = exports.ConversationIdHeader = exports.STORM_ID = void 0;
|
7
7
|
/**
|
8
8
|
* Copyright 2023 Kapeta Inc.
|
9
9
|
* SPDX-License-Identifier: BUSL-1.1
|
@@ -14,6 +14,7 @@ const promises_1 = __importDefault(require("node:readline/promises"));
|
|
14
14
|
const node_stream_1 = require("node:stream");
|
15
15
|
const stream_1 = require("./stream");
|
16
16
|
exports.STORM_ID = 'storm';
|
17
|
+
exports.ConversationIdHeader = 'Conversation-Id';
|
17
18
|
class StormClient {
|
18
19
|
_baseUrl;
|
19
20
|
constructor() {
|
@@ -29,7 +30,8 @@ class StormClient {
|
|
29
30
|
//headers['Authorization'] = `Bearer ${api.getAccessToken()}`; //TODO: Enable authentication
|
30
31
|
}
|
31
32
|
if (body.conversationId) {
|
32
|
-
headers[
|
33
|
+
headers[exports.ConversationIdHeader] = body.conversationId;
|
34
|
+
console.log('Setting ConversationIdHeader', headers[exports.ConversationIdHeader]);
|
33
35
|
}
|
34
36
|
return {
|
35
37
|
url,
|
@@ -42,13 +44,15 @@ class StormClient {
|
|
42
44
|
const stringPrompt = typeof body.prompt === 'string' ? body.prompt : JSON.stringify(body.prompt);
|
43
45
|
const options = this.createOptions(path, method, {
|
44
46
|
prompt: stringPrompt,
|
45
|
-
|
47
|
+
conversationId: body.conversationId,
|
46
48
|
});
|
47
|
-
const out = new stream_1.StormStream(stringPrompt, body.history);
|
48
49
|
const response = await fetch(options.url, options);
|
49
50
|
if (response.status !== 200) {
|
50
51
|
throw new Error(`Got error response from ${options.url}: ${response.status}\nContent: ${await response.text()}`);
|
51
52
|
}
|
53
|
+
const conversationId = response.headers.get(exports.ConversationIdHeader);
|
54
|
+
console.log('Received conversationId', conversationId);
|
55
|
+
const out = new stream_1.StormStream(stringPrompt, conversationId);
|
52
56
|
const jsonLStream = promises_1.default.createInterface(node_stream_1.Readable.fromWeb(response.body));
|
53
57
|
jsonLStream.on('line', (line) => {
|
54
58
|
out.addJSONLine(line);
|
@@ -61,22 +65,22 @@ class StormClient {
|
|
61
65
|
});
|
62
66
|
return out;
|
63
67
|
}
|
64
|
-
createMetadata(prompt,
|
68
|
+
createMetadata(prompt, conversationId) {
|
65
69
|
return this.send('/v2/all', {
|
66
|
-
history: history ?? [],
|
67
70
|
prompt: prompt,
|
71
|
+
conversationId,
|
68
72
|
});
|
69
73
|
}
|
70
|
-
createUIImplementation(prompt,
|
74
|
+
createUIImplementation(prompt, conversationId) {
|
71
75
|
return this.send('/v2/ui/merge', {
|
72
|
-
history: history ?? [],
|
73
76
|
prompt,
|
77
|
+
conversationId,
|
74
78
|
});
|
75
79
|
}
|
76
|
-
createServiceImplementation(prompt,
|
80
|
+
createServiceImplementation(prompt, conversationId) {
|
77
81
|
return this.send('/v2/services/merge', {
|
78
|
-
history: history ?? [],
|
79
82
|
prompt,
|
83
|
+
conversationId,
|
80
84
|
});
|
81
85
|
}
|
82
86
|
}
|
@@ -7,9 +7,10 @@ import { EventEmitter } from 'node:events';
|
|
7
7
|
import { StormEvent } from './events';
|
8
8
|
import { AIFileTypes, GeneratedFile } from '@kapeta/codegen';
|
9
9
|
export declare class StormStream extends EventEmitter {
|
10
|
-
private
|
10
|
+
private conversationId;
|
11
11
|
private lines;
|
12
|
-
constructor(prompt?: string,
|
12
|
+
constructor(prompt?: string, conversationId?: string | null);
|
13
|
+
getConversationId(): string;
|
13
14
|
addJSONLine(line: string): void;
|
14
15
|
end(): void;
|
15
16
|
on(event: 'end', listener: () => void): this;
|
@@ -25,7 +26,6 @@ export interface ConversationItem {
|
|
25
26
|
content: string;
|
26
27
|
}
|
27
28
|
export interface StormContextRequest<T = string> {
|
28
|
-
history?: ConversationItem[];
|
29
29
|
conversationId?: string;
|
30
30
|
prompt: T;
|
31
31
|
}
|
@@ -7,15 +7,14 @@ exports.StormStream = void 0;
|
|
7
7
|
*/
|
8
8
|
const node_events_1 = require("node:events");
|
9
9
|
class StormStream extends node_events_1.EventEmitter {
|
10
|
-
|
10
|
+
conversationId = '';
|
11
11
|
lines = [];
|
12
|
-
constructor(prompt = '',
|
12
|
+
constructor(prompt = '', conversationId) {
|
13
13
|
super();
|
14
|
-
this.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
});
|
14
|
+
this.conversationId = conversationId || '';
|
15
|
+
}
|
16
|
+
getConversationId() {
|
17
|
+
return this.conversationId;
|
19
18
|
}
|
20
19
|
addJSONLine(line) {
|
21
20
|
try {
|
@@ -31,10 +30,6 @@ class StormStream extends node_events_1.EventEmitter {
|
|
31
30
|
}
|
32
31
|
}
|
33
32
|
end() {
|
34
|
-
this.history.push({
|
35
|
-
role: 'model',
|
36
|
-
content: this.lines.join('\n'),
|
37
|
-
});
|
38
33
|
this.emit('end');
|
39
34
|
}
|
40
35
|
on(event, listener) {
|
package/package.json
CHANGED
package/src/storm/codegen.ts
CHANGED
@@ -13,10 +13,7 @@ import { BlockDefinitionInfo } from './event-parser';
|
|
13
13
|
import { ConversationItem, StormFileImplementationPrompt, StormFileInfo, StormStream } from './stream';
|
14
14
|
import { KapetaURI } from '@kapeta/nodejs-utils';
|
15
15
|
|
16
|
-
type ImplementationGenerator = (
|
17
|
-
prompt: StormFileImplementationPrompt,
|
18
|
-
history?: ConversationItem[]
|
19
|
-
) => Promise<StormStream>;
|
16
|
+
type ImplementationGenerator = (prompt: StormFileImplementationPrompt, conversationId?: string) => Promise<StormStream>;
|
20
17
|
|
21
18
|
export class StormCodegen {
|
22
19
|
private readonly userPrompt: string;
|
package/src/storm/routes.ts
CHANGED
@@ -9,7 +9,7 @@ import { corsHandler } from '../middleware/cors';
|
|
9
9
|
import { stringBody } from '../middleware/stringBody';
|
10
10
|
import { KapetaBodyRequest } from '../types';
|
11
11
|
import { StormContextRequest, StormFileImplementationPrompt, StormFileInfo, StormStream } from './stream';
|
12
|
-
import { stormClient } from './stormClient';
|
12
|
+
import { ConversationIdHeader, stormClient } from './stormClient';
|
13
13
|
import { StormEvent } from './events';
|
14
14
|
import { resolveOptions, StormDefinitions, StormEventParser } from './event-parser';
|
15
15
|
import { StormCodegen } from './codegen';
|
@@ -27,10 +27,15 @@ router.post('/:handle/all', async (req: KapetaBodyRequest, res: Response) => {
|
|
27
27
|
|
28
28
|
const eventParser = new StormEventParser(stormOptions);
|
29
29
|
|
30
|
+
const conversationId = req.headers[ConversationIdHeader.toLowerCase()] as string | undefined;
|
31
|
+
|
30
32
|
const aiRequest: StormContextRequest = JSON.parse(req.stringBody ?? '{}');
|
31
|
-
const metaStream = await stormClient.createMetadata(aiRequest.prompt,
|
33
|
+
const metaStream = await stormClient.createMetadata(aiRequest.prompt, conversationId);
|
32
34
|
|
33
35
|
res.set('Content-Type', 'application/x-ndjson');
|
36
|
+
res.set('Access-Control-Expose-Headers', ConversationIdHeader);
|
37
|
+
res.set(ConversationIdHeader, metaStream.getConversationId());
|
38
|
+
console.log('metaStream.getConversationId()', metaStream.getConversationId());
|
34
39
|
|
35
40
|
metaStream.on('data', (data: StormEvent) => {
|
36
41
|
const result = eventParser.addEvent(req.params.handle, data);
|
@@ -56,13 +61,15 @@ router.post('/:handle/all', async (req: KapetaBodyRequest, res: Response) => {
|
|
56
61
|
|
57
62
|
sendDefinitions(res, result);
|
58
63
|
|
59
|
-
|
64
|
+
if (!req.query.skipCodegen) {
|
65
|
+
const stormCodegen = new StormCodegen(aiRequest.prompt, result.blocks, eventParser.getEvents());
|
60
66
|
|
61
|
-
|
67
|
+
const codegenPromise = streamStormPartialResponse(stormCodegen.getStream(), res);
|
62
68
|
|
63
|
-
|
69
|
+
await stormCodegen.process();
|
64
70
|
|
65
|
-
|
71
|
+
await codegenPromise;
|
72
|
+
}
|
66
73
|
|
67
74
|
sendDone(res);
|
68
75
|
} catch (err: any) {
|
package/src/storm/stormClient.ts
CHANGED
@@ -17,6 +17,8 @@ import {
|
|
17
17
|
|
18
18
|
export const STORM_ID = 'storm';
|
19
19
|
|
20
|
+
export const ConversationIdHeader = 'Conversation-Id';
|
21
|
+
|
20
22
|
class StormClient {
|
21
23
|
private readonly _baseUrl: string;
|
22
24
|
|
@@ -35,7 +37,8 @@ class StormClient {
|
|
35
37
|
}
|
36
38
|
|
37
39
|
if (body.conversationId) {
|
38
|
-
headers[
|
40
|
+
headers[ConversationIdHeader] = body.conversationId;
|
41
|
+
console.log('Setting ConversationIdHeader', headers[ConversationIdHeader]);
|
39
42
|
}
|
40
43
|
|
41
44
|
return {
|
@@ -55,11 +58,9 @@ class StormClient {
|
|
55
58
|
|
56
59
|
const options = this.createOptions(path, method, {
|
57
60
|
prompt: stringPrompt,
|
58
|
-
|
61
|
+
conversationId: body.conversationId,
|
59
62
|
});
|
60
63
|
|
61
|
-
const out = new StormStream(stringPrompt, body.history);
|
62
|
-
|
63
64
|
const response = await fetch(options.url, options);
|
64
65
|
|
65
66
|
if (response.status !== 200) {
|
@@ -68,6 +69,11 @@ class StormClient {
|
|
68
69
|
);
|
69
70
|
}
|
70
71
|
|
72
|
+
const conversationId = response.headers.get(ConversationIdHeader);
|
73
|
+
console.log('Received conversationId', conversationId);
|
74
|
+
|
75
|
+
const out = new StormStream(stringPrompt, conversationId);
|
76
|
+
|
71
77
|
const jsonLStream = readLine.createInterface(Readable.fromWeb(response.body!));
|
72
78
|
|
73
79
|
jsonLStream.on('line', (line) => {
|
@@ -85,24 +91,24 @@ class StormClient {
|
|
85
91
|
return out;
|
86
92
|
}
|
87
93
|
|
88
|
-
public createMetadata(prompt: string,
|
94
|
+
public createMetadata(prompt: string, conversationId?: string) {
|
89
95
|
return this.send('/v2/all', {
|
90
|
-
history: history ?? [],
|
91
96
|
prompt: prompt,
|
97
|
+
conversationId,
|
92
98
|
});
|
93
99
|
}
|
94
100
|
|
95
|
-
public createUIImplementation(prompt: StormUIImplementationPrompt,
|
101
|
+
public createUIImplementation(prompt: StormUIImplementationPrompt, conversationId?: string) {
|
96
102
|
return this.send<StormUIImplementationPrompt>('/v2/ui/merge', {
|
97
|
-
history: history ?? [],
|
98
103
|
prompt,
|
104
|
+
conversationId,
|
99
105
|
});
|
100
106
|
}
|
101
107
|
|
102
|
-
public createServiceImplementation(prompt: StormFileImplementationPrompt,
|
108
|
+
public createServiceImplementation(prompt: StormFileImplementationPrompt, conversationId?: string) {
|
103
109
|
return this.send<StormFileImplementationPrompt>('/v2/services/merge', {
|
104
|
-
history: history ?? [],
|
105
110
|
prompt,
|
111
|
+
conversationId,
|
106
112
|
});
|
107
113
|
}
|
108
114
|
}
|
package/src/storm/stream.ts
CHANGED
@@ -7,16 +7,16 @@ import { StormEvent } from './events';
|
|
7
7
|
import { AIFileTypes, GeneratedFile } from '@kapeta/codegen';
|
8
8
|
|
9
9
|
export class StormStream extends EventEmitter {
|
10
|
-
private
|
10
|
+
private conversationId: string = '';
|
11
11
|
private lines: string[] = [];
|
12
12
|
|
13
|
-
constructor(prompt: string = '',
|
13
|
+
constructor(prompt: string = '', conversationId?: string | null) {
|
14
14
|
super();
|
15
|
-
this.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
this.conversationId = conversationId || '';
|
16
|
+
}
|
17
|
+
|
18
|
+
getConversationId() {
|
19
|
+
return this.conversationId;
|
20
20
|
}
|
21
21
|
|
22
22
|
addJSONLine(line: string) {
|
@@ -33,10 +33,6 @@ export class StormStream extends EventEmitter {
|
|
33
33
|
}
|
34
34
|
|
35
35
|
end() {
|
36
|
-
this.history.push({
|
37
|
-
role: 'model',
|
38
|
-
content: this.lines.join('\n'),
|
39
|
-
});
|
40
36
|
this.emit('end');
|
41
37
|
}
|
42
38
|
|
@@ -73,7 +69,6 @@ export interface ConversationItem {
|
|
73
69
|
}
|
74
70
|
|
75
71
|
export interface StormContextRequest<T = string> {
|
76
|
-
history?: ConversationItem[];
|
77
72
|
conversationId?: string;
|
78
73
|
prompt: T;
|
79
74
|
}
|