File size: 7,257 Bytes
8ede856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<template>
    <v-dialog v-model="showDialog" max-width="1100px" min-height="95%">
        <v-card :title="tm('dialogs.addProvider.title')">
            <v-card-text style="overflow-y: auto;">
                <v-tabs v-model="activeProviderTab" grow>
                    <v-tab value="agent_runner" class="font-weight-medium px-3">
                        <v-icon start>mdi-cogs</v-icon>
                        {{ tm('dialogs.addProvider.tabs.agentRunner') }}
                    </v-tab>
                    <v-tab value="speech_to_text" class="font-weight-medium px-3">
                        <v-icon start>mdi-microphone-message</v-icon>
                        {{ tm('dialogs.addProvider.tabs.speechToText') }}
                    </v-tab>
                    <v-tab value="text_to_speech" class="font-weight-medium px-3">
                        <v-icon start>mdi-volume-high</v-icon>
                        {{ tm('dialogs.addProvider.tabs.textToSpeech') }}
                    </v-tab>
                    <v-tab value="embedding" class="font-weight-medium px-3">
                        <v-icon start>mdi-code-json</v-icon>
                        {{ tm('dialogs.addProvider.tabs.embedding') }}
                    </v-tab>
                    <v-tab value="rerank" class="font-weight-medium px-3">
                        <v-icon start>mdi-compare-vertical</v-icon>
                        {{ tm('dialogs.addProvider.tabs.rerank') }}
                    </v-tab>
                </v-tabs>

                <v-window v-model="activeProviderTab" class="mt-4">
                    <v-window-item
                        v-for="tabType in ['chat_completion', 'agent_runner', 'speech_to_text', 'text_to_speech', 'embedding', 'rerank']"
                        :key="tabType" :value="tabType">
                        <v-row class="mt-1">
                            <v-col v-for="(template, name) in getTemplatesByType(tabType)" :key="name" cols="12" sm="6"
                                md="4">
                                <v-card variant="outlined" hover class="provider-card"
                                    @click="selectProviderTemplate(name)">
                                    <div class="provider-card-content">
                                        <div class="provider-card-text">
                                            <v-card-title class="provider-card-title">{{ name }}</v-card-title>
                                            <v-card-text
                                                class="text-caption text-medium-emphasis provider-card-description">
                                                {{ getProviderDescription(template, name) }}
                                            </v-card-text>
                                        </div>
                                        <div class="provider-card-logo">
                                            <img :src="getProviderIcon(template.provider)"
                                                v-if="getProviderIcon(template.provider)" class="provider-logo-img">
                                            <div v-else class="provider-logo-fallback">
                                                {{ name[0].toUpperCase() }}
                                            </div>
                                        </div>
                                    </div>
                                </v-card>
                            </v-col>
                            <v-col v-if="Object.keys(getTemplatesByType(tabType)).length === 0" cols="12">
                                <v-alert type="info" variant="tonal">
                                    {{ tm('dialogs.addProvider.noTemplates') }}
                                </v-alert>
                            </v-col>
                        </v-row>
                    </v-window-item>
                </v-window>
            </v-card-text>
            <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn text @click="closeDialog">{{ tm('dialogs.config.cancel') }}</v-btn>
            </v-card-actions>
        </v-card>
    </v-dialog>
</template>

<script>
import { useModuleI18n } from '@/i18n/composables';
import { getProviderIcon, getProviderDescription } from '@/utils/providerUtils';

export default {
    name: 'AddNewProvider',
    props: {
        show: {
            type: Boolean,
            default: false
        },
        metadata: {
            type: Object,
            default: () => ({})
        }
    },
    emits: ['update:show', 'select-template'],
    setup() {
        const { tm } = useModuleI18n('features/provider');
        return { tm };
    },
    data() {
        return {
            activeProviderTab: 'chat_completion'
        };
    },
    computed: {
        showDialog: {
            get() {
                return this.show;
            },
            set(value) {
                this.$emit('update:show', value);
            }
        },
    },
    methods: {
        closeDialog() {
            this.showDialog = false;
        },

        // 按提供商类型获取模板列表
        getTemplatesByType(type) {
            const templates = this.metadata.provider.config_template || {};
            const filtered = {};

            for (const [name, template] of Object.entries(templates)) {
                if (template.provider_type === type) {
                    filtered[name] = template;
                }
            }

            return filtered;
        },

        // 从工具函数导入
        getProviderIcon,

        // 获取提供商简介
        getProviderDescription(template, name) {
            return getProviderDescription(template, name, this.tm);
        },

        // 选择提供商模板
        selectProviderTemplate(name) {
            this.$emit('select-template', name);
            this.closeDialog();
        }
    }
}
</script>

<style scoped>
.provider-card {
    transition: all 0.3s ease;
    height: 100%;
    cursor: pointer;
    overflow: hidden;
    position: relative;
}

.provider-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 25px 0 rgba(0, 0, 0, 0.05);
    border-color: var(--v-primary-base);
}

.provider-card-content {
    display: flex;
    align-items: center;
    height: 100px;
    padding: 16px;
    position: relative;
    z-index: 2;
}

.provider-card-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.provider-card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
    padding: 0;
}

.provider-card-description {
    padding: 0;
    margin: 0;
}

.provider-card-logo {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.provider-logo-img {
    width: 60px;
    height: 60px;
    opacity: 0.6;
    object-fit: contain;
}

.provider-logo-fallback {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--v-primary-base);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    opacity: 0.3;
}
</style>