1
+ import { JobManager } from "../config" ;
2
+ import Configuration from "../configuration" ;
3
+ import { JobInfo } from "../connection/manager" ;
4
+ import { buildSchemaDefinition , canTalkToDb , generateTableDefinition } from "./context" ;
5
+
6
+ interface Db2ContextItems {
7
+ name : string ;
8
+ description : string ;
9
+ content : string ;
10
+ type : "user" | "assistant" | "system" ;
11
+ specific ?: "copilot" | "continue" ;
12
+ }
13
+
14
+ export async function buildPrompt ( input : string , history ?: Db2ContextItems [ ] ) : Promise < Db2ContextItems [ ] > {
15
+ const currentJob : JobInfo = JobManager . getSelection ( ) ;
16
+ let contextItems : Db2ContextItems [ ] = [ ] ;
17
+
18
+ if ( currentJob ) {
19
+ const currentSchema = currentJob ?. job . options . libraries [ 0 ] || "QGPL" ;
20
+ const schema = this . getDefaultSchema ( ) ;
21
+
22
+ const useSchemaDef : boolean = Configuration . get < boolean > ( `ai.useSchemaDefinition` ) ;
23
+
24
+ if ( useSchemaDef ) {
25
+ const schemaSemantic = await buildSchemaDefinition ( schema ) ;
26
+ if ( schemaSemantic ) {
27
+ contextItems . push ( {
28
+ name : `SCHEMA Definition` ,
29
+ description : `${ schema } definition` ,
30
+ content : JSON . stringify ( schemaSemantic ) ,
31
+ type : "user"
32
+ } ) ;
33
+ }
34
+ }
35
+
36
+ // TODO: self?
37
+
38
+ const refs = await generateTableDefinition (
39
+ currentSchema ,
40
+ input . split ( ` ` )
41
+ ) ;
42
+
43
+ if ( history ) {
44
+ contextItems . push ( ...history ) ;
45
+ }
46
+
47
+ for ( const table of refs ) {
48
+ contextItems . push ( {
49
+ name : `table definition for ${ table . id } ` ,
50
+ content : table . content ,
51
+ description : `${ table . type } definition` ,
52
+ type : `assistant`
53
+ } ) ;
54
+ }
55
+ }
56
+
57
+ return contextItems ;
58
+ }
0 commit comments