@objectivex666/dsh-settings-search 1.12.0 → 1.13.1

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.
@@ -13,6 +13,8 @@ const instrumented = source.replace(hook, `
13
13
  requestUserAi, requestAiKeywords, testAiService, LOGS,
14
14
  modelsUrl, fetchAiModels,
15
15
  readIndexCache, serializeHarvest,
16
+ readDshModelConfig, otherPluginFingerprint, DEEP_SLOTS,
17
+ log, flushLogs, discardPendingLogs, sessionLogText, logTarget, readLogCount,
16
18
  })
17
19
  ${hook}`)
18
20
  const storage = () => {
@@ -321,13 +323,17 @@ for (const cfg of [ollama, openai, anthropic]) {
321
323
  const { api, sandbox, calls } = load(abortedFetch)
322
324
  let expire
323
325
  let cleared = false
326
+ const deadline = cfg.provider === 'ollama' ? 120000 : 12000
327
+ const delays = []
324
328
  sandbox.setTimeout = (callback, ms) => {
325
- assert.equal(ms, cfg.provider === 'ollama' ? 120000 : 12000)
326
- expire = callback
329
+ delays.push(ms)
330
+ // The log batch timer shares this seam, so select the request deadline.
331
+ if (ms === deadline) expire = callback
327
332
  return 1
328
333
  }
329
334
  sandbox.clearTimeout = () => { cleared = true }
330
335
  const result = api.testAiService(cfg)
336
+ assert.ok(delays.includes(deadline), `the request must use a ${deadline}ms deadline, saw ${delays.join('/')}`)
331
337
  expire()
332
338
  assert.equal((await result).code, 'timeout')
333
339
  assert.equal(calls[0].signal.aborted, true)
@@ -377,3 +383,306 @@ test('cache respects settings labels and is invalidated when provider configurat
377
383
  assert.equal(calls.length, 4)
378
384
  assert.equal(calls[3].headers.authorization, `Bearer ${openai.apiKey}`)
379
385
  })
386
+
387
+ // --- DSH default-model import: 0.2 Remote namespaces, the legacy unary client, and failures ---
388
+
389
+ const dshNamespaces = (provider, model, providerProfiles) => ([
390
+ { ns: 'agent-default-model', value: { provider, model, reasoningEffort: 'high' } },
391
+ { ns: 'llm-pi-ai', value: { providers: providerProfiles } },
392
+ ])
393
+ const describeReply = (namespaces) => ({ ok: true, value: { writable: true, hasDocument: true, namespaces } })
394
+
395
+ test('DSH 0.2 remote namespaces supply the default model config without touching credentials', async () => {
396
+ const { api } = load()
397
+ const requested = []
398
+ const ctx = {
399
+ get: (name) => {
400
+ requested.push(name)
401
+ if (name === 'remote.settings') {
402
+ return {
403
+ describe: async () => describeReply(dshNamespaces('openai', 'gpt-x', {
404
+ openai: { api: 'openai-completions', baseURL: 'https://example.test/v1', models: [{ id: 'gpt-x' }] },
405
+ })),
406
+ }
407
+ }
408
+ if (name === 'remote.llm') {
409
+ return {
410
+ listConfigurableProviders: async () => ({
411
+ ok: true,
412
+ value: [{ provider: 'openai', settingsNs: 'llm-pi-ai', settingsPath: ['providers', 'openai'] }],
413
+ }),
414
+ }
415
+ }
416
+ return undefined
417
+ },
418
+ }
419
+ assert.deepEqual(plain(await api.readDshModelConfig(ctx, (key) => key)), {
420
+ provider: 'openai',
421
+ baseUrl: 'https://example.test/v1',
422
+ model: 'gpt-x',
423
+ })
424
+ assert.deepEqual(requested, ['remote.settings', 'remote.llm'])
425
+ })
426
+
427
+ test('the legacy connection.api unary client still supplies the default model config', async () => {
428
+ const { api } = load()
429
+ const ctx = {
430
+ get: (name) => name === 'connection'
431
+ ? {
432
+ api: {
433
+ settings: {
434
+ describe: async (payload) => {
435
+ assert.deepEqual(plain(payload), {})
436
+ return {
437
+ result: {
438
+ ok: true,
439
+ value: {
440
+ namespaces: dshNamespaces('anthropic', 'claude-x', {
441
+ anthropic: { baseURL: 'https://anthropic.test', models: [{ id: 'claude-x', api: 'anthropic-messages' }] },
442
+ }),
443
+ },
444
+ },
445
+ }
446
+ },
447
+ },
448
+ llm: {
449
+ providers: async () => ({
450
+ result: {
451
+ ok: true,
452
+ value: { providers: [{ provider: 'anthropic', settingsNs: 'llm-pi-ai', settingsPath: ['providers', 'anthropic'] }] },
453
+ },
454
+ }),
455
+ },
456
+ },
457
+ }
458
+ : undefined,
459
+ }
460
+ assert.deepEqual(plain(await api.readDshModelConfig(ctx, (key) => key)), {
461
+ provider: 'anthropic',
462
+ baseUrl: 'https://anthropic.test',
463
+ model: 'claude-x',
464
+ })
465
+ })
466
+
467
+ test('a missing llm namespace falls back to the provider profile inside the settings namespace', async () => {
468
+ const { api } = load()
469
+ const ctx = {
470
+ get: (name) => name === 'remote.settings'
471
+ ? {
472
+ describe: async () => describeReply(dshNamespaces('ollama', 'qwen3:8b', {
473
+ ollama: { baseURL: 'http://127.0.0.1:11434/v1', models: [{ id: 'qwen3:8b' }] },
474
+ })),
475
+ }
476
+ : undefined,
477
+ }
478
+ assert.deepEqual(plain(await api.readDshModelConfig(ctx, (key) => key)), {
479
+ provider: 'ollama',
480
+ baseUrl: 'http://127.0.0.1:11434/v1',
481
+ model: 'qwen3:8b',
482
+ })
483
+ })
484
+
485
+ test('a failed describe is reported instead of being mistaken for a missing model', async () => {
486
+ const { api } = load()
487
+ const ctx = {
488
+ get: (name) => name === 'remote.settings'
489
+ ? { describe: async () => ({ ok: false, error: { message: 'settings are read-only' } }) }
490
+ : undefined,
491
+ }
492
+ await assert.rejects(api.readDshModelConfig(ctx, (key) => key), { message: 'settings are read-only' })
493
+ })
494
+
495
+ test('a DSH build with no settings API fails with a readable reason instead of a TypeError', async () => {
496
+ const { api } = load()
497
+ await assert.rejects(api.readDshModelConfig({ get: () => undefined }, (key) => key), { message: 'aiDshImportApi' })
498
+ })
499
+
500
+ // --- DSH default-model import: the built-in DeepSeek route ---
501
+
502
+ /** A ctx whose default model is one route, with whatever namespaces it reads. */
503
+ const dshDefaultModel = (provider, model, { settingsNs, namespaces = [] } = {}) => ({
504
+ get: (name) => name === 'remote.settings'
505
+ ? {
506
+ describe: async () => describeReply([
507
+ { ns: 'agent-default-model', value: { provider, model } },
508
+ ...namespaces,
509
+ ]),
510
+ }
511
+ : name === 'remote.llm'
512
+ ? {
513
+ listConfigurableProviders: async () => ({
514
+ ok: true,
515
+ value: [{ provider, settingsNs, settingsPath: [] }],
516
+ }),
517
+ }
518
+ : undefined,
519
+ })
520
+
521
+ test('a built-in DeepSeek default model imports the adapter\u2019s own endpoint', async () => {
522
+ const { api } = load()
523
+ for (const [provider, settingsNs] of [['deepseek-account', 'llm-deepseek-account'], ['deepseek-official', 'llm-deepseek']]) {
524
+ const ctx = dshDefaultModel(provider, 'deepseek-flash', { settingsNs })
525
+ assert.deepEqual(plain(await api.readDshModelConfig(ctx, (key) => key)), {
526
+ provider: 'anthropic',
527
+ baseUrl: 'https://api.deepseek.com/anthropic',
528
+ model: 'deepseek-flash',
529
+ builtin: true,
530
+ }, `${provider} must fall back to the DeepSeek endpoint`)
531
+ }
532
+ })
533
+
534
+ test('a configured DeepSeek base URL wins over the built-in fallback', async () => {
535
+ const { api } = load()
536
+ const ctx = dshDefaultModel('deepseek-official', 'deepseek-chat', {
537
+ settingsNs: 'llm-deepseek',
538
+ namespaces: [{ ns: 'llm-deepseek', value: { baseURL: 'https://proxy.test/anthropic' } }],
539
+ })
540
+ assert.deepEqual(plain(await api.readDshModelConfig(ctx, (key) => key)), {
541
+ provider: 'anthropic',
542
+ baseUrl: 'https://proxy.test/anthropic',
543
+ model: 'deepseek-chat',
544
+ })
545
+ })
546
+
547
+ test('a third-party route without an importable Base URL still names the model', async () => {
548
+ const { api } = load()
549
+ const ctx = dshDefaultModel('acme-gateway', 'acme-large', {
550
+ settingsNs: 'llm-pi-ai',
551
+ namespaces: [{ ns: 'llm-pi-ai', value: { providers: { 'acme-gateway': { models: [{ id: 'acme-large' }] } } } }],
552
+ })
553
+ await assert.rejects(api.readDshModelConfig(ctx, (key) => key), { message: 'aiDshImportNoBaseUrl' })
554
+ })
555
+
556
+ test('no default model imports nothing', async () => {
557
+ const { api } = load()
558
+ const idle = {
559
+ get: (name) => name === 'remote.settings'
560
+ ? { describe: async () => describeReply([{ ns: 'agent-default-model', value: {} }]) }
561
+ : undefined,
562
+ }
563
+ assert.equal(await api.readDshModelConfig(idle, (key) => key), null)
564
+ })
565
+
566
+ // --- DSH 0.2 adaptation: plugin-inventory fingerprint and in-page seats ---
567
+
568
+ test('the plugin-inventory fingerprint drops this plugin and follows 0.2 bundle/plugin rows', () => {
569
+ const { api } = load()
570
+ const own = { id: '@objectivex666/dsh-settings-search', npm: '@objectivex666/dsh-settings-search', version: '1.13.0' }
571
+ const shell = { id: '@deepseek-ai/dsh-client-ui-shell', npm: '@deepseek-ai/dsh-client-ui-shell', version: '0.2.0-rc.2', enabled: true }
572
+ const baseline = api.otherPluginFingerprint([own, shell])
573
+ assert.equal(api.otherPluginFingerprint([shell]), baseline, 'this plugin must not affect its own index fingerprint')
574
+ assert.notEqual(api.otherPluginFingerprint([own, { ...shell, version: '0.2.1' }]), baseline, 'a plugin update must invalidate')
575
+ assert.notEqual(api.otherPluginFingerprint([own, { ...shell, enabled: false }]), baseline, 'a plugin toggle must invalidate')
576
+ assert.notEqual(api.otherPluginFingerprint([own]), baseline, 'a plugin removal must invalidate')
577
+ assert.equal(api.otherPluginFingerprint([]), api.otherPluginFingerprint([own]))
578
+ // 0.2 plugin rows carry entryId/moduleName rather than id/name.
579
+ assert.notEqual(
580
+ api.otherPluginFingerprint([own, { id: 'ui-theme', npm: '@deepseek-ai/dsh-client-ui-theme', enabled: true }]),
581
+ baseline,
582
+ )
583
+ })
584
+
585
+ test('legacy plugin-card seats stay indexed for pre-0.2 builds only', () => {
586
+ const { api } = load()
587
+ const seats = Object.fromEntries(api.DEEP_SLOTS.map((config) => [config.slot, config.parent]))
588
+ assert.equal(seats['settings.plugins.tab'], 'plugins', 'the Settings to Plugins tab seat is inside the panel and indexed')
589
+ assert.equal(seats['settings.general.item'], 'general')
590
+ assert.equal(seats['settings.plugin.item'], 'plugins', 'legacy seat stays indexed')
591
+ assert.equal(seats['web-ui.plugin.item'], 'web-ui-plugins', 'legacy seat stays indexed')
592
+ // 0.2 moves the plugin cards to its standalone Plugins panel, which the
593
+ // settings-panel navigation cannot reach: indexing it would dead-end.
594
+ assert.equal(seats['plugins.item'], undefined, 'the standalone panel seat must not be indexed')
595
+ })
596
+
597
+ test('the seat fingerprint stays meaningful on DSH 0.2, where the legacy card seats are empty', () => { const { api } = load()
598
+ const pages = [{ options: { id: 'general', order: 0, label: 'General' } }]
599
+ const ctx = {
600
+ effect: (fn) => fn(),
601
+ get: () => null,
602
+ inject: () => {},
603
+ locale: { register: () => {}, bind: () => () => '', subscribe: () => () => {} },
604
+ slots: {
605
+ register: (name, id, options) => ({ name, id, options }),
606
+ inject: (_slot, registrar) => registrar(),
607
+ entries: (slot) => (slot === 'settings.section' ? pages : []),
608
+ subscribe: () => () => {},
609
+ },
610
+ }
611
+ api.apply(ctx)
612
+ const model = api.__indexTestModel
613
+ const before = model.slotsFingerprint()
614
+ assert.notEqual(before, '[]', 'an empty fingerprint would disable every rebuild signal on 0.2')
615
+ pages.push({ options: { id: 'plugins', order: 15, label: 'Plugins' } })
616
+ assert.notEqual(model.slotsFingerprint(), before, 'a settings page appearing must invalidate a stored index')
617
+ })
618
+
619
+ // --- Log recording: the in-memory ring, the batched host write-through, and the viewer fallback ---
620
+
621
+ const logRouteCalls = (calls) => calls.filter((call) => String(call.url).includes('api/settings-search-log'))
622
+
623
+ test('log entries are batched to the host log route as one formatted line each', () => {
624
+ const { api, calls } = load()
625
+ api.log('info', '应用装载', { version: '1.13.1' })
626
+ api.log('error', '导入失败')
627
+ api.flushLogs()
628
+ const [call] = logRouteCalls(calls)
629
+ assert.ok(call, 'the host log route must be posted to')
630
+ assert.equal(call.method, 'POST')
631
+ assert.deepEqual(plain(call.headers), { 'content-type': 'application/json' })
632
+ assert.equal(call.body.action, 'append')
633
+ assert.equal(call.body.lines.length, 2)
634
+ assert.match(call.body.lines[0], /^\d{4}-\d{2}-\d{2}T[\d:.]+Z \[info\] \[[0-9a-f]{8}:1\] 应用装载 \{"version":"1\.13\.1"\}$/)
635
+ assert.match(call.body.lines[1], /\[error\] \[[0-9a-f]{8}:2\] 导入失败$/)
636
+ })
637
+
638
+ test('the debounce timer ships queued lines, and clearing drops them instead', () => {
639
+ const { api, calls, sandbox } = load()
640
+ let fire = null
641
+ let delay = 0
642
+ sandbox.setTimeout = (callback, ms) => { fire = callback; delay = ms; return 1 }
643
+ sandbox.clearTimeout = () => {}
644
+ api.log('info', 'a')
645
+ assert.equal(delay, 1200, 'the batch must be debounced instead of posting per line')
646
+ assert.equal(logRouteCalls(calls).length, 0)
647
+ fire()
648
+ assert.equal(logRouteCalls(calls).length, 1, 'the debounce must ship the queued line')
649
+
650
+ api.log('info', 'b')
651
+ api.discardPendingLogs()
652
+ api.flushLogs()
653
+ assert.equal(logRouteCalls(calls).length, 1, 'a cleared queue must not be shipped')
654
+ })
655
+
656
+ test('the session log text mirrors the on-disk line format for the viewer fallback', () => {
657
+ const { api } = load()
658
+ assert.deepEqual(plain(api.logTarget()), { dir: '', file: '', state: 'idle', detail: '', count: null })
659
+ api.log('info', 'only line')
660
+ assert.match(api.sessionLogText(), /^\d{4}-\d{2}-\d{2}T[\d:.]+Z \[info\] \[[0-9a-f]{8}:1\] only line$/)
661
+ })
662
+
663
+ test('a failing host log channel never throws and never logs about itself', async () => {
664
+ const { api, calls } = load(async () => { throw new TypeError('Failed to fetch') })
665
+ api.log('info', 'first')
666
+ api.flushLogs()
667
+ await new Promise((resolve) => setTimeout(resolve, 0))
668
+ assert.equal(logRouteCalls(calls).length, 1)
669
+ assert.equal(api.logTarget().state, 'fail')
670
+ // The failed transport must not have queued a log line of its own.
671
+ api.flushLogs()
672
+ assert.equal(logRouteCalls(calls).length, 1)
673
+ })
674
+
675
+ test('the badge count follows the host file, not just this session', async () => {
676
+ // The host reports the entries that exist on disk, including earlier runs.
677
+ const { api, calls } = load(async () => json({ ok: true, count: 7, dir: 'D', file: 'F' }))
678
+ assert.equal(await api.readLogCount(), 7)
679
+ const [call] = logRouteCalls(calls)
680
+ assert.equal(call.method, 'GET')
681
+ assert.match(String(call.url), /api\/settings-search-log\?count=1$/)
682
+ assert.deepEqual(plain(api.logTarget()), { dir: 'D', file: 'F', state: 'ok', detail: '', count: 7 })
683
+
684
+ // A count that fails to arrive leaves the badge on the session fallback.
685
+ const { api: offline } = load(async () => { throw new TypeError('Failed to fetch') })
686
+ assert.equal(await offline.readLogCount(), null)
687
+ assert.equal(offline.logTarget().count, null)
688
+ })
package/scripts/check.mjs CHANGED
@@ -60,6 +60,34 @@ check(versionMatch !== null, 'lib/client.js must define const PKG_VERSION')
60
60
  check(versionMatch?.[1] === pkg.version,
61
61
  `PKG_VERSION (${versionMatch?.[1]}) must equal package.json version (${pkg.version})`)
62
62
 
63
+ // 5. theme variables: every token the bundle styles with must exist in the DSH
64
+ // 0.2 theme registry (verified against @deepseek-ai/dsh-client-ui-theme).
65
+ // A token that 0.2 never defines silently falls back to the inherited value.
66
+ const VERIFIED_THEME_TOKENS = new Set([
67
+ '--dsw-alias-bg-layer-1',
68
+ '--dsw-alias-bg-layer-2',
69
+ '--dsw-alias-bg-layer-3',
70
+ '--dsw-alias-bg-mask-1',
71
+ '--dsw-alias-bg-module-platform',
72
+ '--dsw-alias-bg-overlay',
73
+ '--dsw-alias-border-l1',
74
+ '--dsw-alias-border-l2',
75
+ '--dsw-alias-brand-primary',
76
+ '--dsw-alias-interactive-bg-hover',
77
+ '--dsw-alias-label-dimmed',
78
+ '--dsw-alias-label-primary',
79
+ '--dsw-alias-label-secondary',
80
+ '--dsw-alias-label-tertiary',
81
+ '--dsw-alias-state-error-primary',
82
+ '--dsw-alias-state-success-primary',
83
+ '--dsw-shadow-lv2',
84
+ '--dsw-shadow-lv3',
85
+ ])
86
+ for (const token of new Set([...source.matchAll(/--dsw-[a-z0-9-]+/g)].map((match) => match[0]))) {
87
+ check(VERIFIED_THEME_TOKENS.has(token),
88
+ `lib/client.js uses ${token}, which the DSH 0.2 theme does not define`)
89
+ }
90
+
63
91
  if (failed > 0) {
64
92
  console.error(`${failed} check(s) failed`)
65
93
  process.exit(1)