"Cannot read properties of undefined (reading 'role')" — triggered on every prompt, even with empty context. Seems like a middleware or handler bug with no fallback on missing role

I see this error for every prompt in the prototyper. Even for basic prompts like say “hello”. I couldn’t find a similar thread. Please let me know how to fix this.

say “hello”

Sorry, I hit a snag. Please try again shortly or modify your prompt.

Cannot read properties of undefined (reading ‘role’)

Same here!!!
What happened??? :tired_face:

Same for me. I tried nearly everything, but without any success.

Yup. Same for me. Just started happening.

Completely blocking me from continuing! I really hope they address this soon.

Same here!!!
Testing in other environment.

Same happened for me today after clearing context as i did for last several days. I put my last 2 context entries back and it is resolved for now. I think new model is failing if context entries are all empty.

Hi @Sertac_Firat can you give more details for what you did please? I had cleared my context in the middle of the day. So It was not completely clear when this started happening

Sorry everyone, @Sertac_Firat is right.

What happened here is we landed the first of a few fixes for long histories, but did not account for users who may have been working around this issue locally, i.e. by clearing their histories.

I have a fix ready for this, but it could be a few days before it rolls to prod.

In the meantime, the only option is to ensure a user and model turn are in the history. The safest way to do this is to create a new workspace, and to copy the structure of the context.json from the known good workspace. The other option is to try and do this manually, and in that case you want something like:

{
  "currentProposalObject": {...},
  "agentHistories": {
    "app-prototyping-agent: proposal-agent": [
      {
        "role": "user",
        "content": [
          {
            "text": "..."
          }
        ]
      },
      {
        "role": "model",
        "content": [
          {
            "text": "..."
          }
        ]
      }
    ],
    "app-prototyping-agent: edit-app-agent": [
      {
        "role": "user",
        "content": [
          {
            "text": "..."
          }
        ]
      },
      {
        "role": "model",
        "content": [
          {
            "text": "..."
          }
        ]
      }
    ]
  },
  "currentState": "edit-app"
}

My apologies if this is confusing, or if the workaround doesn’t quite work in all cases. We’ll have a proper fix rolled out to prod next week.

I opened up studio in my current project, started a new terminal, ran:

code /home/user/.idx/ai/capra-context-state.json

And then I had to actually rename the “capra-text-state.json” to “prototyper-context-state.json” instead. I went and followed the dev’s instructions on starting a new workspace. It’s not called capra-text-state.json anymore. So instead of using that in the command, try this in the new workspace:

code /home/user/.idx/ai/prototyper-context-state.json

I also had to make sure the old capra-text-state.json would fill in the correct information into the new prototyper. So I copied the file, pasted it into an ai model that works, pasted the prototyper context state from the new workspace in, and used this prompt with the “Tipsplit” example project:

My Firebase Studio project context for [INSERT YOUR PROJECT NAME] is showing placeholder data instead of actual project information. I have a working example from a TipSplit project that demonstrates the correct JSON structure with populated core features, UI guidelines, and agent histories. I need to update my project context to follow that same format.

Hi @Joshua_Litt , can you please notify here when the fix is ready in prod, please?

I managed to get back to work. What I did:

  1. Open the capra-context-state.json at terminal:
code /home/user/.idx/ai/capra-context-state.json
  1. Changed the code based on a new project
{
   "currentProposalObject":{
      "appName":"SmartTracking",
      "coreFeatures":[
         {
            "name":"Existing Project Core",
            "description":"Details to be determined by codebase scan.",
            "categories":[
               "ui"
            ]
         }
      ],
      "uiStyleGuidelines":[
         {
            "category":"layout",
            "description":"Awaiting codebase scan for details."
         }
      ]
   },
   "agentHistories":{
      "app-prototyping-agent: proposal-agent":[
         {
            "role":"user",
            "content":[
               {
                  "text":"I'm ready to work on your project. Please let me know what you'd like to do."
               }
            ]
         },
         {
            "role":"model",
            "content":[
               {
                  "text":"I'm ready to work on your project. Please let me know what you'd like to do."
               }
            ]
         }
      ],
      "app-prototyping-agent: edit-app-agent":[
         {
            "role":"user",
            "content":[
               {
                  "text":"..."
               }
            ]
         },
         {
            "role":"model",
            "content":[
               {
                  "text":"..."
               }
            ]
         }
      ]
   },
   "currentState":"edit-app"
}

Hello, how are you?

Is there any news on a definitive solution to this issue?

you can try adding an other model . the new 2.5 model is smarter then the basic model. Go to ai studio generte and api key for the project then add it to your project and select the LLM .

could you please explain in more detail , how can i change the model in my prototyper ?

infirbase studio ther is a code view and a prototiper view.
go to code view
you will seee code and a preview onf your site . In an other tab next to the previw youwill vind geminie. Clivk on geminie.

At the bottum you can see the model used .Select gemenie 2.5 . It will wask for anapi key

go to https://aistudio.google.com/ generate an api key for your project

past the key inyour project . It will give you the positionwhere to past it when youselect an other model

make sure youcanchat with geminie withthe model selected. If so you are set ready to go

this model will be used for the prototyper as well . It has huge free resources but youcan see what you have used in th https://aistudio.google.com/

hope this helps