@@ -17,6 +17,7 @@ import {
17
17
} from "../context" ;
18
18
import { DB2_SELF_PROMPT , DB2_SYSTEM_PROMPT } from "../prompts" ;
19
19
import Configuration from "../../configuration" ;
20
+ import { getContextItems } from "../prompt" ;
20
21
21
22
export let isContinueActive = false ;
22
23
@@ -138,71 +139,33 @@ export class db2ContextProvider implements IContextProvider {
138
139
) : Promise < ContextItem [ ] > {
139
140
const contextItems : ContextItem [ ] = [ ] ;
140
141
if ( canTalkToDb ( ) ) {
141
- const job : JobInfo = this . getCurrentJob ( ) ;
142
- const schema = this . getDefaultSchema ( ) ;
142
+ const job = this . getCurrentJob ( ) ;
143
143
const fullInput = extras . fullInput ;
144
144
145
- // 1. SCHEMA Definiton (semantic)
146
- const useSchemaDef : boolean = Configuration . get < boolean > ( `ai.useSchemaDefinition` ) ;
147
-
148
- if ( useSchemaDef ) {
149
- const schemaSemantic = await buildSchemaDefinition ( schema ) ;
150
- if ( schemaSemantic ) {
151
- contextItems . push ( {
152
- name : `SCHEMA Definition` ,
153
- description : `${ schema } definition` ,
154
- content : JSON . stringify ( schemaSemantic ) ,
155
- } ) ;
156
- }
157
- }
158
-
159
- try {
160
- switch ( true ) {
161
- case fullInput . includes ( `*SELF` ) || query ?. includes ( `*SELF` ) :
162
- // get current self code errors in job
163
- // build promt with error information
164
- // add to contextItems
165
-
166
- if ( job ) {
167
- const selfCodes = await this . getSelfCodes ( job ) ;
168
-
169
- let prompt = DB2_SELF_PROMPT . join ( " " ) ;
170
- prompt += JSON . stringify ( selfCodes , null , 2 ) ;
171
-
172
- contextItems . push ( {
173
- name : `${ job . name } -self` ,
174
- description : `SELF code errors for ${ job . name } ` ,
175
- content : prompt ,
176
- } ) ;
177
- }
178
-
179
- break ;
180
- default :
181
- // 2. TABLE References
182
- const tablesRefs = await getSqlContextItems ( fullInput ) ;
183
- for ( const table of tablesRefs ) {
184
- contextItems . push ( {
185
- name : `table definition for ${ table . id } ` ,
186
- content : table . content ,
187
- description : `${ table . type } definition` ,
188
- } ) ;
189
- }
190
-
191
- break ;
192
- }
193
- } catch ( error ) {
194
- vscode . window . showErrorMessage (
195
- `Failed to query Db2i database: ${ error } `
196
- ) ;
197
- throw new Error ( `Failed to query Db2i database: ${ error } ` ) ;
198
- } finally {
199
- // 3. DB2 Guidelines
145
+ if ( job && fullInput . includes ( `*SELF` ) || query ?. includes ( `*SELF` ) ) {
146
+ // get current self code errors in job
147
+ // build promt with error information
148
+ // add to contextItems
149
+
150
+ const selfCodes = await this . getSelfCodes ( job ) ;
151
+
152
+ let prompt = DB2_SELF_PROMPT . join ( " " ) ;
153
+ prompt += JSON . stringify ( selfCodes , null , 2 ) ;
154
+
200
155
contextItems . push ( {
201
- name : `Db2i Guidelines ` ,
202
- content : DB2_SYSTEM_PROMPT ,
203
- description : `Guidelines for Db2i Context provider` ,
156
+ name : `${ job . name } -self ` ,
157
+ description : `SELF code errors for ${ job . name } ` ,
158
+ content : prompt ,
204
159
} ) ;
205
160
}
161
+
162
+ const newContextItems = await getContextItems ( fullInput , {
163
+ withDb2Prompt : true ,
164
+ } )
165
+
166
+ contextItems . push ( ...newContextItems . context ) ;
167
+
168
+
206
169
} else {
207
170
throw new Error (
208
171
`Not connected to the database. Please check your configuration.`
0 commit comments