Skip to content

Commit af85751

Browse files
committed
feat(canvas): track pre-prompt last updated
1 parent b2e7c04 commit af85751

File tree

5 files changed

+70
-33
lines changed

5 files changed

+70
-33
lines changed

src/data/plugins/query-box/language-model-selector/language-models.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export const localLanguageModels = [
5151
code: "turbo",
5252
provider: "Perplexity",
5353
},
54-
];
54+
] as const;
5555

56-
export let languageModels: LanguageModel[] = localLanguageModels;
56+
export let languageModels: LanguageModel[] = [...localLanguageModels];
5757
export let groupedLanguageModelsByProvider: GroupedLanguageModelsByProvider =
5858
getGroupedLanguageModelsByProvider();
5959

@@ -89,7 +89,7 @@ CsLoaderRegistry.register({
8989
)();
9090

9191
if (error || !data) {
92-
languageModels = localLanguageModels;
92+
languageModels = [...localLanguageModels];
9393
} else {
9494
languageModels = data;
9595
groupedLanguageModelsByProvider = getGroupedLanguageModelsByProvider();

src/features/plugins/thread/canvas/components/PrePromptInstallationDialog.tsx

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ import {
1717
DialogTitle,
1818
} from "@/components/ui/dialog";
1919
import { toast } from "@/components/ui/use-toast";
20+
import { cplxApiQueries } from "@/services/cplx-api/query-keys";
2021
import { PluginsStatesService } from "@/services/plugins-states/plugins-states";
2122
import { PplxApiService } from "@/services/pplx-api/pplx-api";
22-
import { fetchResource } from "@/utils/utils";
23+
import { unixTimestampToDate } from "@/utils/dayjs";
24+
import { fetchResource, setCookie } from "@/utils/utils";
2325

2426
function CanvasPrePromptInstallationDialog() {
2527
const navigate = useNavigate();
2628

2729
const {
28-
data: canvasInstructionClaudeMd,
30+
data: canvasInstruction,
2931
isError,
3032
isFetching,
3133
} = useQuery({
@@ -46,6 +48,12 @@ function CanvasPrePromptInstallationDialog() {
4648
description: "The Canvas Pre-Prompt has been installed as a Space.",
4749
});
4850

51+
setCookie(
52+
`pplx.source-selection-v3-space-${data.uuid}`,
53+
JSON.stringify([]),
54+
365,
55+
);
56+
4957
sendMessage(
5058
"spa-router:push",
5159
{
@@ -64,6 +72,8 @@ function CanvasPrePromptInstallationDialog() {
6472
},
6573
});
6674

75+
const { data: versions } = useQuery(cplxApiQueries.versions);
76+
6777
return (
6878
<Dialog
6979
defaultOpen={true}
@@ -85,53 +95,63 @@ function CanvasPrePromptInstallationDialog() {
8595
<div className="tw-text-sm tw-text-muted-foreground">
8696
For reference, here is the prompt:
8797
</div>
88-
{canvasInstructionClaudeMd && (
89-
<div className="tw-max-h-[500px] tw-overflow-y-auto tw-whitespace-pre-line tw-rounded-md tw-border tw-border-border/50 tw-bg-secondary tw-p-4 tw-text-sm tw-text-secondary-foreground">
90-
<CopyButton
91-
className="tw-float-right"
92-
content={canvasInstructionClaudeMd}
93-
/>
94-
{canvasInstructionClaudeMd}
95-
</div>
96-
)}
97-
{isFetching && !canvasInstructionClaudeMd && (
98-
<div className="tw-flex tw-flex-col tw-gap-2">
99-
<p className="tw-text-sm tw-text-muted-foreground">
100-
Fetching the Canvas Pre-Prompt, please wait...
101-
</p>
102-
</div>
103-
)}
104-
{isError && (
105-
<div className="tw-flex tw-flex-col tw-gap-2">
106-
<p className="tw-text-sm tw-text-muted-foreground">
107-
Failed to fetch the Canvas Pre-Prompt.
108-
</p>
109-
</div>
110-
)}
98+
<div className="tw-h-[500px] tw-max-h-[500px] tw-overflow-y-auto tw-whitespace-pre-line tw-rounded-md tw-border tw-border-border/50 tw-bg-secondary tw-p-4 tw-text-sm tw-text-secondary-foreground">
99+
{isFetching && !canvasInstruction && (
100+
<div className="tw-flex tw-flex-col tw-gap-2">
101+
<p className="tw-text-sm tw-text-muted-foreground">
102+
Fetching the Canvas Pre-Prompt, please wait...
103+
</p>
104+
</div>
105+
)}
106+
{isError && (
107+
<div className="tw-flex tw-flex-col tw-gap-2">
108+
<p className="tw-text-sm tw-text-muted-foreground">
109+
Failed to fetch the Canvas Pre-Prompt.
110+
</p>
111+
</div>
112+
)}
113+
{canvasInstruction && (
114+
<>
115+
<CopyButton
116+
className="tw-float-right"
117+
content={canvasInstruction}
118+
/>
119+
{canvasInstruction}
120+
</>
121+
)}
122+
</div>
111123
</div>
124+
{versions?.canvasInstructionLastUpdated != null && (
125+
<div className="tw-text-sm tw-text-muted-foreground">
126+
Last updated:{" "}
127+
{unixTimestampToDate({
128+
unixTimestamp: versions.canvasInstructionLastUpdated,
129+
})}
130+
</div>
131+
)}
112132
<DialogFooter>
113-
<DialogClose asChild>
133+
<DialogClose asChild tabIndex={-1}>
114134
<Button variant="outline">Cancel</Button>
115135
</DialogClose>
116136
<AsyncButton
117-
disabled={isFetching || !canvasInstructionClaudeMd}
137+
disabled={isFetching || !canvasInstruction}
118138
loadingText={
119139
<div className="tw-flex tw-items-center tw-gap-2">
120140
<LuLoaderCircle className="tw-animate-spin" />
121141
<span>Installing...</span>
122142
</div>
123143
}
124144
onClick={async () => {
125-
if (!canvasInstructionClaudeMd) {
145+
if (!canvasInstruction) {
126146
return;
127147
}
128148

129149
await createSpace({
130150
title: "CPLX Canvas",
131151
description: "",
132152
emoji: "1f5bc-fe0f",
133-
instructions: canvasInstructionClaudeMd,
134-
model_selection: null,
153+
instructions: canvasInstruction,
154+
model_selection: "claude2",
135155
});
136156
}}
137157
>

src/services/cplx-api/cplx-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class CplxApiService {
3434
latest: parsedData[latest],
3535
changelogEntries: parsedData.changelogEntries,
3636
featureFlagsEntries: parsedData.featureFlagsEntries,
37+
canvasInstructionLastUpdated: parsedData.canvasInstructionLastUpdated,
3738
};
3839
}
3940

src/services/cplx-api/cplx-api.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const CplxVersionsApiResponseSchema = z.object({
55
latestFirefox: z.string(),
66
changelogEntries: z.array(z.string()),
77
featureFlagsEntries: z.array(z.string()),
8+
canvasInstructionLastUpdated: z.number().optional(),
89
});
910

1011
export type CplxVersionsApiResponse = z.infer<

src/utils/dayjs.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dayjs from "dayjs";
2+
import localizedFormat from "dayjs/plugin/localizedFormat";
23
import relativeTime from "dayjs/plugin/relativeTime";
34
import utc from "dayjs/plugin/utc";
45

@@ -49,6 +50,20 @@ const IMPORT_MAP: Record<SupportedLangs, () => Promise<unknown>> = {
4950

5051
dayjs.extend(utc);
5152
dayjs.extend(relativeTime);
53+
dayjs.extend(localizedFormat);
54+
55+
export function unixTimestampToDate({
56+
unixTimestamp,
57+
includeTime = true,
58+
}: {
59+
unixTimestamp: number;
60+
includeTime?: boolean;
61+
}) {
62+
return dayjs
63+
.unix(Math.floor(unixTimestamp / 1000))
64+
.local()
65+
.format(includeTime ? "lll" : "ll");
66+
}
5267

5368
export function formatHowLongAgo(date: string) {
5469
return dayjs.utc(date).local().fromNow();

0 commit comments

Comments
 (0)