Skip to content

Commit

Permalink
Fix null dereference from empty intent/input (microsoft#442)
Browse files Browse the repository at this point in the history
### Motivation and Context
Fixes microsoft#438 

### Description
Old plans do not have the `userIntent` or `originalUserInput` fields, so
use the plan description as a fallback to populate the goal.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [Contribution
Guidelines](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
  • Loading branch information
gitri-ms authored Oct 2, 2023
1 parent 3d04b87 commit 19868f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion webapp/src/components/chat/plan-viewer/PlanViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ export const PlanViewer: React.FC<PlanViewerProps> = ({ message, messageIndex })
plan={plan}
setPlan={setPlan}
planState={planState}
description={getPlanGoal(parsedContent.userIntent ?? parsedContent.originalUserInput)}
description={getPlanGoal(
parsedContent.userIntent ??
parsedContent.originalUserInput ??
parsedContent.proposedPlan.description,
)}
/>
{planState === PlanState.PlanApprovalRequired && (
<>
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/chat/tabs/PlansTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ function useTable(planMessages: IChatMessage[], setChatTab: () => void) {
const items = planMessages
.map((message, index) => {
const parsedPlan = JSON.parse(message.content) as ProposedPlan;
const plangoal = parsedPlan.userIntent ?? parsedPlan.originalUserInput;
const plangoal =
parsedPlan.userIntent ?? parsedPlan.originalUserInput ?? parsedPlan.proposedPlan.description;

return {
index: index,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/libs/models/Plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export interface ProposedPlan {
state: PlanState;

// User input that prompted the plan
originalUserInput: string;
originalUserInput?: string;

// User intent to serves as goal of plan.
userIntent?: string;
Expand Down

0 comments on commit 19868f0

Please sign in to comment.