mirror of
https://github.com/hansjone/netxops.git
synced 2026-10-09 02:40:45 +08:00
Support both dsh settings APIs for the netxops namespace.
0.1.1-rc.2 uses installSettingsSection; 0.1.2+ uses settings.installSection — detect at runtime so global and source dsh both boot. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ca91031fd0
commit
4854101afd
3 changed files with 47 additions and 8 deletions
39
src/index.ts
39
src/index.ts
|
|
@ -13,7 +13,7 @@ import type { Context, Fiber } from '@deepseek-ai/cordis'
|
|||
import z from '@deepseek-ai/schemastery'
|
||||
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
||||
import type {} from '@deepseek-ai/dsh-credentials'
|
||||
import { installSettingsSection } from '@deepseek-ai/dsh-settings'
|
||||
import * as DshSettings from '@deepseek-ai/dsh-settings'
|
||||
import type {} from '@deepseek-ai/dsh-settings'
|
||||
import * as McpClient from '@deepseek-ai/dsh-mcp-client'
|
||||
|
||||
|
|
@ -64,6 +64,38 @@ async function resolveToken(ctx: Context, refName: string): Promise<string> {
|
|||
return hit?.value ?? ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the settings namespace on both dsh generations:
|
||||
* - 0.1.1-rc.2: standalone `installSettingsSection`
|
||||
* - ≥0.1.2-rc.1: `settings.installSection` on the provider
|
||||
*/
|
||||
function installNetxopsSettings(
|
||||
ctx: Context,
|
||||
entry: Config,
|
||||
hooks: {
|
||||
setSource: (current: () => Config) => void
|
||||
onChange: () => void
|
||||
},
|
||||
): void {
|
||||
const legacy = (DshSettings as {
|
||||
installSettingsSection?: (
|
||||
context: Context,
|
||||
ns: string,
|
||||
schema: z<Config>,
|
||||
base: Config,
|
||||
sectionHooks: typeof hooks,
|
||||
) => void
|
||||
}).installSettingsSection
|
||||
if (typeof legacy === 'function') {
|
||||
legacy(ctx, NETXOPS_SETTINGS_NAMESPACE, Config, entry, hooks)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.inject(['settings'], (settingsCtx) => {
|
||||
settingsCtx.settings.installSection(ctx, NETXOPS_SETTINGS_NAMESPACE, Config, entry, hooks)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the Netx Ops host bridge.
|
||||
*/
|
||||
|
|
@ -119,10 +151,7 @@ export function apply(ctx: Context, config: Config = Config({})): void {
|
|||
// Composition defaults first (works even when settings provider is absent).
|
||||
remount()
|
||||
|
||||
// Shipped dsh 0.1.1-rc.2 exports the standalone helper; SettingsProvider has
|
||||
// no `.installSection` method there. Newer cookbooks moved it onto the
|
||||
// provider — keep the helper call so the Plugins tab can see `netxops`.
|
||||
installSettingsSection(ctx, NETXOPS_SETTINGS_NAMESPACE, Config, config, {
|
||||
installNetxopsSettings(ctx, config, {
|
||||
setSource: (current) => {
|
||||
source = current
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue