Skip to content

Commit ff9df84

Browse files
committed
fix(ai): restore prompt bizTags to List<String> for backward compatibility
Revert PromptMetaSummary.bizTags from String back to List<String> to maintain backward compatibility with existing clients. Add a new bizTagsStr field (String) to carry the raw DB value for console-ui usage. - Restore bizTags field type to List<String> in PromptMetaSummary - Add bizTagsStr (String) field for raw string representation - Add parseBizTagsList() in PromptOperationServiceImpl to convert DB string to List (supports JSON array and comma-separated formats) - Populate both bizTags and bizTagsStr in listPrompts/getPromptDetail - Update legacy console-ui to read from bizTagsStr - Update console-ui-next types and components to use string[] bizTags 🤖 Generated with [Qoder][https://qoder.com]
1 parent dff1617 commit ff9df84

7 files changed

Lines changed: 55 additions & 18 deletions

File tree

ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ public PromptMetaInfo getPromptDetail(String namespaceId, String promptKey) thro
644644
detail.setOnlineCnt(versionInfo.getOnlineCnt());
645645
detail.setLabels(versionInfo.getLabels());
646646
detail.setGmtModified(meta.getGmtModified() == null ? null : meta.getGmtModified().getTime());
647-
detail.setBizTags(meta.getBizTags());
647+
detail.setBizTags(parseBizTagsList(meta.getBizTags()));
648+
detail.setBizTagsStr(meta.getBizTags());
648649

649650
// Load version list
650651
List<AiResourceVersion> allVersions = loadAllVersionRows(namespaceId, promptKey);
@@ -727,7 +728,8 @@ public Page<PromptMetaSummary> listPrompts(String namespaceId, String promptKey,
727728
summary.setLabels(vInfo != null ? vInfo.getLabels() : null);
728729
summary.setGmtModified(
729730
resource.getGmtModified() == null ? null : resource.getGmtModified().getTime());
730-
summary.setBizTags(resource.getBizTags());
731+
summary.setBizTags(parseBizTagsList(resource.getBizTags()));
732+
summary.setBizTagsStr(resource.getBizTags());
731733
items.add(summary);
732734
}
733735
}
@@ -931,6 +933,28 @@ private AiResource requireMeta(String namespaceId, String promptKey) throws Naco
931933
return meta;
932934
}
933935

936+
/**
937+
* Parse biz tags JSON string to list. Supports JSON array format and comma-separated fallback.
938+
*/
939+
private static List<String> parseBizTagsList(String bizTags) {
940+
if (StringUtils.isBlank(bizTags)) {
941+
return new ArrayList<>();
942+
}
943+
try {
944+
return JacksonUtils.toObj(bizTags, List.class);
945+
} catch (Exception e) {
946+
// Fallback: treat as comma-separated
947+
List<String> result = new ArrayList<>();
948+
for (String tag : bizTags.split(",")) {
949+
String trimmed = tag.trim();
950+
if (!trimmed.isEmpty()) {
951+
result.add(trimmed);
952+
}
953+
}
954+
return result;
955+
}
956+
}
957+
934958
private static PromptVersionInfoPojo requireVersionInfo(AiResource meta) {
935959
PromptVersionInfoPojo info = parseVersionInfo(meta == null ? null : meta.getVersionInfo());
936960
if (info == null) {

api/src/main/java/com/alibaba/nacos/api/ai/model/prompt/PromptMetaSummary.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.alibaba.nacos.api.ai.model.prompt;
1818

1919
import java.io.Serializable;
20+
import java.util.ArrayList;
21+
import java.util.List;
2022
import java.util.Map;
2123

2224
/**
@@ -34,7 +36,9 @@ public class PromptMetaSummary implements Serializable {
3436

3537
private String description;
3638

37-
private String bizTags;
39+
private List<String> bizTags = new ArrayList<>();
40+
41+
private String bizTagsStr;
3842

3943
private String latestVersion;
4044

@@ -84,14 +88,22 @@ public void setDescription(String description) {
8488
this.description = description;
8589
}
8690

87-
public String getBizTags() {
91+
public List<String> getBizTags() {
8892
return bizTags;
8993
}
9094

91-
public void setBizTags(String bizTags) {
95+
public void setBizTags(List<String> bizTags) {
9296
this.bizTags = bizTags;
9397
}
9498

99+
public String getBizTagsStr() {
100+
return bizTagsStr;
101+
}
102+
103+
public void setBizTagsStr(String bizTagsStr) {
104+
this.bizTagsStr = bizTagsStr;
105+
}
106+
95107
public String getLatestVersion() {
96108
return latestVersion;
97109
}

console-ui-next/src/components/ai/prompt/PromptCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Checkbox } from '@/components/ui/checkbox';
66
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
77
import { cn } from '@/lib/utils';
88
import dayjs from 'dayjs';
9-
import { parseBizTags, type PromptMetaSummary } from '@/types/prompt';
9+
import { type PromptMetaSummary } from '@/types/prompt';
1010

1111
interface PromptCardProps {
1212
prompt: PromptMetaSummary;
@@ -25,7 +25,7 @@ export function PromptCard({
2525
}: PromptCardProps) {
2626
const { t } = useTranslation();
2727

28-
const bizTags = parseBizTags(prompt.bizTags).slice(0, 2);
28+
const bizTags = (prompt.bizTags || []).slice(0, 2);
2929

3030
return (
3131
<Card

console-ui-next/src/pages/promptDetail/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ import { promptApi } from '@/api/prompt';
7070
import { cn } from '@/lib/utils';
7171
import dayjs from 'dayjs';
7272
import { parsePipelineInfo } from '@/types/skill';
73-
import { parseBizTags } from '@/types/prompt';
7473
import { PromptVersionTimeline } from '@/pages/promptManagement/components/PromptVersionTimeline';
7574
import { PipelineStatusDisplay } from '@/pages/skillManagement/components/PipelineStatusDisplay';
7675
import { LabelBindDialog } from '@/components/ai/LabelBindDialog';
@@ -526,7 +525,7 @@ export default function PromptDetailPage() {
526525
// --- Edit metadata ---
527526
const handleEdit = () => {
528527
setEditDescription(meta?.description || '');
529-
setEditBizTags(parseBizTags(meta?.bizTags));
528+
setEditBizTags(meta?.bizTags || []);
530529
setEditTagInput('');
531530
setEditDialogOpen(true);
532531
};
@@ -696,9 +695,9 @@ export default function PromptDetailPage() {
696695
{dayjs(meta.gmtModified).format('YYYY-MM-DD HH:mm')}
697696
</span>
698697
)}
699-
{meta.bizTags && parseBizTags(meta.bizTags).length > 0 && (
698+
{meta.bizTags && meta.bizTags.length > 0 && (
700699
<div className="flex items-center gap-1">
701-
{parseBizTags(meta.bizTags).slice(0, 3).map((tag) => (
700+
{meta.bizTags.slice(0, 3).map((tag) => (
702701
<Badge key={tag} variant="outline" className="text-[10px] px-1.5 py-0">{tag}</Badge>
703702
))}
704703
</div>
@@ -996,9 +995,9 @@ export default function PromptDetailPage() {
996995
</Button>
997996
</div>
998997
<CardContent className="p-3.5">
999-
{meta.bizTags && parseBizTags(meta.bizTags).length > 0 ? (
998+
{meta.bizTags && meta.bizTags.length > 0 ? (
1000999
<div className="flex flex-wrap gap-1.5">
1001-
{parseBizTags(meta.bizTags).map((tag) => (
1000+
{meta.bizTags.map((tag) => (
10021001
<DetailTagChip key={tag} label={tag} />
10031002
))}
10041003
</div>
@@ -1304,7 +1303,7 @@ export default function PromptDetailPage() {
13041303
<BizTagEditDialog
13051304
open={bizTagDialogOpen}
13061305
onOpenChange={setBizTagDialogOpen}
1307-
tags={parseBizTags(meta?.bizTags)}
1306+
tags={meta?.bizTags || []}
13081307
placeholder={t('prompt.tagPlaceholder')}
13091308
emptyText={t('prompt.noLabels')}
13101309
onSave={handleSaveBizTags}

console-ui-next/src/stores/__tests__/prompt-store.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const mockGovernanceData = {
88
schemaVersion: 1,
99
promptKey: 'test-prompt',
1010
description: 'test',
11-
bizTags: '',
11+
bizTags: [],
12+
bizTagsStr: '',
1213
latestVersion: '1.0.0',
1314
gmtModified: Date.now(),
1415
editingVersion: null,

console-ui-next/src/types/prompt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export interface PromptMetaSummary {
2020
schemaVersion: number;
2121
promptKey: string;
2222
description: string;
23-
bizTags: string; // raw string, use parseBizTags() to get string[]
23+
bizTags: string[]; // parsed list of biz tags
24+
bizTagsStr: string; // raw biz tags string for console-ui compatibility
2425
latestVersion: string;
2526
gmtModified: number;
2627
editingVersion: string | null;

console-ui/src/pages/AI/PromptDetail/PromptDetail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class PromptDetail extends React.Component {
365365
// ===== BizTags Editor =====
366366

367367
handleEditBizTags = () => {
368-
const bizTags = this.state.governanceData?.bizTags;
368+
const bizTags = this.state.governanceData?.bizTagsStr;
369369
let parsed = [];
370370
if (bizTags) {
371371
try {
@@ -1164,7 +1164,7 @@ class PromptDetail extends React.Component {
11641164
const reviewingVersionStr = governanceData?.reviewingVersion || null;
11651165
const description = governanceData?.description || '';
11661166
const bizTags = (() => {
1167-
const raw = governanceData?.bizTags;
1167+
const raw = governanceData?.bizTagsStr;
11681168
if (!raw) return [];
11691169
try {
11701170
const parsed = JSON.parse(raw);

0 commit comments

Comments
 (0)