@@ -10,26 +10,21 @@ import {
1010 GitHubCopilotAgent ,
1111 AgentMessage
1212} from '../interfaces/agentInterface' ;
13- import { PromptService , PromptUsageContext , TsxRenderOptions , TsxRenderResult } from '../shared/promptManager/types' ;
13+ import { PromptService , PromptUsageContext } from '../shared/promptManager/types' ;
1414import { PromptServiceFactory } from '../shared/promptManager/PromptServiceFactory' ;
15- import { AgentPrompt } from '../shared/promptManager/tsx/components/AgentPrompt' ;
16- import { ChatMessage , DEFAULT_PRIORITIES } from '../shared/promptManager/tsx/types' ;
1715
1816/**
1917 * Configuration interface for agent prompt handling
2018 */
2119interface AgentPromptConfig {
2220 maxTokens : number ;
2321 historyMessageCount : number ;
24- enablePrioritization : boolean ;
25- fallbackToStringConcatenation : boolean ;
2622}
2723
2824/**
2925 * Wu Wei Agent Panel Provider (Enhanced with Prompt Integration)
3026 * Provides a panel for triggering agents with messages using separated HTML, CSS, and JavaScript files
3127 * Phase 4: Added prompt selection and integration capabilities
32- * Phase 5: Enhanced with TSX-based prompt composition (Issue #378)
3328 */
3429export class AgentPanelProvider extends BaseWebviewProvider implements vscode . WebviewViewProvider {
3530 private _agentRegistry : AgentRegistry ;
@@ -38,14 +33,12 @@ export class AgentPanelProvider extends BaseWebviewProvider implements vscode.We
3833 private _selectedPromptContext ?: PromptUsageContext ;
3934 private _agentPromptConfig : AgentPromptConfig = {
4035 maxTokens : 4096 ,
41- historyMessageCount : 4 ,
42- enablePrioritization : true ,
43- fallbackToStringConcatenation : true
36+ historyMessageCount : 4
4437 } ;
4538
4639 constructor ( context : vscode . ExtensionContext ) {
4740 super ( context ) ;
48- logger . debug ( 'Wu Wei Agent Panel Provider initialized with prompt integration and TSX support ' ) ;
41+ logger . debug ( 'Wu Wei Agent Panel Provider initialized with prompt integration' ) ;
4942
5043 // Initialize prompt service
5144 this . _promptService = PromptServiceFactory . createService ( context ) ;
@@ -282,32 +275,37 @@ export class AgentPanelProvider extends BaseWebviewProvider implements vscode.We
282275 return params ;
283276 }
284277
285- // Try TSX-based rendering first if enabled
286- if ( this . _agentPromptConfig . enablePrioritization ) {
287- try {
288- return await this . enhanceParamsWithTsxPrompt ( params , promptContext , agent ) ;
289- } catch ( error ) {
290- logger . warn ( 'TSX prompt rendering failed, falling back to string concatenation' , error ) ;
291-
292- // If fallback is disabled, re-throw the error
293- if ( ! this . _agentPromptConfig . fallbackToStringConcatenation ) {
294- throw error ;
295- }
296- }
278+ // Check if both prompt and user input are empty - do nothing in this case
279+ const userInput = params . message || params . question || params . query || params . input ;
280+ if ( ! promptContext . promptId && ! userInput ) {
281+ throw new Error ( 'Please provide either a prompt template or a message' ) ;
297282 }
298283
299- // Original string concatenation logic (fallback)
284+ // String concatenation logic
300285 const capabilities = agent . getCapabilities ( ) ;
301286 const promptSupport = capabilities . metadata ?. promptSupport ;
302287
303288 if ( promptSupport ?. supportsPrompts ) {
304289 const promptParam = promptSupport . promptParameterName || 'prompt' ;
305290
306- // Render the prompt with variables
307- const rendered = await this . _promptService . renderPromptWithVariables (
308- promptContext . promptId ,
309- promptContext . variables
310- ) ;
291+ // Check if the prompt has variables that need rendering
292+ const hasVariables = promptContext . variables && Object . keys ( promptContext . variables ) . length > 0 ;
293+
294+ let rendered : string ;
295+ if ( hasVariables ) {
296+ // Render the prompt with variables
297+ rendered = await this . _promptService . renderPromptWithVariables (
298+ promptContext . promptId ,
299+ promptContext . variables
300+ ) ;
301+ } else {
302+ // Get the prompt file path for direct reference
303+ const promptData = await this . _promptService . getPrompt ( promptContext . promptId ) ;
304+ if ( ! promptData ) {
305+ throw new Error ( `Prompt with id '${ promptContext . promptId } ' not found` ) ;
306+ }
307+ rendered = promptData . filePath ? `#${ promptData . filePath } ` : promptData . content ;
308+ }
311309
312310 const enhancedParams = {
313311 ...params ,
@@ -318,120 +316,58 @@ export class AgentPanelProvider extends BaseWebviewProvider implements vscode.We
318316 enhancedParams . variables = promptContext . variables ;
319317 }
320318
321- // Always use combined mode - check for user input
319+ // Support optional user input - can use prompt alone or combined with user message
322320 const userInput = params . message || params . question || params . query || params . input ;
323- if ( ! userInput ) {
324- throw new Error ( 'Please provide a custom message to combine with the prompt template' ) ;
321+ if ( userInput ) {
322+ enhancedParams . additionalMessage = userInput ;
325323 }
326- enhancedParams . additionalMessage = userInput ;
327324
328325 return enhancedParams ;
329326 }
330327
331328 // Fallback: add prompt as message parameter
332329 if ( promptContext . promptId ) {
333- const rendered = await this . _promptService . renderPromptWithVariables (
334- promptContext . promptId ,
335- promptContext . variables
336- ) ;
330+ // Check if the prompt has variables that need rendering
331+ const hasVariables = promptContext . variables && Object . keys ( promptContext . variables ) . length > 0 ;
332+
333+ let promptContent : string ;
334+ if ( hasVariables ) {
335+ // Render the prompt with variables
336+ const rendered = await this . _promptService . renderPromptWithVariables (
337+ promptContext . promptId ,
338+ promptContext . variables
339+ ) ;
340+ promptContent = "System Instructions:\n" + rendered ;
341+ } else {
342+ // Get the prompt file path for direct reference
343+ const promptData = await this . _promptService . getPrompt ( promptContext . promptId ) ;
344+ if ( ! promptData ) {
345+ throw new Error ( `Prompt with id '${ promptContext . promptId } ' not found` ) ;
346+ }
347+ promptContent = promptData . filePath ? `Follow Instances in ${ promptData . filePath } ` : "System Instructions:\n" + promptData . content ;
348+ }
337349
338- // Always use combined mode - require both prompt and custom message
350+ // Support optional user input - can use prompt alone or combined with user message
339351 const userInput = params . message || params . question || params . query || params . input ;
340- if ( ! userInput ) {
341- throw new Error ( 'Please provide a custom message to combine with the prompt template' ) ;
342- }
343352
344- // Combine prompt and custom message
345- return {
346- ...params ,
347- message : `${ rendered } \n\n${ userInput } `
348- } ;
353+ if ( userInput ) {
354+ // Combine prompt with user input
355+ return {
356+ ...params ,
357+ message : `${ promptContent } \n\nUser Request:\n${ userInput } `
358+ } ;
359+ } else {
360+ // Use prompt alone
361+ return {
362+ ...params ,
363+ message : promptContent
364+ } ;
365+ }
349366 }
350367
351368 return params ;
352369 }
353370
354- /**
355- * Enhanced TSX-based prompt parameter enhancement
356- * Replaces string concatenation with intelligent TSX composition
357- */
358- private async enhanceParamsWithTsxPrompt (
359- params : any ,
360- promptContext : any ,
361- agent : AbstractAgent
362- ) : Promise < any > {
363- if ( ! promptContext ) {
364- return params ;
365- }
366-
367- const userInput = params . message || params . question || params . query || params . input ;
368- if ( ! userInput ) {
369- throw new Error ( 'Please provide a custom message to combine with the prompt template' ) ;
370- }
371-
372- // Render the prompt with variables
373- const rendered = await this . _promptService . renderPromptWithVariables (
374- promptContext . promptId ,
375- promptContext . variables
376- ) ;
377-
378- // Convert message history to ChatMessage format
379- const conversationHistory : ChatMessage [ ] = this . _messageHistory
380- . filter ( msg => msg . type === 'request' || msg . type === 'response' )
381- . slice ( - this . _agentPromptConfig . historyMessageCount )
382- . map ( msg => ( {
383- role : msg . type === 'request' ? 'user' : 'assistant' ,
384- content : this . extractMessageContent ( msg ) ,
385- timestamp : msg . timestamp ,
386- id : msg . id
387- } ) ) ;
388-
389- // Prepare TSX rendering options
390- const tsxOptions : TsxRenderOptions = {
391- modelMaxPromptTokens : this . _agentPromptConfig . maxTokens ,
392- enablePrioritization : this . _agentPromptConfig . enablePrioritization ,
393- tokenBudget : this . _agentPromptConfig . maxTokens
394- } ;
395-
396- // Render TSX prompt with intelligent composition
397- const tsxResult : TsxRenderResult = await this . _promptService . renderTsxPrompt (
398- AgentPrompt ,
399- {
400- systemPrompt : rendered ,
401- userInput : userInput ,
402- conversationHistory : conversationHistory ,
403- contextData : params . context || '' ,
404- maxTokens : this . _agentPromptConfig . maxTokens ,
405- priorityStrategy : DEFAULT_PRIORITIES
406- } ,
407- tsxOptions
408- ) ;
409-
410- // Check agent capabilities for TSX support
411- const capabilities = agent . getCapabilities ( ) ;
412- const promptSupport = capabilities . metadata ?. promptSupport ;
413-
414- if ( promptSupport ?. supportsPrompts && promptSupport . supportsTsxMessages ) {
415- // Agent supports TSX messages directly
416- return {
417- ...params ,
418- messages : tsxResult . messages ,
419- tokenCount : tsxResult . tokenCount ,
420- renderingMetadata : tsxResult . renderingMetadata
421- } ;
422- } else {
423- // Convert TSX messages back to string format for compatibility
424- const combinedMessage = this . convertTsxMessagesToString ( tsxResult . messages ) ;
425-
426- return {
427- ...params ,
428- message : combinedMessage ,
429- tokenCount : tsxResult . tokenCount ,
430- renderingMetadata : tsxResult . renderingMetadata
431- } ;
432- }
433- }
434-
435371 /**
436372 * Extract content from AgentMessage for conversation history
437373 */
@@ -444,38 +380,6 @@ export class AgentPanelProvider extends BaseWebviewProvider implements vscode.We
444380 return 'Unknown message' ;
445381 }
446382
447- /**
448- * Convert TSX messages to string format for agents that don't support TSX
449- */
450- private convertTsxMessagesToString ( messages : vscode . LanguageModelChatMessage [ ] ) : string {
451- return messages . map ( msg => {
452- // Map roles to string labels
453- let role = 'USER' ;
454- if ( msg . role === vscode . LanguageModelChatMessageRole . User ) {
455- role = 'USER' ;
456- } else {
457- // For any other role (system, assistant, etc.), use generic labels
458- role = 'ASSISTANT' ;
459- }
460-
461- // Extract text content from message
462- const content = Array . isArray ( msg . content )
463- ? msg . content . map ( part => {
464- if ( typeof part === 'string' ) {
465- return part ;
466- } else if ( part && typeof part === 'object' && 'text' in part ) {
467- return part . text ;
468- } else if ( part && typeof part === 'object' && 'value' in part ) {
469- return String ( part . value ) ;
470- }
471- return JSON . stringify ( part ) ;
472- } ) . join ( ' ' )
473- : String ( msg . content ) ;
474-
475- return `${ role } : ${ content } ` ;
476- } ) . join ( '\n\n' ) ;
477- }
478-
479383 /**
480384 * Update agent prompt configuration
481385 */
0 commit comments