@@ -55,6 +55,8 @@ interface AIProviderExecutor {
5555 * Chrome Built-in AI Provider
5656 */
5757class ChromeAIProvider implements AIProviderExecutor {
58+ constructor ( private config ?: Extract < AIProvider , { type : 'chrome' } > ) { }
59+
5860 async checkAvailability ( ) {
5961 if ( typeof window === 'undefined' || typeof LanguageModel === 'undefined' ) {
6062 return { available : false , status : 'unavailable' , needsDownload : false } ;
@@ -78,7 +80,7 @@ class ChromeAIProvider implements AIProviderExecutor {
7880 formContext : Record < string , any >
7981 ) : Promise < AIResponse | null > {
8082 try {
81- const prompt = `You are assisting with form completion. The user is filling out a field named "${ fieldName } ".
83+ const defaultPrompt = `You are assisting with form completion. The user is filling out a field named "${ fieldName } ".
8284
8385Current value: "${ currentValue } "
8486Form context: ${ JSON . stringify ( formContext , null , 2 ) }
@@ -93,6 +95,13 @@ Rules:
9395
9496Suggested value:` ;
9597
98+ const prompt = this . config ?. systemPrompt
99+ ? this . config . systemPrompt
100+ . replace ( '{fieldName}' , fieldName )
101+ . replace ( '{currentValue}' , currentValue )
102+ . replace ( '{formContext}' , JSON . stringify ( formContext , null , 2 ) )
103+ : defaultPrompt ;
104+
96105 const session = await LanguageModel . create ( ) ;
97106 const result = await session . prompt ( prompt ) ;
98107 session . destroy ( ) ;
@@ -111,7 +120,7 @@ Suggested value:`;
111120 onProgress ?: ( progress : number ) => void
112121 ) : Promise < AutofillData | null > {
113122 try {
114- const prompt = `You are an intelligent form assistant. Generate realistic example values for a form.
123+ const defaultPrompt = `You are an intelligent form assistant. Generate realistic example values for a form.
115124
116125Form fields: ${ fields . join ( ', ' ) }
117126Context: ${ JSON . stringify ( formContext , null , 2 ) }
@@ -124,6 +133,12 @@ Example format:
124133
125134JSON object:` ;
126135
136+ const prompt = this . config ?. systemPrompt
137+ ? this . config . systemPrompt
138+ . replace ( '{fields}' , fields . join ( ', ' ) )
139+ . replace ( '{formContext}' , JSON . stringify ( formContext , null , 2 ) )
140+ : defaultPrompt ;
141+
127142 const session = await LanguageModel . create ( {
128143 monitor ( m ) {
129144 m . addEventListener ( 'downloadprogress' , ( e ) => {
@@ -338,7 +353,7 @@ class CustomServerProvider implements AIProviderExecutor {
338353export function createAIProvider ( config : AIProvider ) : AIProviderExecutor {
339354 switch ( config . type ) {
340355 case 'chrome' :
341- return new ChromeAIProvider ( ) ;
356+ return new ChromeAIProvider ( config ) ;
342357 case 'openai' :
343358 return new OpenAIProvider ( config ) ;
344359 case 'custom' :
0 commit comments