@@ -4,19 +4,19 @@ import dotenv from 'dotenv';
4
4
import { Hono , type Context } from 'hono' ;
5
5
import { env } from 'hono/adapter' ;
6
6
7
- import { stepStream , workflowStream } from './stream.js' ;
7
+ import { stepStreamResponse , worklflowStreamResponse } from './stream.js' ;
8
8
9
9
dotenv . config ( ) ;
10
10
11
11
const PORT = 8085 ;
12
12
13
13
const app = new Hono ( ) ;
14
14
15
- const createCortex = ( c : Context ) => {
15
+ const createCortex = ( ctx : Context ) => {
16
16
const { CORTEX_API_KEY , BASE_URL } = env < {
17
17
CORTEX_API_KEY : string ;
18
18
BASE_URL : string ;
19
- } > ( c ) ;
19
+ } > ( ctx ) ;
20
20
21
21
const cortex = new Cortex ( {
22
22
apiKey : CORTEX_API_KEY ,
@@ -30,17 +30,30 @@ app.get('/', c => {
30
30
return c . text ( 'Cortex SDK' ) ;
31
31
} ) ;
32
32
33
- app . get ( '/stream/step' , c => {
34
- const cortex = createCortex ( c ) ;
35
- stepStream ( cortex ) ;
36
- return c . text ( 'Stream Step' ) ;
33
+ app . get ( '/stream/step' , async ctx => {
34
+ const cortex = createCortex ( ctx ) ;
35
+
36
+ const response = await stepStreamResponse ( cortex ) ;
37
+
38
+ if ( response instanceof Response ) {
39
+ return response ;
40
+ }
41
+
42
+ return ctx . text ( response ) ;
37
43
} ) ;
38
44
39
- app . get ( '/stream/workflow' , c => {
40
- const { WORKFLOW_ID } = env < { WORKFLOW_ID : string } > ( c ) ;
41
- const cortex = createCortex ( c ) ;
42
- workflowStream ( cortex , WORKFLOW_ID ) ;
43
- return c . text ( 'Stream Workflow' ) ;
45
+ app . get ( '/stream/workflow' , async ctx => {
46
+ const { WORKFLOW_ID } = env < { WORKFLOW_ID : string } > ( ctx ) ;
47
+
48
+ const cortex = createCortex ( ctx ) ;
49
+
50
+ const response = await worklflowStreamResponse ( cortex , WORKFLOW_ID ) ;
51
+
52
+ if ( response instanceof Response ) {
53
+ return response ;
54
+ }
55
+
56
+ return ctx . text ( response ) ;
44
57
} ) ;
45
58
46
59
console . log ( `Server is running on http://localhost:${ PORT } ` ) ;
0 commit comments