Skip to content

Commit 9865d92

Browse files
authored
Merge pull request #532 from refly-ai/fix/skill-rerun
fix: skill rerun issues and node preview truncation
2 parents 06e5421 + bc6b0a1 commit 9865d92

File tree

10 files changed

+37
-40
lines changed

10 files changed

+37
-40
lines changed

.github/workflows/build-image.yml

-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ name: Build and Push Docker Images
22

33
on:
44
workflow_dispatch:
5-
push:
6-
branches: [ main ]
7-
paths:
8-
- 'apps/api/**'
9-
- 'apps/web/**'
10-
- 'packages/**'
115

126
jobs:
137
build-and-push:

.github/workflows/e2e.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: End-to-End Tests
22

33
on:
4-
pull_request:
5-
types: [opened, synchronize]
4+
pull_request_review:
5+
types: [submitted]
66

77
jobs:
88
e2e:
9+
if: github.event.review.state == 'approved'
910
runs-on: ubuntu-latest
1011
strategy:
1112
fail-fast: false # https://github.com/cypress-io/github-action/issues/48

packages/ai-workspace-common/src/components/canvas/node-preview/skill-response/index.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ const SkillResponseNodePreviewComponent = ({ node, resultId }: SkillResponseNode
173173
{
174174
resultId,
175175
query: title,
176+
selectedSkill: {
177+
name: actionMeta?.name || 'CommonQnA',
178+
},
179+
contextItems,
176180
},
177181
{
178182
entityId: canvasId,

packages/ai-workspace-common/src/components/canvas/nodes/document.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,6 @@ export const DocumentNode = memo(
244244
content={data.contentPreview || t('canvas.nodePreview.document.noContentPreview')}
245245
sizeMode={sizeMode}
246246
isOperating={isOperating}
247-
isLoading={data.metadata?.status === 'executing' && !data.contentPreview}
248-
maxCompactLength={20}
249247
className="min-h-8"
250248
/>
251249
</div>

packages/ai-workspace-common/src/components/canvas/nodes/resource.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { useCreateDocument } from '@refly-packages/ai-workspace-common/hooks/can
3434
import { message, Result } from 'antd';
3535
import getClient from '@refly-packages/ai-workspace-common/requests/proxiedRequest';
3636
import { useEditorPerformance } from '@refly-packages/ai-workspace-common/context/editor-performance';
37+
import { useSubscriptionUsage } from '@refly-packages/ai-workspace-common/hooks/use-subscription-usage';
3738

3839
const NodeContent = memo(
3940
({ data, isOperating }: { data: CanvasNodeData<ResourceNodeMeta>; isOperating: boolean }) => {
@@ -65,7 +66,6 @@ const NodeContent = memo(
6566
content={data.contentPreview || t('canvas.nodePreview.resource.noContentPreview')}
6667
sizeMode={sizeMode}
6768
isOperating={isOperating}
68-
maxCompactLength={10}
6969
/>
7070
);
7171
},
@@ -97,6 +97,8 @@ export const ResourceNode = memo(
9797
const isDragging = draggingNodeId === id;
9898
const node = useMemo(() => getNode(id), [id, getNode]);
9999

100+
const { refetchUsage } = useSubscriptionUsage();
101+
100102
const { containerStyle, handleResize } = useNodeSize({
101103
id,
102104
node,
@@ -252,6 +254,10 @@ export const ResourceNode = memo(
252254
},
253255
},
254256
);
257+
258+
if (indexStatus === 'finish' && resourceType === 'file') {
259+
refetchUsage();
260+
}
255261
}
256262
}, [data.entityId, remoteResult, setNodeDataByEntity]);
257263

packages/ai-workspace-common/src/components/canvas/nodes/shared/content-preview.tsx

+9-19
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,33 @@ interface ContentPreviewProps {
77
sources?: Source[];
88
sizeMode: 'compact' | 'adaptive';
99
isOperating: boolean;
10-
maxCompactLength?: number;
1110
className?: string;
1211
}
1312

1413
export const ContentPreview = memo(
15-
({
16-
content,
17-
sources,
18-
sizeMode,
19-
isOperating,
20-
maxCompactLength = 10,
21-
className = '',
22-
}: ContentPreviewProps) => {
23-
const previewContent = useMemo(() => {
24-
if (sizeMode === 'compact') {
25-
return `${content?.slice(0, maxCompactLength)}...` || '';
26-
}
27-
return content || '';
28-
}, [content, sizeMode, maxCompactLength]);
14+
({ content, sources, sizeMode, isOperating, className = '' }: ContentPreviewProps) => {
15+
const previewContent = content ?? '';
2916

3017
// Memoize className to prevent re-renders when only isOperating changes
3118
const markdownClassName = useMemo(
3219
() =>
33-
`text-xs overflow-hidden ${isOperating ? 'pointer-events-auto cursor-text select-text' : 'pointer-events-none select-none'} ${className}`,
34-
[isOperating, className],
20+
`text-xs overflow-hidden ${sizeMode === 'compact' ? 'max-h-[1.5rem] line-clamp-1' : ''} ${
21+
isOperating
22+
? 'pointer-events-auto cursor-text select-text'
23+
: 'pointer-events-none select-none'
24+
} ${className}`,
25+
[isOperating, sizeMode, className],
3526
);
3627

3728
return (
38-
<Markdown className={markdownClassName} content={previewContent} sources={sources || []} />
29+
<Markdown className={markdownClassName} content={previewContent} sources={sources ?? []} />
3930
);
4031
},
4132
(prevProps, nextProps) => {
4233
return (
4334
prevProps.content === nextProps.content &&
4435
prevProps.sizeMode === nextProps.sizeMode &&
4536
prevProps.isOperating === nextProps.isOperating &&
46-
prevProps.maxCompactLength === nextProps.maxCompactLength &&
4737
prevProps.className === nextProps.className &&
4838
JSON.stringify(prevProps.sources) === JSON.stringify(nextProps.sources)
4939
);

packages/ai-workspace-common/src/components/canvas/nodes/shared/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
IndexError,
99
IndexStatus,
1010
ModelInfo,
11+
ResourceType,
1112
Skill,
1213
SkillTemplateConfig,
1314
TokenUsageItem,
@@ -39,7 +40,7 @@ export interface DocumentNodeMeta {
3940
}
4041

4142
export interface ResourceNodeMeta {
42-
resourceType?: string;
43+
resourceType?: ResourceType;
4344
indexStatus?: IndexStatus;
4445
indexError?: IndexError;
4546
sizeMode?: 'compact' | 'adaptive';

packages/ai-workspace-common/src/components/canvas/nodes/skill-response.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export const SkillResponseNode = memo(
240240
: '';
241241

242242
const skill = {
243-
name: actionMeta?.name || '',
243+
name: actionMeta?.name || 'CommonQnA',
244244
icon: actionMeta?.icon,
245245
};
246246
const skillName = actionMeta?.name;
@@ -288,6 +288,7 @@ export const SkillResponseNode = memo(
288288
{
289289
resultId: entityId,
290290
query: title,
291+
selectedSkill: skill,
291292
contextItems: data?.metadata?.contextItems,
292293
},
293294
{
@@ -598,7 +599,6 @@ export const SkillResponseNode = memo(
598599
content={content || t('canvas.nodePreview.resource.noContentPreview')}
599600
sizeMode={sizeMode}
600601
isOperating={isOperating}
601-
maxCompactLength={10}
602602
sources={sources}
603603
/>
604604
)}

packages/ai-workspace-common/src/hooks/use-subscription-usage.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { useGetSubscriptionUsage } from '@refly-packages/ai-workspace-common/queries/queries';
2+
import { subscriptionEnabled } from '@refly-packages/ai-workspace-common/utils/env';
23

34
export const useSubscriptionUsage = () => {
45
const {
56
data,
67
isLoading: isUsageLoading,
78
refetch,
89
} = useGetSubscriptionUsage({}, [], {
9-
refetchOnWindowFocus: false,
10-
refetchOnMount: false,
11-
refetchOnReconnect: false,
12-
staleTime: 60 * 1000, // Consider data fresh for 1 minute
13-
gcTime: 60 * 1000, // Cache for 1 minute
10+
refetchOnWindowFocus: true,
11+
refetchOnMount: true,
12+
refetchOnReconnect: true,
13+
refetchInterval: 15 * 1000, // Refetch every 15 seconds
14+
staleTime: 15 * 1000,
15+
gcTime: 15 * 1000,
16+
enabled: subscriptionEnabled,
1417
});
1518
const { token, storage, fileParsing } = data?.data ?? {};
1619

packages/ai-workspace-common/src/utils/env.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export const wsServerOrigin =
44
(typeof window !== 'undefined' && window.ENV?.COLLAB_URL) || import.meta.env.VITE_COLLAB_URL;
55

66
export const subscriptionEnabled =
7-
(typeof window !== 'undefined' && window.ENV?.SUBSCRIPTION_ENABLED) ||
8-
import.meta.env.VITE_SUBSCRIPTION_ENABLED;
7+
Boolean(typeof window !== 'undefined' && window.ENV?.SUBSCRIPTION_ENABLED) ||
8+
Boolean(import.meta.env.VITE_SUBSCRIPTION_ENABLED);

0 commit comments

Comments
 (0)