netxops/src/agent-tools.ts
oliver 027f83dd00 Fix empty Bearer on netx__* by waiting for credentials.
Inject credentials before publish, read the live token per HTTP request, and surface netx_token_missing instead of a silent 401.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-05 02:11:20 +08:00

50 lines
1.5 KiB
TypeScript

/**
* Agent-plane Netx Ops tools: register `netx__*` into the calling context's
* tool scope (the Netx Ops preset standing mount), so other presets do not see them.
*
* @module dsh-netxops/tools
*/
import type { Context } from '@deepseek-ai/cordis'
import type {} from '@deepseek-ai/dsh-tools'
import { getNetxConnection, watchNetxConnection } from './netx/runtime.ts'
import { registerNetxTools } from './netx/tools.ts'
/** Cordis plugin name. */
export const name = 'netxops-tools'
/** Tool registry must exist in this (preset-scoped) context. */
export const inject = ['tools']
/**
* Mount netx REST tools for the Netx Ops agent preset only.
*/
export function apply(ctx: Context): void {
let unregister: (() => void) | undefined
const remount = (): void => {
unregister?.()
unregister = undefined
const connection = getNetxConnection()
if (connection === undefined) {
ctx.logger.warn('netxops-tools: no connection yet — waiting for host settings bridge')
return
}
unregister = registerNetxTools(ctx, connection)
const tokenConfigured = connection.token.trim().length > 0
ctx.logger.info(
'netxops-tools: registered netx__* for Ops preset → %s tokenConfigured=%s',
connection.apiUrl,
tokenConfigured,
)
}
remount()
const stopWatch = watchNetxConnection(() => { remount() })
ctx.effect(() => () => {
stopWatch()
unregister?.()
unregister = undefined
}, 'netxops-tools: dispose')
}