@@ -36,21 +36,8 @@ export async function getContextItems(input: string, options: PromptOptions = {}
36
36
37
37
if ( currentJob ) {
38
38
const currentSchema = currentJob ?. job . options . libraries [ 0 ] || "QGPL" ;
39
-
40
39
const useSchemaDef : boolean = Configuration . get < boolean > ( `ai.useSchemaDefinition` ) ;
41
40
42
- if ( useSchemaDef ) {
43
- progress ( `Building schema definition for ${ currentSchema } ...` ) ;
44
- const schemaSemantic = await buildSchemaDefinition ( currentSchema ) ;
45
- if ( schemaSemantic ) {
46
- contextItems . push ( {
47
- name : `SCHEMA Definition` ,
48
- description : `${ currentSchema } definition` ,
49
- content : JSON . stringify ( schemaSemantic )
50
- } ) ;
51
- }
52
- }
53
-
54
41
// TODO: self?
55
42
56
43
progress ( `Finding objects to work with...` ) ;
@@ -73,24 +60,42 @@ export async function getContextItems(input: string, options: PromptOptions = {}
73
60
if ( context . refs . length === 1 ) {
74
61
const ref = context . refs [ 0 ] ;
75
62
const prettyNameRef = Statement . prettyName ( ref . name ) ;
76
- progress ( `Finding objects related to ${ prettyNameRef } ...` ) ;
77
63
78
- const relatedObjects = await Schemas . getRelatedObjects ( ref ) ;
79
- const contentItems = await getContentItemsForRefs ( relatedObjects ) ;
64
+ if ( ref . sqlType === `SCHEMA` ) {
65
+ followUps . push (
66
+ `What are some objects in that schema?` ,
67
+ `What is the difference between a schema and a library?` ,
68
+ ) ;
69
+ } else {
70
+ progress ( `Finding objects related to ${ prettyNameRef } ...` ) ;
71
+
72
+ const relatedObjects = await Schemas . getRelatedObjects ( ref ) ;
73
+ const contentItems = await getContentItemsForRefs ( relatedObjects ) ;
80
74
81
- contextItems . push ( ...contentItems ) ;
75
+ contextItems . push ( ...contentItems ) ;
82
76
83
- if ( relatedObjects . length === 1 ) {
84
- followUps . push ( `How is ${ prettyNameRef } related to ${ Statement . prettyName ( relatedObjects [ 0 ] . name ) } ?` ) ;
85
- } else if ( ref . sqlType === `TABLE` ) {
86
- followUps . push ( `What are some objects related to that table?` ) ;
77
+ if ( relatedObjects . length === 1 ) {
78
+ followUps . push ( `How is ${ prettyNameRef } related to ${ Statement . prettyName ( relatedObjects [ 0 ] . name ) } ?` ) ;
79
+ } else if ( ref . sqlType === `TABLE` ) {
80
+ followUps . push ( `What are some objects related to that table?` ) ;
81
+ }
87
82
}
88
83
89
84
} else if ( context . refs . length > 1 ) {
90
85
const randomRef = context . refs [ Math . floor ( Math . random ( ) * context . refs . length ) ] ;
91
86
const prettyNameRef = Statement . prettyName ( randomRef . name ) ;
92
87
93
88
followUps . push ( `What are some objects related to ${ prettyNameRef } ?` ) ;
89
+ } else if ( useSchemaDef ) {
90
+ progress ( `Getting info for schema ${ currentSchema } ...` ) ;
91
+ const schemaSemantic = await buildSchemaDefinition ( currentSchema ) ;
92
+ if ( schemaSemantic ) {
93
+ contextItems . push ( {
94
+ name : `SCHEMA Definition` ,
95
+ description : `${ currentSchema } definition` ,
96
+ content : JSON . stringify ( schemaSemantic )
97
+ } ) ;
98
+ }
94
99
}
95
100
96
101
if ( options . withDb2Prompt ) {
0 commit comments