@moguiyu/dsh-tavily 0.1.3 → 0.1.4

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/lib/client.js CHANGED
@@ -168,6 +168,29 @@ window.__ModuleLoader__.load({
168
168
  }
169
169
  }
170
170
 
171
+ const saveAdd = async (item) => {
172
+ const value = item.value.trim()
173
+ if (!value) return
174
+ setBusy(true)
175
+ setNotice(null)
176
+ try {
177
+ const response = await fetch('/api/tavily-manager', {
178
+ method: 'POST',
179
+ headers: { 'content-type': 'application/json' },
180
+ body: JSON.stringify({ add: [value], remove: [], strategy })
181
+ })
182
+ const data = await response.json()
183
+ if (!data.ok) { setNotice({ error: data.error || 'Save failed' }); return }
184
+ setNotice({ ok: 'Key saved.' })
185
+ setAdds((current) => current.filter((entry) => entry.id !== item.id))
186
+ await refresh()
187
+ } catch (error) {
188
+ setNotice({ error: String(error && error.message ? error.message : error) })
189
+ } finally {
190
+ setBusy(false)
191
+ }
192
+ }
193
+
171
194
  const save = async () => {
172
195
  setBusy(true)
173
196
  setNotice(null)
@@ -348,12 +371,16 @@ window.__ModuleLoader__.load({
348
371
  placeholder: 'New key value',
349
372
  value: item.value,
350
373
  onChange: (event) => setAdds((current) => current.map((entry) => entry.id === item.id ? Object.assign({}, entry, { value: event.target.value }) : entry)),
374
+ onKeyDown: (event) => { if (event.key === 'Enter') saveAdd(item) },
351
375
  disabled: busy
352
376
  })
353
377
  ),
354
378
  react.createElement('td', { style: cellStyle }, '—'),
355
379
  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 })
380
+ react.createElement('span', { style: { display: 'inline-flex', gap: 2 } },
381
+ react.createElement(IconButton, { icon: 'check', title: 'Save key', onClick: () => saveAdd(item), disabled: busy || item.value.trim().length === 0 }),
382
+ react.createElement(IconButton, { icon: 'trash', title: 'Remove', danger: true, onClick: () => setAdds((current) => current.filter((entry) => entry.id !== item.id)), disabled: busy })
383
+ )
357
384
  )
358
385
  ))
359
386
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moguiyu/dsh-tavily",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Tavily Search for DSH: multiple API keys, rotation/failover, usage gauge, settings card, and web_search toggle in one plugin.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/client.js CHANGED
@@ -173,6 +173,29 @@ export function factory(require) {
173
173
  }
174
174
  }
175
175
 
176
+ const saveAdd = async (item) => {
177
+ const value = item.value.trim()
178
+ if (!value) return
179
+ setBusy(true)
180
+ setNotice(null)
181
+ try {
182
+ const response = await fetch('/api/tavily-manager', {
183
+ method: 'POST',
184
+ headers: { 'content-type': 'application/json' },
185
+ body: JSON.stringify({ add: [value], remove: [], strategy })
186
+ })
187
+ const data = await response.json()
188
+ if (!data.ok) { setNotice({ error: data.error || 'Save failed' }); return }
189
+ setNotice({ ok: 'Key saved.' })
190
+ setAdds((current) => current.filter((entry) => entry.id !== item.id))
191
+ await refresh()
192
+ } catch (error) {
193
+ setNotice({ error: String(error && error.message ? error.message : error) })
194
+ } finally {
195
+ setBusy(false)
196
+ }
197
+ }
198
+
176
199
  const save = async () => {
177
200
  setBusy(true)
178
201
  setNotice(null)
@@ -353,12 +376,16 @@ export function factory(require) {
353
376
  placeholder: 'New key value',
354
377
  value: item.value,
355
378
  onChange: (event) => setAdds((current) => current.map((entry) => entry.id === item.id ? Object.assign({}, entry, { value: event.target.value }) : entry)),
379
+ onKeyDown: (event) => { if (event.key === 'Enter') saveAdd(item) },
356
380
  disabled: busy
357
381
  })
358
382
  ),
359
383
  react.createElement('td', { style: cellStyle }, '—'),
360
384
  react.createElement('td', { style: cellStyle },
361
- react.createElement(IconButton, { icon: 'trash', title: 'Remove', danger: true, onClick: () => setAdds((current) => current.filter((entry) => entry.id !== item.id)), disabled: busy })
385
+ react.createElement('span', { style: { display: 'inline-flex', gap: 2 } },
386
+ react.createElement(IconButton, { icon: 'check', title: 'Save key', onClick: () => saveAdd(item), disabled: busy || item.value.trim().length === 0 }),
387
+ react.createElement(IconButton, { icon: 'trash', title: 'Remove', danger: true, onClick: () => setAdds((current) => current.filter((entry) => entry.id !== item.id)), disabled: busy })
388
+ )
362
389
  )
363
390
  ))
364
391
  )
package/src/index.js CHANGED
@@ -6,7 +6,7 @@ import { readFileSync, writeFileSync } from 'node:fs'
6
6
  import { join } from 'node:path'
7
7
  import { resolveDshHome } from '@deepseek-ai/dsh-home-paths'
8
8
  import { defineTool } from '@deepseek-ai/dsh-tools'
9
- import { STRATEGIES, maskValue, parseKeyList, orderKeys, readJsonFile } from './lib.js'
9
+ import { STRATEGIES, isValidStrategy, maskValue, parseKeyList, orderKeys, readJsonFile } from './lib.js'
10
10
 
11
11
  export const name = 'dsh-tavily'
12
12