Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"react-dom": "^19.2.7",
"react-markdown": "^10.1.0",
"remark-gfm": "^4.0.1",
"sonner": "^2.0.7",
"zod": "^4.4.3"
}
}
30 changes: 26 additions & 4 deletions plugin/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getApiUrlAndToken } from '@ds-wizard/plugin-sdk/requests'

import type {
PipelineRunResponse,
PipelineStatusResponse,
PipelineSummaryItem,
TemplateDetail,
TemplateOption,
TemplateScope,
Expand Down Expand Up @@ -103,6 +103,28 @@ export const getPipelineStatus = async (runId: string): Promise<PipelineStatusRe
return data
}

export const getPipelineHistory = async (
questionnaireUuid: string,
): Promise<PipelineSummaryItem[]> => {
const url = `${getApiBaseUrl()}/pipelines?questionnaireUuid=${encodeURIComponent(questionnaireUuid)}`
const response = await apiFetch(url)
const data = await readApiResponse<PipelineSummaryItem[] | { detail?: string }>(response, url)

if (!response.ok) {
throw new Error(
'detail' in data && data.detail
? data.detail
: 'Failed to load the generation history.',
)
}

if (!Array.isArray(data)) {
throw new Error('Invalid generation history returned.')
}

return data
}

type RunPipelineParams = {
questionnaireUuid: string
templateUuid: string
Expand All @@ -119,7 +141,7 @@ export const runPipeline = async ({
llmApiKey = null,
llmApiUrl = null,
llmMaxWorkers = null,
}: RunPipelineParams): Promise<PipelineRunResponse> => {
}: RunPipelineParams): Promise<PipelineStatusResponse> => {
const url = `${getApiBaseUrl()}/pipelines/run`
const response = await apiFetch(url, {
method: 'POST',
Expand All @@ -136,7 +158,7 @@ export const runPipeline = async ({
}),
})

const data = await readApiResponse<PipelineRunResponse | { detail?: unknown }>(response, url)
const data = await readApiResponse<PipelineStatusResponse | { detail?: unknown }>(response, url)

if (!response.ok) {
if (response.status == 422) {
Expand All @@ -150,7 +172,7 @@ export const runPipeline = async ({
)
}

if (!('runId' in data)) {
if (!isPipelineStatusResponse(data)) {
throw new Error('The backend did not return a pipeline run identifier.')
}

Expand Down
18 changes: 7 additions & 11 deletions plugin/src/components/CustomTemplateSection.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChangeEvent, DragEvent, useEffect, useRef, useState } from 'react'
import { toast } from 'sonner'
Comment thread
MatejFrnka marked this conversation as resolved.

import { createTemplate, updateTemplate } from '@/client'
import styles from '@/components/CustomTemplateSection.module.css'
import { FeedbackAlert } from '@/components/FeedbackAlert'
import { TemplateStructureEditor } from '@/components/TemplateStructureEditor'
import type { ApiTemplateContent, TemplateOption, TemplateScope } from '@/types'

Expand Down Expand Up @@ -34,7 +34,6 @@ export function CustomTemplateSection({
editingTemplate ? JSON.stringify(editingTemplate.content, null, 2) : '',
)
const [fileName, setFileName] = useState('')
const [error, setError] = useState<string | null>(null)
const [isSaving, setIsSaving] = useState(false)
const [inputMode, setInputMode] = useState<'visual' | 'file'>('visual')
const [isDraggingFile, setIsDraggingFile] = useState(false)
Expand All @@ -46,7 +45,6 @@ export function CustomTemplateSection({
setTitle(editingTemplate?.title ?? '')
setJson(editingTemplate ? JSON.stringify(editingTemplate.content, null, 2) : '')
setFileName('')
setError(null)
setInputMode('visual')
}, [editingTemplate])

Expand All @@ -58,9 +56,8 @@ export function CustomTemplateSection({
if (!title.trim()) {
setTitle(file.name.replace(/\.json$/i, ''))
}
setError(null)
} catch {
setError('Failed to read the selected JSON file.')
toast.error('Failed to read the selected JSON file.')
}
}

Expand Down Expand Up @@ -114,12 +111,12 @@ export function CustomTemplateSection({
const trimmedJson = json.trim()

if (!trimmedTitle) {
setError('Enter a template title.')
toast.error('Enter a template title.')
return
}

if (!trimmedJson) {
setError('Insert or upload template JSON.')
toast.error('Insert or upload template JSON.')
return
}

Expand Down Expand Up @@ -147,10 +144,11 @@ export function CustomTemplateSection({
setJson('')
setFileName('')
}
setError(null)
onSaved(data)
} catch (saveError) {
setError(saveError instanceof Error ? saveError.message : 'Template JSON is not valid.')
toast.error(
saveError instanceof Error ? saveError.message : 'Template JSON is not valid.',
)
} finally {
setIsSaving(false)
}
Expand Down Expand Up @@ -265,8 +263,6 @@ export function CustomTemplateSection({
</button>
) : null}
</div>

{error ? <FeedbackAlert kind="error">{error}</FeedbackAlert> : null}
</section>
)
}
Loading