@@ -42,40 +42,42 @@ export const initializePrompts = async ({
42
42
}
43
43
44
44
// Get all the prompts and parse out the arguments
45
- const prompts = promptsResponse . data . data . map ( async ( prompt ) => {
46
- const promptVersionResponse = await client . GET (
47
- "/v1/prompts/{prompt_identifier}/latest" ,
48
- {
49
- params : {
50
- path : {
51
- prompt_identifier : prompt . name ,
45
+ const prompts = await Promise . all (
46
+ promptsResponse . data . data . map ( async ( prompt ) => {
47
+ const promptVersionResponse = await client . GET (
48
+ "/v1/prompts/{prompt_identifier}/latest" ,
49
+ {
50
+ params : {
51
+ path : {
52
+ prompt_identifier : prompt . name ,
53
+ } ,
52
54
} ,
53
- } ,
54
- }
55
- ) ;
56
-
57
- const args : string [ ] = [ ] ;
58
- const template = promptVersionResponse . data ?. data . template ;
59
- const format = promptVersionResponse . data ?. data . template_format ;
60
- const parser =
61
- format === "F_STRING" ? parseArgumentsFString : parseVariablesMustache ;
62
- if ( template && template . type === "chat" ) {
63
- template . messages . forEach ( ( message ) => {
64
- const content = message . content ;
65
- if ( typeof content === "string" ) {
66
- args . push ( ...parser ( content ) ) ;
67
55
}
68
- } ) ;
69
- }
56
+ ) ;
70
57
71
- return {
72
- name : prompt . name ,
73
- description : prompt . description ,
74
- arguments : args ,
75
- } ;
76
- } ) ;
77
-
78
- return { prompts : prompts } ;
58
+ const args : string [ ] = [ ] ;
59
+ const template = promptVersionResponse . data ?. data . template ;
60
+ const format = promptVersionResponse . data ?. data . template_format ;
61
+ const parser =
62
+ format === "F_STRING"
63
+ ? parseArgumentsFString
64
+ : parseVariablesMustache ;
65
+ if ( template && template . type === "chat" ) {
66
+ template . messages . forEach ( ( message ) => {
67
+ const content = message . content ;
68
+ if ( typeof content === "string" ) {
69
+ args . push ( ...parser ( content ) ) ;
70
+ }
71
+ } ) ;
72
+ }
73
+ return {
74
+ name : prompt . name ,
75
+ description : prompt . description ,
76
+ arguments : args ,
77
+ } ;
78
+ } )
79
+ ) ;
80
+ return { prompts } ;
79
81
} ) ;
80
82
81
83
server . server . setRequestHandler ( GetPromptRequestSchema , async ( request ) => {
@@ -93,14 +95,42 @@ export const initializePrompts = async ({
93
95
) ;
94
96
95
97
const template = promptVersionResponse . data ?. data . template ;
96
- let messages : { role : string ; content : string } [ ] = [ ] ;
98
+ let messages : { role : string ; content : { type : string ; text : string } } [ ] =
99
+ [ ] ;
97
100
if ( template && template . type === "chat" ) {
98
- messages = template . messages . map ( ( message ) => {
99
- return {
100
- role : message . role as string ,
101
- content : message . content as string ,
102
- } ;
103
- } ) ;
101
+ messages = template . messages
102
+ . map ( ( message ) => {
103
+ if ( message . role === "system" ) {
104
+ return undefined ;
105
+ }
106
+ const messageContent = message . content ;
107
+ if ( typeof messageContent === "string" ) {
108
+ return {
109
+ role : message . role ,
110
+ content : {
111
+ type : "text" ,
112
+ text : messageContent ,
113
+ } ,
114
+ } ;
115
+ }
116
+ if ( Array . isArray ( messageContent ) ) {
117
+ if (
118
+ messageContent . length === 1 &&
119
+ messageContent [ 0 ] . type === "text"
120
+ ) {
121
+ const messageContentText = messageContent [ 0 ] . text ;
122
+ return {
123
+ role : message . role ,
124
+ content : {
125
+ type : "text" ,
126
+ text : messageContentText ,
127
+ } ,
128
+ } ;
129
+ }
130
+ }
131
+ return undefined ;
132
+ } )
133
+ . filter ( ( message ) => message !== undefined ) ;
104
134
}
105
135
return {
106
136
description : promptVersionResponse . data ?. data . description ,
0 commit comments