@moguiyu/dsh-tavily 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +18 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +434 -0
- package/package.json +58 -0
- package/src/client.js +438 -0
- package/src/index.js +541 -0
- package/src/invariant.js +18 -0
- package/src/lib.js +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 moguiyu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @moguiyu/dsh-tool-tavily-search
|
|
2
|
+
|
|
3
|
+
Registers the `tavily_search` model tool and the **Tavily Search** settings card for the
|
|
4
|
+
DeepSeek Harness web UI.
|
|
5
|
+
|
|
6
|
+
- **`tavily_search`** — full Tavily surface (`max_results`, `search_depth`, `topic`, `days`,
|
|
7
|
+
`include_answer`, `include_raw_content`, `include_domains`, `exclude_domains`). Keys are
|
|
8
|
+
resolved from the `TAVILY_API_KEYS` credential on every call; round-robin rotation with
|
|
9
|
+
failover on HTTP 401/429.
|
|
10
|
+
- **Settings card** (`settings.plugin.item`, id `tavily-search`) — expandable card matching
|
|
11
|
+
the native plugin-config design: flat key list (masked values, saved dates, show/edit/delete
|
|
12
|
+
icons), key-usage strategy selector, usage gauge, and the on/off switch for the `web`
|
|
13
|
+
provider.
|
|
14
|
+
|
|
15
|
+
Host half: plain ESM (`src/index.js`). Client half: prebuilt `window.__ModuleLoader__` bundle
|
|
16
|
+
at `lib/client.js`, generated from `src/client.js` via `pnpm build`.
|
|
17
|
+
|
|
18
|
+
See the [workspace README](../../README.md) for install and configuration.
|
package/cordis.patch.yml
ADDED
package/lib/client.js
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@moguiyu/dsh-tavily",
|
|
3
|
+
factory: function factory(require) {
|
|
4
|
+
const react = require('react')
|
|
5
|
+
const _primitives = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
6
|
+
|
|
7
|
+
const inject = ['slots']
|
|
8
|
+
|
|
9
|
+
const STRATEGIES = [
|
|
10
|
+
{ id: 'rotate', label: 'Rotate each key', hint: 'Keys are tried in turn (round-robin); on 401/429 the next key is used.' },
|
|
11
|
+
{ id: 'low-usage-first', label: 'Lowest usage first', hint: 'On save, keys are re-ordered by current Tavily usage (least used first).' },
|
|
12
|
+
{ id: 'high-usage-first', label: 'Highest usage first', hint: 'On save, keys are re-ordered by current Tavily usage (most used first).' }
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
const ICONS = {
|
|
16
|
+
eye: ['M1.5 8C1.5 8 4 3.5 8 3.5S14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8Z', 'M8 5.8a2.2 2.2 0 1 0 0 4.4 2.2 2.2 0 0 0 0-4.4Z'],
|
|
17
|
+
eyeOff: ['M1.5 8C1.5 8 4 3.5 8 3.5c1.6 0 3 .5 4.1 1.2', 'M14.5 8C14.5 8 12 12.5 8 12.5c-1.6 0-3-.5-4.1-1.2', 'M2 2l12 12', 'M8 5.8a2.2 2.2 0 0 1 2.2 2.2'],
|
|
18
|
+
pencil: ['M11.2 2.3l2.5 2.5L6 12.5l-3.3.8.8-3.3 7.7-7.7Z', 'M9.5 4l2.5 2.5'],
|
|
19
|
+
trash: ['M2.5 4h11', 'M6.2 4V2.8h3.6V4', 'M4.2 4l.7 9.2h6.2L11.8 4', 'M6.5 6.5v4.2', 'M9.5 6.5v4.2'],
|
|
20
|
+
check: ['M3 8.5l3.5 3.5L13 5'],
|
|
21
|
+
close: ['M4 4l8 8', 'M12 4l-8 8'],
|
|
22
|
+
restore: ['M8 3a5 5 0 1 0 4.9 4', 'M13.4 1.8V5H10']
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const btn = { height: 28, borderRadius: 14, border: '1px solid var(--dsw-alias-border-l2)', background: 'var(--dsw-alias-bg-layer-1)', color: 'var(--dsw-alias-label-primary)', padding: '0 10px', cursor: 'pointer', fontSize: 12 }
|
|
26
|
+
const inputStyle = { boxSizing: 'border-box', border: '1px solid var(--dsw-alias-border-l2)', width: '100%', background: 'var(--dsw-alias-bg-layer-1)', color: 'var(--dsw-alias-label-primary)', borderRadius: 8, padding: '8px 10px', fontSize: 13, fontFamily: 'var(--ds-font-family-code, monospace)' }
|
|
27
|
+
|
|
28
|
+
function formatDate(iso) {
|
|
29
|
+
if (!iso) return '—'
|
|
30
|
+
const d = new Date(iso)
|
|
31
|
+
if (isNaN(d.getTime())) return '—'
|
|
32
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
33
|
+
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate())
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function SvgIcon({ name, size, style }) {
|
|
37
|
+
const paths = ICONS[name] || []
|
|
38
|
+
return react.createElement('svg', { width: size || 14, height: size || 14, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true', style: style },
|
|
39
|
+
paths.map((d, index) => react.createElement('path', { key: index, d: d }))
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function IconButton({ icon, title, onClick, disabled, danger, className }) {
|
|
44
|
+
return react.createElement('button', {
|
|
45
|
+
type: 'button',
|
|
46
|
+
title: title,
|
|
47
|
+
'aria-label': title,
|
|
48
|
+
disabled: disabled,
|
|
49
|
+
onClick: onClick,
|
|
50
|
+
className: className || 'dts-icon-btn',
|
|
51
|
+
style: { width: 26, height: 26, borderRadius: 6, border: 'none', background: 'transparent', color: danger ? 'var(--dsw-alias-state-error-primary)' : 'var(--dsw-alias-label-tertiary)', cursor: 'pointer', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', padding: 0, flex: 'none' }
|
|
52
|
+
}, react.createElement(SvgIcon, { name: icon, size: 13 }))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function Switch({ checked, disabled, label, onChange }) {
|
|
56
|
+
return react.createElement('button', {
|
|
57
|
+
type: 'button',
|
|
58
|
+
role: 'switch',
|
|
59
|
+
'aria-checked': checked === true,
|
|
60
|
+
'aria-label': label,
|
|
61
|
+
disabled: disabled || checked === null,
|
|
62
|
+
onClick: onChange,
|
|
63
|
+
style: { width: 36, height: 20, borderRadius: 10, border: '1px solid var(--dsw-alias-border-l2)', background: checked === true ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-bg-layer-1)', cursor: 'pointer', padding: 0, position: 'relative', flex: 'none', opacity: disabled ? 0.5 : 1 }
|
|
64
|
+
}, react.createElement('span', { style: { position: 'absolute', top: 2, left: checked === true ? 18 : 2, width: 14, height: 14, borderRadius: 7, background: '#fff', transition: 'left .12s ease' } }))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function UsageCircle({ percent, size, label }) {
|
|
68
|
+
const radius = 15
|
|
69
|
+
const circumference = 2 * Math.PI * radius
|
|
70
|
+
const pct = percent != null ? Math.min(100, Math.max(0, percent)) : 0
|
|
71
|
+
const warn = pct > 85
|
|
72
|
+
const dim = size || 44
|
|
73
|
+
return react.createElement('div', { style: { position: 'relative', width: dim, height: dim, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' } },
|
|
74
|
+
react.createElement('svg', { width: dim, height: dim, viewBox: '0 0 40 40' },
|
|
75
|
+
react.createElement('circle', { cx: 20, cy: 20, r: radius, fill: 'none', stroke: 'var(--dsw-alias-border-l2)', strokeWidth: 4 }),
|
|
76
|
+
react.createElement('circle', { cx: 20, cy: 20, r: radius, fill: 'none', stroke: warn ? 'var(--dsw-alias-state-error-primary)' : 'var(--dsw-alias-brand-primary)', strokeWidth: 4, strokeLinecap: 'round', strokeDasharray: circumference, strokeDashoffset: circumference - (pct / 100) * circumference, transform: 'rotate(-90 20 20)' })
|
|
77
|
+
),
|
|
78
|
+
react.createElement('span', { style: { position: 'absolute', fontSize: 11, fontWeight: 600, color: 'var(--dsw-alias-label-primary)' } }, label != null ? label : (percent != null ? percent + '%' : '—'))
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function TavilyCard() {
|
|
83
|
+
const [enabled, setEnabled] = react.useState(null)
|
|
84
|
+
const [expanded, setExpanded] = react.useState(false)
|
|
85
|
+
const [server, setServer] = react.useState(null)
|
|
86
|
+
const [loadError, setLoadError] = react.useState(null)
|
|
87
|
+
const [strategy, setStrategy] = react.useState('rotate')
|
|
88
|
+
const [removing, setRemoving] = react.useState({})
|
|
89
|
+
const [replacing, setReplacing] = react.useState({})
|
|
90
|
+
const [replaceDrafts, setReplaceDrafts] = react.useState({})
|
|
91
|
+
const [adds, setAdds] = react.useState([])
|
|
92
|
+
const [revealed, setRevealed] = react.useState({})
|
|
93
|
+
const [confirm, setConfirm] = react.useState({})
|
|
94
|
+
const [busy, setBusy] = react.useState(false)
|
|
95
|
+
const [notice, setNotice] = react.useState(null)
|
|
96
|
+
const [usage, setUsage] = react.useState(null)
|
|
97
|
+
const [usageError, setUsageError] = react.useState(null)
|
|
98
|
+
|
|
99
|
+
const refresh = react.useCallback(async () => {
|
|
100
|
+
try {
|
|
101
|
+
const response = await fetch('/api/tavily-toggle', { cache: 'no-store' })
|
|
102
|
+
const data = await response.json()
|
|
103
|
+
if (data.ok) { setEnabled(data.enabled); setLoadError(null) } else { setLoadError(data.error || 'Failed to load settings') }
|
|
104
|
+
} catch (error) {
|
|
105
|
+
setLoadError(String(error && error.message ? error.message : error))
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const response = await fetch('/api/tavily-manager', { cache: 'no-store' })
|
|
109
|
+
const data = await response.json()
|
|
110
|
+
if (data.ok) { setServer(data); setStrategy(data.strategy) } else { setLoadError(data.error || 'Failed to load keys') }
|
|
111
|
+
} catch (error) {
|
|
112
|
+
setLoadError(String(error && error.message ? error.message : error))
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const response = await fetch('/api/tavily-usage', { cache: 'no-store' })
|
|
116
|
+
const data = await response.json()
|
|
117
|
+
setUsage(data)
|
|
118
|
+
setUsageError(null)
|
|
119
|
+
} catch (error) {
|
|
120
|
+
setUsageError(String(error && error.message ? error.message : error))
|
|
121
|
+
}
|
|
122
|
+
}, [])
|
|
123
|
+
|
|
124
|
+
react.useEffect(() => { refresh() }, [refresh])
|
|
125
|
+
|
|
126
|
+
const toggleEnabled = async () => {
|
|
127
|
+
const next = enabled !== true
|
|
128
|
+
setBusy(true)
|
|
129
|
+
setNotice(null)
|
|
130
|
+
try {
|
|
131
|
+
const response = await fetch('/api/tavily-toggle', {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
headers: { 'content-type': 'application/json' },
|
|
134
|
+
body: JSON.stringify({ enabled: next })
|
|
135
|
+
})
|
|
136
|
+
const data = await response.json()
|
|
137
|
+
if (!data.ok) { setNotice({ error: data.error || 'Switch failed' }); return }
|
|
138
|
+
setEnabled(data.enabled)
|
|
139
|
+
setNotice({ ok: data.enabled ? 'Tavily search enabled — web_search uses Tavily.' : 'Tavily search off — web_search uses the native provider (DeepSeek). No Tavily key is needed.' })
|
|
140
|
+
} catch (error) {
|
|
141
|
+
setNotice({ error: String(error && error.message ? error.message : error) })
|
|
142
|
+
} finally {
|
|
143
|
+
setBusy(false)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const hasPending = Object.values(removing).some(Boolean)
|
|
148
|
+
|| Object.values(replacing).some(Boolean)
|
|
149
|
+
|| adds.some((item) => item.value.trim().length > 0)
|
|
150
|
+
|
|
151
|
+
const saveStrategy = async (next) => {
|
|
152
|
+
setBusy(true)
|
|
153
|
+
setNotice(null)
|
|
154
|
+
try {
|
|
155
|
+
const response = await fetch('/api/tavily-manager', {
|
|
156
|
+
method: 'POST',
|
|
157
|
+
headers: { 'content-type': 'application/json' },
|
|
158
|
+
body: JSON.stringify({ add: [], remove: [], strategy: next })
|
|
159
|
+
})
|
|
160
|
+
const data = await response.json()
|
|
161
|
+
if (!data.ok) { setNotice({ error: data.error || 'Strategy save failed' }); return }
|
|
162
|
+
setNotice({ ok: 'Strategy saved — effective on the next search.' })
|
|
163
|
+
await refresh()
|
|
164
|
+
} catch (error) {
|
|
165
|
+
setNotice({ error: String(error && error.message ? error.message : error) })
|
|
166
|
+
} finally {
|
|
167
|
+
setBusy(false)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const save = async () => {
|
|
172
|
+
setBusy(true)
|
|
173
|
+
setNotice(null)
|
|
174
|
+
try {
|
|
175
|
+
const addValues = adds.map((item) => item.value.trim()).filter((value) => value.length > 0)
|
|
176
|
+
const removeMasked = [
|
|
177
|
+
...Object.keys(removing).filter((masked) => removing[masked] === true),
|
|
178
|
+
...Object.keys(replacing).filter((masked) => replacing[masked] === true)
|
|
179
|
+
]
|
|
180
|
+
const response = await fetch('/api/tavily-manager', {
|
|
181
|
+
method: 'POST',
|
|
182
|
+
headers: { 'content-type': 'application/json' },
|
|
183
|
+
body: JSON.stringify({ add: addValues, remove: removeMasked, strategy })
|
|
184
|
+
})
|
|
185
|
+
const data = await response.json()
|
|
186
|
+
if (!data.ok) { setNotice({ error: data.error || 'Save failed' }); return }
|
|
187
|
+
setNotice({ ok: 'Saved — effective on the next search.' })
|
|
188
|
+
setRemoving({})
|
|
189
|
+
setReplacing({})
|
|
190
|
+
setReplaceDrafts({})
|
|
191
|
+
setAdds([])
|
|
192
|
+
setRevealed({})
|
|
193
|
+
setConfirm({})
|
|
194
|
+
await refresh()
|
|
195
|
+
} catch (error) {
|
|
196
|
+
setNotice({ error: String(error && error.message ? error.message : error) })
|
|
197
|
+
} finally {
|
|
198
|
+
setBusy(false)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const toggleReveal = async (masked) => {
|
|
203
|
+
if (typeof revealed[masked] === 'string') {
|
|
204
|
+
setRevealed((current) => Object.assign({}, current, { [masked]: false }))
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
setBusy(true)
|
|
208
|
+
setNotice(null)
|
|
209
|
+
try {
|
|
210
|
+
const response = await fetch('/api/tavily-manager?reveal=' + encodeURIComponent(masked), { cache: 'no-store' })
|
|
211
|
+
const data = await response.json()
|
|
212
|
+
if (data.ok) setRevealed((current) => Object.assign({}, current, { [masked]: data.value }))
|
|
213
|
+
else setNotice({ error: data.error || 'Failed to reveal key' })
|
|
214
|
+
} catch (error) {
|
|
215
|
+
setNotice({ error: String(error && error.message ? error.message : error) })
|
|
216
|
+
} finally {
|
|
217
|
+
setBusy(false)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const markRemoved = (masked) => {
|
|
222
|
+
if (confirm[masked] !== true) {
|
|
223
|
+
setConfirm((current) => Object.assign({}, current, { [masked]: true }))
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
setConfirm((current) => Object.assign({}, current, { [masked]: false }))
|
|
227
|
+
setRemoving((current) => Object.assign({}, current, { [masked]: true }))
|
|
228
|
+
setRevealed((current) => Object.assign({}, current, { [masked]: false }))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const restore = (masked) => {
|
|
232
|
+
setRemoving((current) => Object.assign({}, current, { [masked]: false }))
|
|
233
|
+
setConfirm((current) => Object.assign({}, current, { [masked]: false }))
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const startReplace = (masked) => {
|
|
237
|
+
setReplacing((current) => Object.assign({}, current, { [masked]: true }))
|
|
238
|
+
setReplaceDrafts((current) => Object.assign({}, current, { [masked]: '' }))
|
|
239
|
+
setNotice(null)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const cancelReplace = (masked) => {
|
|
243
|
+
setReplacing((current) => Object.assign({}, current, { [masked]: false }))
|
|
244
|
+
setReplaceDrafts((current) => Object.assign({}, current, { [masked]: '' }))
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const headStyle = { textAlign: 'left', padding: '6px 8px', borderBottom: '1px solid var(--dsw-alias-border-l2)', fontSize: 12, color: 'var(--dsw-alias-label-tertiary)' }
|
|
248
|
+
const cellStyle = { padding: '8px', verticalAlign: 'top' }
|
|
249
|
+
|
|
250
|
+
const isOff = enabled === false
|
|
251
|
+
|
|
252
|
+
return react.createElement('div', { style: { border: '1px solid var(--dsw-alias-border-l2)', borderRadius: 10, minWidth: 0, overflow: 'hidden' } },
|
|
253
|
+
react.createElement('style', null, '.dts-icon-btn:hover{background:var(--dsw-alias-interactive-bg-hover)}.dts-icon-btn:disabled{opacity:.4;cursor:default}.dts-icon-btn-danger:hover{background:var(--dsw-alias-interactive-bg-hover-danger)}'),
|
|
254
|
+
react.createElement('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 12, padding: '12px 14px', minHeight: 52, boxSizing: 'border-box' } },
|
|
255
|
+
react.createElement('button', {
|
|
256
|
+
type: 'button',
|
|
257
|
+
'aria-expanded': expanded,
|
|
258
|
+
onClick: () => setExpanded((current) => !current),
|
|
259
|
+
style: { flex: 1, minWidth: 0, textAlign: 'left', background: 'none', border: 'none', padding: 0, cursor: 'pointer', display: 'flex', flexDirection: 'column', gap: 2, font: 'inherit', color: 'inherit' }
|
|
260
|
+
},
|
|
261
|
+
react.createElement('strong', { style: { fontSize: 14, fontWeight: 600, lineHeight: '20px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, 'Tavily Search'),
|
|
262
|
+
react.createElement('span', { style: { fontSize: 12, lineHeight: '16px', color: 'var(--dsw-alias-label-tertiary)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, 'Tavily-backed web_search · key rotation · usage')
|
|
263
|
+
),
|
|
264
|
+
react.createElement('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 6, flex: 'none' } },
|
|
265
|
+
react.createElement(Switch, { checked: enabled, disabled: busy, label: 'Tavily search enabled', onChange: toggleEnabled }),
|
|
266
|
+
react.createElement('button', {
|
|
267
|
+
type: 'button',
|
|
268
|
+
className: 'dts-icon-btn',
|
|
269
|
+
title: expanded ? 'Collapse' : 'Expand',
|
|
270
|
+
'aria-label': expanded ? 'Collapse' : 'Expand',
|
|
271
|
+
onClick: () => setExpanded((current) => !current),
|
|
272
|
+
style: { width: 26, height: 26, borderRadius: 6, border: 'none', background: 'transparent', color: 'var(--dsw-alias-label-tertiary)', cursor: 'pointer', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', padding: 0 }
|
|
273
|
+
},
|
|
274
|
+
react.createElement('span', { style: { display: 'inline-flex', transform: expanded ? 'rotate(180deg)' : undefined, transition: 'transform .14s var(--ds-ease-in-out)' } },
|
|
275
|
+
react.createElement(_primitives.IconChevronDownOutline14, { size: 12, 'aria-hidden': 'true' })
|
|
276
|
+
)
|
|
277
|
+
)
|
|
278
|
+
)
|
|
279
|
+
),
|
|
280
|
+
expanded && react.createElement('div', { style: { borderTop: '1px solid var(--dsw-alias-border-l2)', padding: '12px 14px', display: 'flex', flexDirection: 'column', gap: 16 } },
|
|
281
|
+
isOff
|
|
282
|
+
? react.createElement('p', { style: { margin: 0, fontSize: 13, color: 'var(--dsw-alias-label-tertiary)' } },
|
|
283
|
+
'Tavily search is off — web_search uses the native provider (DeepSeek). No Tavily key is needed.'
|
|
284
|
+
)
|
|
285
|
+
: react.createElement(react.Fragment, null,
|
|
286
|
+
react.createElement('p', { style: { margin: 0, fontSize: 13, color: 'var(--dsw-alias-label-tertiary)' } },
|
|
287
|
+
'All keys are listed below; the key marked with the green dot is the primary key used by web_search. The tavily_search tool uses all keys according to the strategy. Changes take effect on the next search.'
|
|
288
|
+
),
|
|
289
|
+
loadError !== null && react.createElement('p', { style: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-state-error-primary)' } }, String(loadError)),
|
|
290
|
+
react.createElement('table', { style: { width: '100%', borderCollapse: 'collapse', fontSize: 13 } },
|
|
291
|
+
react.createElement('thead', null,
|
|
292
|
+
react.createElement('tr', null,
|
|
293
|
+
react.createElement('th', { style: headStyle }, 'Key'),
|
|
294
|
+
react.createElement('th', { style: headStyle }, 'Saved'),
|
|
295
|
+
react.createElement('th', { style: headStyle }, 'Actions')
|
|
296
|
+
)
|
|
297
|
+
),
|
|
298
|
+
react.createElement('tbody', null,
|
|
299
|
+
(server !== null ? server.keys : []).map((key) => {
|
|
300
|
+
const masked = key.masked
|
|
301
|
+
const isRemoved = removing[masked] === true
|
|
302
|
+
const isReplacing = replacing[masked] === true
|
|
303
|
+
const isRevealed = typeof revealed[masked] === 'string'
|
|
304
|
+
return react.createElement('tr', { key: masked, style: { borderBottom: '1px solid var(--dsw-alias-border-l2)', opacity: isRemoved ? 0.45 : 1 } },
|
|
305
|
+
react.createElement('td', { style: Object.assign({}, cellStyle, { fontFamily: 'var(--ds-font-family-code, monospace)', fontSize: 12, wordBreak: 'break-all' }) },
|
|
306
|
+
isReplacing
|
|
307
|
+
? react.createElement('textarea', {
|
|
308
|
+
style: Object.assign({}, inputStyle, { minHeight: 32, resize: 'vertical' }),
|
|
309
|
+
placeholder: 'New key value (leave blank to keep)',
|
|
310
|
+
value: replaceDrafts[masked] || '',
|
|
311
|
+
onChange: (event) => setReplaceDrafts((current) => Object.assign({}, current, { [masked]: event.target.value })),
|
|
312
|
+
disabled: busy
|
|
313
|
+
})
|
|
314
|
+
: react.createElement('span', null,
|
|
315
|
+
isRevealed ? revealed[masked] : masked,
|
|
316
|
+
key.primary === true && !isRemoved && react.createElement('span', {
|
|
317
|
+
title: 'Primary — used by web_search',
|
|
318
|
+
style: { display: 'inline-block', width: 8, height: 8, borderRadius: 4, background: 'var(--dsw-alias-state-success-primary)', marginLeft: 8, verticalAlign: 'middle', flex: 'none' }
|
|
319
|
+
})
|
|
320
|
+
)
|
|
321
|
+
),
|
|
322
|
+
react.createElement('td', { style: Object.assign({}, cellStyle, { color: 'var(--dsw-alias-label-tertiary)', whiteSpace: 'nowrap' }) }, formatDate(key.savedAt)),
|
|
323
|
+
react.createElement('td', { style: cellStyle },
|
|
324
|
+
isReplacing
|
|
325
|
+
? react.createElement('span', { style: { display: 'inline-flex', gap: 2 } },
|
|
326
|
+
react.createElement(IconButton, { icon: 'check', title: 'Keep', onClick: () => { setReplacing((current) => Object.assign({}, current, { [masked]: false })) }, disabled: busy }),
|
|
327
|
+
react.createElement(IconButton, { icon: 'close', title: 'Cancel', onClick: () => cancelReplace(masked), disabled: busy })
|
|
328
|
+
)
|
|
329
|
+
: react.createElement('span', { style: { display: 'inline-flex', gap: 2 } },
|
|
330
|
+
!isRemoved && react.createElement(IconButton, { icon: isRevealed ? 'eyeOff' : 'eye', title: isRevealed ? 'Hide key' : 'Show key', onClick: () => toggleReveal(masked), disabled: busy }),
|
|
331
|
+
!isRemoved && react.createElement(IconButton, { icon: 'pencil', title: 'Edit', onClick: () => startReplace(masked), disabled: busy }),
|
|
332
|
+
react.createElement(IconButton, {
|
|
333
|
+
icon: isRemoved ? 'restore' : (confirm[masked] === true ? 'check' : 'trash'),
|
|
334
|
+
title: isRemoved ? 'Restore' : (confirm[masked] === true ? 'Click again to confirm' : 'Delete'),
|
|
335
|
+
danger: !isRemoved,
|
|
336
|
+
className: isRemoved ? 'dts-icon-btn' : 'dts-icon-btn dts-icon-btn-danger',
|
|
337
|
+
onClick: () => isRemoved ? restore(masked) : markRemoved(masked),
|
|
338
|
+
disabled: busy
|
|
339
|
+
})
|
|
340
|
+
)
|
|
341
|
+
)
|
|
342
|
+
)
|
|
343
|
+
}),
|
|
344
|
+
adds.map((item) => react.createElement('tr', { key: item.id, style: { borderBottom: '1px solid var(--dsw-alias-border-l2)' } },
|
|
345
|
+
react.createElement('td', { style: cellStyle },
|
|
346
|
+
react.createElement('input', {
|
|
347
|
+
style: inputStyle,
|
|
348
|
+
placeholder: 'New key value',
|
|
349
|
+
value: item.value,
|
|
350
|
+
onChange: (event) => setAdds((current) => current.map((entry) => entry.id === item.id ? Object.assign({}, entry, { value: event.target.value }) : entry)),
|
|
351
|
+
disabled: busy
|
|
352
|
+
})
|
|
353
|
+
),
|
|
354
|
+
react.createElement('td', { style: cellStyle }, '—'),
|
|
355
|
+
react.createElement('td', { style: cellStyle },
|
|
356
|
+
react.createElement(IconButton, { icon: 'trash', title: 'Remove', danger: true, onClick: () => setAdds((current) => current.filter((entry) => entry.id !== item.id)), disabled: busy })
|
|
357
|
+
)
|
|
358
|
+
))
|
|
359
|
+
)
|
|
360
|
+
),
|
|
361
|
+
react.createElement('div', { style: { display: 'flex', gap: 8, alignItems: 'center' } },
|
|
362
|
+
react.createElement('button', { type: 'button', style: btn, onClick: () => setAdds((current) => [...current, { id: 'add-' + Date.now() + '-' + Math.random().toString(36).slice(2, 7), value: '' }]), disabled: busy }, '+ Add key')
|
|
363
|
+
),
|
|
364
|
+
react.createElement('div', { style: { border: '1px solid var(--dsw-alias-border-l2)', borderRadius: 12, padding: '12px 14px', display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
365
|
+
react.createElement('label', { style: { fontWeight: 500, fontSize: 13 } }, 'Key usage strategy'),
|
|
366
|
+
react.createElement('select', {
|
|
367
|
+
style: { maxWidth: 280, height: 32, border: '1px solid var(--dsw-alias-border-l2)', borderRadius: 8, background: 'var(--dsw-alias-bg-layer-1)', color: 'var(--dsw-alias-label-primary)', padding: '0 10px', fontSize: 13 },
|
|
368
|
+
value: strategy,
|
|
369
|
+
onChange: (event) => saveStrategy(event.target.value),
|
|
370
|
+
disabled: busy
|
|
371
|
+
}, STRATEGIES.map((option) => react.createElement('option', { key: option.id, value: option.id }, option.label))),
|
|
372
|
+
react.createElement('p', { style: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-label-tertiary)' } },
|
|
373
|
+
(STRATEGIES.find((option) => option.id === strategy) || STRATEGIES[0]).hint + ' The strategy is saved immediately when you select it; the first key then becomes primary for web_search.'
|
|
374
|
+
)
|
|
375
|
+
),
|
|
376
|
+
react.createElement('div', { style: { display: 'flex', gap: 8, alignItems: 'center' } },
|
|
377
|
+
react.createElement('button', { type: 'button', style: Object.assign({}, btn, { height: 32, background: 'var(--dsw-alias-button-primary-fill)', color: 'var(--dsw-alias-label-primary-foreground)' }), onClick: save, disabled: busy || !hasPending }, 'Save key changes'),
|
|
378
|
+
notice !== null && react.createElement('span', { style: { fontSize: 13, color: notice.ok ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-error-primary)' } }, notice.ok ? notice.ok : String(notice.error))
|
|
379
|
+
),
|
|
380
|
+
react.createElement('div', { style: { border: '1px solid var(--dsw-alias-border-l2)', borderRadius: 12, padding: '12px 14px', display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
381
|
+
react.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 8, justifyContent: 'space-between' } },
|
|
382
|
+
react.createElement('span', { style: { fontWeight: 500, fontSize: 13 } }, 'Tavily Usage'),
|
|
383
|
+
react.createElement('button', { type: 'button', style: btn, onClick: refresh, disabled: busy }, 'Refresh')
|
|
384
|
+
),
|
|
385
|
+
usageError !== null && react.createElement('p', { style: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-state-error-primary)' } }, String(usageError)),
|
|
386
|
+
usage !== null && usage.ok === false && react.createElement('p', { style: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-state-error-primary)' } }, String(usage.error)),
|
|
387
|
+
usage !== null && usage.ok === true && react.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
388
|
+
react.createElement('div', { style: { fontSize: 13 } },
|
|
389
|
+
usage.totals.keys + ' key(s) (' + usage.totals.okKeys + ' readable)' + (usage.totals.planLimit !== null ? ' · plan usage ' + usage.totals.planUsage + ' / ' + usage.totals.planLimit : '')
|
|
390
|
+
),
|
|
391
|
+
react.createElement('table', { style: { width: '100%', borderCollapse: 'collapse', fontSize: 13 } },
|
|
392
|
+
react.createElement('thead', null,
|
|
393
|
+
react.createElement('tr', null,
|
|
394
|
+
react.createElement('th', { style: headStyle }, 'API Key'),
|
|
395
|
+
react.createElement('th', { style: headStyle }, 'Usage')
|
|
396
|
+
)
|
|
397
|
+
),
|
|
398
|
+
react.createElement('tbody', null,
|
|
399
|
+
(server !== null ? server.keys : []).map((key, index) => {
|
|
400
|
+
const row = usage.perKey[index]
|
|
401
|
+
const pct = row && row.ok && row.planLimit != null && row.planLimit > 0 && row.planUsage != null
|
|
402
|
+
? Math.min(100, Math.round((row.planUsage / row.planLimit) * 100))
|
|
403
|
+
: null
|
|
404
|
+
return react.createElement('tr', { key: key.masked, style: { borderBottom: '1px solid var(--dsw-alias-border-l2)' } },
|
|
405
|
+
react.createElement('td', { style: Object.assign({}, cellStyle, { fontFamily: 'var(--ds-font-family-code, monospace)', fontSize: 12, wordBreak: 'break-all' }) }, key.masked),
|
|
406
|
+
react.createElement('td', { style: cellStyle },
|
|
407
|
+
react.createElement(UsageCircle, { percent: pct, label: pct != null ? pct + '%' : (row && row.ok && row.planUsage != null ? String(row.planUsage) : '—') })
|
|
408
|
+
)
|
|
409
|
+
)
|
|
410
|
+
})
|
|
411
|
+
)
|
|
412
|
+
)
|
|
413
|
+
)
|
|
414
|
+
),
|
|
415
|
+
react.createElement('p', { style: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-label-tertiary)' } },
|
|
416
|
+
'Usage data comes from the Tavily /usage endpoint (fetched locally; no keys are exposed).'
|
|
417
|
+
)
|
|
418
|
+
)
|
|
419
|
+
)
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function apply(ctx) {
|
|
424
|
+
ctx.slots.inject('settings.plugin.item', () => ctx.slots.register({
|
|
425
|
+
name: 'settings.plugin.item',
|
|
426
|
+
id: 'tavily-search',
|
|
427
|
+
order: 30,
|
|
428
|
+
label: 'Tavily Search'
|
|
429
|
+
}, TavilyCard))
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
return { apply, inject }
|
|
433
|
+
}
|
|
434
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moguiyu/dsh-tavily",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Tavily Search for DSH: multiple API keys, rotation/failover, usage gauge, settings card, and web_search toggle in one plugin.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js",
|
|
9
|
+
"./invariant": "./src/invariant.js",
|
|
10
|
+
"./client": "./lib/client.js",
|
|
11
|
+
"./src/*": "./src/*",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"src",
|
|
16
|
+
"lib",
|
|
17
|
+
"cordis.patch.yml",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dsh": {
|
|
26
|
+
"bundle": {
|
|
27
|
+
"patch": "./cordis.patch.yml"
|
|
28
|
+
},
|
|
29
|
+
"client": {
|
|
30
|
+
"platform": "web",
|
|
31
|
+
"inject": [
|
|
32
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
33
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "node scripts/build-client.mjs",
|
|
39
|
+
"test": "node --test"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"deepseek-harness",
|
|
43
|
+
"dsh",
|
|
44
|
+
"dsh-plugin",
|
|
45
|
+
"tavily",
|
|
46
|
+
"web-search",
|
|
47
|
+
"tool"
|
|
48
|
+
],
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "https://github.com/moguiyu/dsh-tavily.git"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
55
|
+
"@deepseek-ai/dsh-home-paths": "^0.1.0-rc.6",
|
|
56
|
+
"@deepseek-ai/dsh-tools": "^0.1.0-rc.6"
|
|
57
|
+
}
|
|
58
|
+
}
|