Skip to content

Commit e821516

Browse files
committed
fix(playground): update JSON patch application result handling
Refactor the JSON patch application logic by renaming the setJsonPatchApplyFailed function to setJsonPatchApplyResult, which now accepts a result parameter to indicate success or failure. This change enhances clarity in error handling and improves the management of JSON patch application states across components.
1 parent 30e679d commit e821516

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

sites/playground/web/src/components/genui-template/GenuiTemplateChat.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
getLastUserMessage,
3333
isManualSchemaSaveMessage,
3434
resolveJsonPatchApplyFailed,
35+
setJsonPatchApplyResult,
3536
} from './template-chat-utils';
3637
import { generateId } from '../../utils';
3738
import { useTemplateContext } from './composables';
@@ -304,8 +305,11 @@ const handleNotification = (event: INotificationPayload) => {
304305
|| findLatestPendingSchemaCard(messages.value)?.cardId
305306
|| '';
306307
const card = cardId ? findSchemaCardByCardId(messages.value, cardId) : null;
307-
const applyFailed =
308-
card?.type === 'json-patch' && resolveJsonPatchApplyFailed(card, messages.value);
308+
let applyFailed = false;
309+
if (card?.type === 'json-patch') {
310+
applyFailed = resolveJsonPatchApplyFailed(card, messages.value);
311+
setJsonPatchApplyResult(applyFailed ? 'failed' : 'success', messages.value, cardId);
312+
}
309313
const preview = schema.currentPreviewSchema;
310314
if (preview && !applyFailed) {
311315
generateIdForComponents(preview);

sites/playground/web/src/components/genui-template/composables/use-template-stream-render.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
validateJsonPatch,
55
PARSE_PARTIAL_JSON_STATE,
66
applyJsonPatchOperations,
7-
setJsonPatchApplyFailed,
7+
setJsonPatchApplyResult,
88
} from '../template-chat-utils';
99
import { clonePlainJson } from '../template-chat-utils/json-patch-format';
1010
import { stripSchemaFieldsWhileStreaming } from '../../../utils';
@@ -115,16 +115,15 @@ async function jsonPatchRenderer(props: {
115115
const targetSchema = applyJsonPatchOperations(patchBaseline, operations as never[]);
116116
if (!targetSchema) {
117117
if (isStreamComplete) {
118-
setJsonPatchApplyFailed(messages.value, cardId, true);
118+
setJsonPatchApplyResult('failed', messages.value, cardId);
119119
}
120120
return;
121121
}
122122

123-
setJsonPatchApplyFailed(messages.value, cardId, false);
124123
const strippedSchema = stripSchemaFieldsWhileStreaming(targetSchema, isStreamComplete);
125124
setCurrentPreviewSchema(strippedSchema, isStreamComplete);
126125
} catch (error) {
127-
setJsonPatchApplyFailed(messages.value, props.cardId, true);
126+
setJsonPatchApplyResult('failed', messages.value, props.cardId);
128127
console.error('jsonPatch error ===>', error);
129128
}
130129
}

sites/playground/web/src/components/genui-template/template-chat-utils/conversation-schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ export function backfillJsonPatchApplyFailedFlags(messages?: ChatMessage[]): boo
125125
return updated;
126126
}
127127

128-
export function setJsonPatchApplyFailed(
128+
export function setJsonPatchApplyResult(
129+
result: 'success' | 'failed',
129130
messages: ChatMessage[] | undefined,
130131
cardId: string,
131-
applyFailed: boolean,
132132
): void {
133133
const card = findSchemaCardByCardId(messages, cardId);
134134
if (card?.type === 'json-patch') {
135-
card.applyFailed = applyFailed;
135+
card.applyFailed = result === 'failed';
136136
}
137137
}
138138

0 commit comments

Comments
 (0)