mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-10 03:03:37 +02:00
Improved prompt function add add ctx.* functions (#301)
This commit is contained in:
@@ -1,17 +1,25 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { RenderPurpose } from '@yaakapp-internal/plugins';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { minPromiseMillis } from '../lib/minPromiseMillis';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||
import { activeWorkspaceIdAtom } from './useActiveWorkspace';
|
||||
|
||||
export function useRenderTemplate(template: string) {
|
||||
export function useRenderTemplate(
|
||||
template: string,
|
||||
enabled: boolean,
|
||||
purpose: RenderPurpose,
|
||||
refreshKey: string | null,
|
||||
) {
|
||||
const workspaceId = useAtomValue(activeWorkspaceIdAtom) ?? 'n/a';
|
||||
const environmentId = useActiveEnvironment()?.id ?? null;
|
||||
return useQuery<string>({
|
||||
refetchOnWindowFocus: false,
|
||||
queryKey: ['render_template', template, workspaceId, environmentId],
|
||||
queryFn: () => minPromiseMillis(renderTemplate({ template, workspaceId, environmentId }), 200),
|
||||
enabled,
|
||||
queryKey: ['render_template', workspaceId, environmentId, refreshKey, purpose],
|
||||
queryFn: () =>
|
||||
minPromiseMillis(renderTemplate({ template, workspaceId, environmentId, purpose }), 300),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,12 +27,14 @@ export async function renderTemplate({
|
||||
template,
|
||||
workspaceId,
|
||||
environmentId,
|
||||
purpose,
|
||||
}: {
|
||||
template: string;
|
||||
workspaceId: string;
|
||||
environmentId: string | null;
|
||||
purpose: RenderPurpose;
|
||||
}): Promise<string> {
|
||||
return invokeCmd('cmd_render_template', { template, workspaceId, environmentId });
|
||||
return invokeCmd('cmd_render_template', { template, workspaceId, environmentId, purpose });
|
||||
}
|
||||
|
||||
export async function decryptTemplate({
|
||||
|
||||
Reference in New Issue
Block a user