Skip to content

Commit

Permalink
fix: suggestedAction could be null (#104)
Browse files Browse the repository at this point in the history
* fix: suggestedAction could be null

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: update

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe authored Jan 23, 2024
1 parent 87e5b43 commit 43f24d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 7 additions & 0 deletions server/parsers/basic_input_output_parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ describe('parseSuggestedActions', () => {

it('should return empty array when input is not valid', () => {
expect(parseSuggestedActions('')).toEqual([]);
expect(parseSuggestedActions('6')).toEqual([]);
expect(parseSuggestedActions('true')).toEqual([]);
expect(parseSuggestedActions('false')).toEqual([]);
expect(parseSuggestedActions((null as unknown) as string)).toEqual([]);
});

it('should not throw error when suggested actions is "null"', () => {
expect(parseSuggestedActions('null')).toEqual([]);
});
});
10 changes: 3 additions & 7 deletions server/parsers/basic_input_output_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const sanitize = (content: string) => {
};

const isStringArray = (array?: unknown): array is string[] =>
Array.isArray(array) && array.every((item) => typeof item === 'string');
Array.isArray(array) && !!array.length && array.every((item) => typeof item === 'string');

export const parseSuggestedActions = (value: string): string[] => {
if (!value) {
Expand All @@ -29,12 +29,8 @@ export const parseSuggestedActions = (value: string): string[] => {
suggestedActions = [];
}

if (suggestedActions.length) {
if (isStringArray(suggestedActions)) {
return suggestedActions;
}

return [];
if (isStringArray(suggestedActions)) {
return suggestedActions;
}

/**
Expand Down

0 comments on commit 43f24d7

Please sign in to comment.