Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | <script setup lang="ts"> import { ref, watch, onMounted } from 'vue' import { ElMessage, ElSelect, ElOption } from 'element-plus' import { listTemplates, getTemplate, type TemplateInfo } from '@/api/python' import ExpressionInput from '@/components/shared/ExpressionInput.vue' interface PythonConfig { code?: string input?: string dependencies?: string[] } interface Props { modelValue: PythonConfig } const props = defineProps<Props>() const emit = defineEmits<{ 'update:modelValue': [value: PythonConfig] }>() const localData = ref<PythonConfig>({}) const dependenciesText = ref('') const templates = ref<TemplateInfo[]>([]) const selectedTemplate = ref<string>('') const loadingTemplates = ref(false) const loadingTemplate = ref(false) watch( () => props.modelValue, (newValue) => { localData.value = { ...newValue } dependenciesText.value = newValue.dependencies?.join('\n') || '' }, { immediate: true } ) const updateData = () => { emit('update:modelValue', { ...localData.value }) } const updateDependencies = () => { const deps = dependenciesText.value .split('\n') .map((line) => line.trim()) .filter((line) => line.length > 0) localData.value.dependencies = deps updateData() } const loadTemplates = async () => { loadingTemplates.value = true try { templates.value = await listTemplates() } catch (error) { console.error('Failed to load templates:', error) } finally { loadingTemplates.value = false } } const loadTemplate = async () => { if (!selectedTemplate.value) return loadingTemplate.value = true try { const template = await getTemplate(selectedTemplate.value) // Parse dependencies from JSON string const dependencies = JSON.parse(template.dependencies) as string[] // Update local data localData.value.code = template.content localData.value.dependencies = dependencies dependenciesText.value = dependencies.join('\n') updateData() ElMessage.success(`Template "${template.name}" loaded successfully`) } catch (error) { console.error('Failed to load template:', error) ElMessage.error('Failed to load template') } finally { loadingTemplate.value = false } } onMounted(() => { loadTemplates() }) </script> <template> <div class="python-config"> <div class="form-group template-selector"> <label>Template (Optional)</label> <div class="template-controls"> <ElSelect v-model="selectedTemplate" placeholder="Choose a template to start" :loading="loadingTemplates" clearable style="flex: 1" > <ElOption v-for="template in templates" :key="template.id" :label="template.name" :value="template.id" > <div class="template-option"> <span class="template-name">{{ template.name }}</span> </div> <div class="template-description">{{ template.description }}</div> </ElOption> </ElSelect> <button type="button" class="load-button" :disabled="!selectedTemplate || loadingTemplate" @click="loadTemplate" > {{ loadingTemplate ? 'Loading...' : 'Load' }} </button> </div> <p class="hint">Start with a LangGraph template or write your own Python script</p> </div> <div class="form-group"> <label>Input Data (JSON)</label> <ExpressionInput :model-value="localData.input || ''" :multiline="true" placeholder='{"data": {{trigger.payload}}, "user": {{node.http1.data.body.user}}}' @update:model-value="(val) => { localData.input = val; updateData(); }" /> <p class="hint">JSON data to pass as stdin to the Python script</p> </div> <div class="form-group"> <label>Python Code</label> <textarea v-model="localData.code" @input="updateData" placeholder="import json import sys input_data = json.load(sys.stdin) result = {'output': 'Hello'} print(json.dumps(result))" rows="12" class="code-textarea" /> <p class="hint">Read JSON input from stdin, output JSON result to stdout</p> </div> <div class="form-group"> <label>Dependencies (one per line)</label> <textarea v-model="dependenciesText" @input="updateDependencies" placeholder="pandas numpy>=1.24.0 requests" rows="4" /> <p class="hint">Format: package_name or package_name>=version</p> </div> </div> </template> <style lang="scss" scoped> .python-config { display: flex; flex-direction: column; gap: var(--rf-spacing-lg); } .form-group { display: flex; flex-direction: column; gap: var(--rf-spacing-xs); label { font-weight: 600; color: var(--rf-color-text-primary); font-size: var(--rf-font-size-sm); } textarea { padding: var(--rf-spacing-sm); border: 1px solid var(--rf-color-border-base); border-radius: var(--rf-radius-base); font-size: var(--rf-font-size-sm); resize: vertical; background: var(--rf-color-bg-container); color: var(--rf-color-text-primary); &.code-textarea { font-family: 'Monaco', 'Menlo', 'Consolas', monospace; font-size: var(--rf-font-size-xs); } &:focus { outline: none; border-color: var(--rf-color-primary); } } .hint { font-size: var(--rf-font-size-xs); color: var(--rf-color-text-secondary); margin: 0; } &.template-selector { .template-controls { display: flex; gap: var(--rf-spacing-sm); align-items: stretch; } .load-button { padding: 0 var(--rf-spacing-lg); background: var(--rf-color-primary); color: white; border: none; border-radius: var(--rf-radius-base); font-size: var(--rf-font-size-sm); font-weight: 500; cursor: pointer; transition: all 0.2s; white-space: nowrap; &:hover:not(:disabled) { background: var(--rf-color-primary-dark); transform: translateY(-1px); } &:disabled { opacity: 0.5; cursor: not-allowed; } } } } .template-option { display: flex; align-items: center; .template-name { font-weight: 500; } } .template-description { font-size: var(--rf-font-size-xs); color: var(--rf-color-text-secondary); margin-top: 2px; } </style> |