Вроде работает
This commit is contained in:
@@ -11,10 +11,12 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { runTask } from '../../services/toolsService.js';
|
||||
import { getConnections } from '../../services/connectionService.js';
|
||||
import { api } from '../../lib/api';
|
||||
import { selectedTask } from '../../lib/stores.js';
|
||||
import { addToast } from '../../lib/toasts.js';
|
||||
import { t } from '../../lib/i18n';
|
||||
import { Button, Card, Select, Input } from '../../lib/ui';
|
||||
import DocPreview from '../llm/DocPreview.svelte';
|
||||
// [/SECTION]
|
||||
|
||||
let envs = [];
|
||||
@@ -27,6 +29,8 @@
|
||||
let tableSchema = 'public';
|
||||
let excelPath = '';
|
||||
let isRunning = false;
|
||||
let isGeneratingDocs = false;
|
||||
let generatedDoc = null;
|
||||
|
||||
// [DEF:fetchData:Function]
|
||||
// @PURPOSE: Fetches environments and saved connections.
|
||||
@@ -34,8 +38,7 @@
|
||||
// @POST: envs and connections arrays are populated.
|
||||
async function fetchData() {
|
||||
try {
|
||||
const envsRes = await fetch('/api/environments');
|
||||
envs = await envsRes.json();
|
||||
envs = await api.fetchApi('/environments');
|
||||
connections = await getConnections();
|
||||
} catch (e) {
|
||||
addToast($t.mapper.errors.fetch_failed, 'error');
|
||||
@@ -86,6 +89,53 @@
|
||||
}
|
||||
// [/DEF:handleRunMapper:Function]
|
||||
|
||||
// [DEF:handleGenerateDocs:Function]
|
||||
// @PURPOSE: Triggers the LLM Documentation task.
|
||||
// @PRE: selectedEnv and datasetId are set.
|
||||
// @POST: Documentation task is started.
|
||||
async function handleGenerateDocs() {
|
||||
if (!selectedEnv || !datasetId) {
|
||||
addToast($t.mapper.errors.required_fields, 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
isGeneratingDocs = true;
|
||||
try {
|
||||
// Fetch active provider first
|
||||
const providers = await api.fetchApi('/llm/providers');
|
||||
const activeProvider = providers.find(p => p.is_active);
|
||||
|
||||
if (!activeProvider) {
|
||||
addToast('No active LLM provider found', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const task = await runTask('llm_documentation', {
|
||||
dataset_id: datasetId,
|
||||
environment_id: selectedEnv,
|
||||
provider_id: activeProvider.id
|
||||
});
|
||||
|
||||
selectedTask.set(task);
|
||||
addToast('Documentation generation started', 'success');
|
||||
} catch (e) {
|
||||
addToast(e.message || 'Failed to start documentation generation', 'error');
|
||||
} finally {
|
||||
isGeneratingDocs = false;
|
||||
}
|
||||
}
|
||||
// [/DEF:handleGenerateDocs:Function]
|
||||
|
||||
async function handleApplyDoc(doc) {
|
||||
try {
|
||||
await api.put(`/mappings/datasets/${datasetId}/metadata`, doc);
|
||||
generatedDoc = null;
|
||||
addToast('Documentation applied successfully', 'success');
|
||||
} catch (err) {
|
||||
addToast(err.message || 'Failed to apply documentation', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
onMount(fetchData);
|
||||
</script>
|
||||
|
||||
@@ -167,7 +217,18 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex justify-end pt-2">
|
||||
<div class="flex justify-end pt-2 space-x-3">
|
||||
<Button
|
||||
variant="secondary"
|
||||
on:click={handleGenerateDocs}
|
||||
disabled={isGeneratingDocs || isRunning}
|
||||
>
|
||||
{#if isGeneratingDocs}
|
||||
<span class="animate-spin mr-1">↻</span> Generating...
|
||||
{:else}
|
||||
<span class="mr-1">✨</span> Generate Docs
|
||||
{/if}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
on:click={handleRunMapper}
|
||||
@@ -178,6 +239,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<DocPreview
|
||||
documentation={generatedDoc}
|
||||
onCancel={() => generatedDoc = null}
|
||||
onSave={handleApplyDoc}
|
||||
/>
|
||||
</div>
|
||||
<!-- [/SECTION] -->
|
||||
<!-- [/DEF:MapperTool:Component] -->
|
||||
Reference in New Issue
Block a user