@@ -16,6 +16,9 @@ import {
1616import { janApiClient , JanChatMessage } from './api'
1717import { janProviderStore } from './store'
1818
19+ // Jan models support tools via MCP
20+ const JAN_MODEL_CAPABILITIES = [ 'tools' ] as const
21+
1922export default class JanProviderWeb extends AIEngine {
2023 readonly provider = 'jan'
2124 private activeSessions : Map < string , SessionInfo > = new Map ( )
@@ -24,6 +27,9 @@ export default class JanProviderWeb extends AIEngine {
2427 console . log ( 'Loading Jan Provider Extension...' )
2528
2629 try {
30+ // Check and clear invalid Jan models (capabilities mismatch)
31+ this . validateJanModelsLocalStorage ( )
32+
2733 // Initialize authentication and fetch models
2834 await janApiClient . initialize ( )
2935 console . log ( 'Jan Provider Extension loaded successfully' )
@@ -35,6 +41,54 @@ export default class JanProviderWeb extends AIEngine {
3541 super . onLoad ( )
3642 }
3743
44+ // Verify Jan models capabilities in localStorage
45+ private validateJanModelsLocalStorage ( ) {
46+ try {
47+ console . log ( "Validating Jan models in localStorage..." )
48+ const storageKey = 'model-provider'
49+ const data = localStorage . getItem ( storageKey )
50+ if ( ! data ) return
51+
52+ const parsed = JSON . parse ( data )
53+ if ( ! parsed ?. state ?. providers ) return
54+
55+ // Check if any Jan model has incorrect capabilities
56+ let hasInvalidModel = false
57+
58+ for ( const provider of parsed . state . providers ) {
59+ if ( provider . provider === 'jan' && provider . models ) {
60+ for ( const model of provider . models ) {
61+ console . log ( `Checking Jan model: ${ model . id } ` , model . capabilities )
62+ if ( JSON . stringify ( model . capabilities ) !== JSON . stringify ( JAN_MODEL_CAPABILITIES ) ) {
63+ hasInvalidModel = true
64+ console . log ( `Found invalid Jan model: ${ model . id } , clearing localStorage` )
65+ break
66+ }
67+ }
68+ }
69+ if ( hasInvalidModel ) break
70+ }
71+
72+ // If any invalid model found, just clear the storage
73+ if ( hasInvalidModel ) {
74+ // Force clear the storage
75+ localStorage . removeItem ( storageKey )
76+ // Verify it's actually removed
77+ const afterRemoval = localStorage . getItem ( storageKey )
78+ // If still present, try setting to empty state
79+ if ( afterRemoval ) {
80+ // Try alternative clearing method
81+ localStorage . setItem ( storageKey , JSON . stringify ( { state : { providers : [ ] } , version : parsed . version || 3 } ) )
82+ }
83+ console . log ( 'Cleared model-provider from localStorage due to invalid Jan capabilities' )
84+ // Force a page reload to ensure clean state
85+ window . location . reload ( )
86+ }
87+ } catch ( error ) {
88+ console . error ( 'Failed to check Jan models:' , error )
89+ }
90+ }
91+
3892 override async onUnload ( ) {
3993 console . log ( 'Unloading Jan Provider Extension...' )
4094
@@ -64,7 +118,7 @@ export default class JanProviderWeb extends AIEngine {
64118 path : undefined , // Remote model, no local path
65119 owned_by : model . owned_by ,
66120 object : model . object ,
67- capabilities : [ 'tools' ] , // Jan models support both tools via MCP
121+ capabilities : [ ... JAN_MODEL_CAPABILITIES ] ,
68122 }
69123 : undefined
70124 )
@@ -85,7 +139,7 @@ export default class JanProviderWeb extends AIEngine {
85139 path : undefined , // Remote model, no local path
86140 owned_by : model . owned_by ,
87141 object : model . object ,
88- capabilities : [ 'tools' ] , // Jan models support both tools via MCP
142+ capabilities : [ ... JAN_MODEL_CAPABILITIES ] ,
89143 } ) )
90144 } catch ( error ) {
91145 console . error ( 'Failed to list Jan models:' , error )
0 commit comments