Ask Mode and No More Auto Driven AI Confirm
This commit is contained in:
+206
-46
@@ -29,6 +29,15 @@ function params(properties = {}, required) {
|
||||
* @typedef {{ type: 'function', name: string, description: string, parameters: object, tier?: ToolTier }} ToolDef
|
||||
*/
|
||||
|
||||
/** Shared optional navigate param for UI-affecting tools */
|
||||
const NAVIGATE_PROP = {
|
||||
navigate: {
|
||||
type: 'boolean',
|
||||
description:
|
||||
'true only if the user asked to open/see that view, or they confirmed auto-navigate. Default false keeps them on the current tab.',
|
||||
},
|
||||
}
|
||||
|
||||
/** @type {ToolDef[]} */
|
||||
export const TOOL_DEFS = [
|
||||
// ── core: diagnosis + navigation ─────────────────────────────────────
|
||||
@@ -130,7 +139,7 @@ export const TOOL_DEFS = [
|
||||
name: 'open_chart',
|
||||
tier: 'core',
|
||||
description:
|
||||
'Open one chart on the Charts wall (scroll + focus). Prefer show_charts when pinning multiple or changing window/type.',
|
||||
'Prepare one chart on the Charts wall (pin/focus). Does NOT switch tabs unless navigate=true or user allows auto-navigate.',
|
||||
parameters: params(
|
||||
{
|
||||
chart: { type: 'string', description: 'Chart id' },
|
||||
@@ -145,6 +154,7 @@ export const TOOL_DEFS = [
|
||||
type: 'string',
|
||||
description: 'Time preset e.g. 5m|15m|1h|6h|24h',
|
||||
},
|
||||
...NAVIGATE_PROP,
|
||||
},
|
||||
['chart']
|
||||
),
|
||||
@@ -154,7 +164,7 @@ export const TOOL_DEFS = [
|
||||
name: 'show_charts',
|
||||
tier: 'core',
|
||||
description:
|
||||
'PRIMARY live chart tool. Opens Charts view, pins charts to the board, sets time window/type, optional focus and related panel. Use for "show me graphs", "plot CPU", multi-chart boards.',
|
||||
'PRIMARY chart tool: pin charts, set window/type on the Charts wall. Stays on QVAC unless navigate=true (user asked to see graphs) or auto-navigate allows.',
|
||||
parameters: params(
|
||||
{
|
||||
charts: {
|
||||
@@ -196,6 +206,7 @@ export const TOOL_DEFS = [
|
||||
type: 'boolean',
|
||||
description: 'Live play (true) or pause (false)',
|
||||
},
|
||||
...NAVIGATE_PROP,
|
||||
},
|
||||
['charts']
|
||||
),
|
||||
@@ -204,7 +215,7 @@ export const TOOL_DEFS = [
|
||||
type: 'function',
|
||||
name: 'pin_charts',
|
||||
tier: 'core',
|
||||
description: 'Pin or unpin charts on the Charts board without changing focus.',
|
||||
description: 'Pin or unpin charts on the Charts board (no tab switch unless navigate=true).',
|
||||
parameters: params(
|
||||
{
|
||||
charts: {
|
||||
@@ -215,6 +226,7 @@ export const TOOL_DEFS = [
|
||||
type: 'boolean',
|
||||
description: 'true=pin (default), false=unpin',
|
||||
},
|
||||
...NAVIGATE_PROP,
|
||||
},
|
||||
['charts']
|
||||
),
|
||||
@@ -232,6 +244,7 @@ export const TOOL_DEFS = [
|
||||
description: 'line|area|stacked|bar|multibar|pie',
|
||||
enum: ['line', 'area', 'stacked', 'bar', 'multibar', 'pie'],
|
||||
},
|
||||
...NAVIGATE_PROP,
|
||||
},
|
||||
['chart', 'mode']
|
||||
),
|
||||
@@ -248,6 +261,7 @@ export const TOOL_DEFS = [
|
||||
},
|
||||
seconds: { type: 'number', description: 'Lookback seconds' },
|
||||
playing: { type: 'boolean', description: 'Live updates on/off' },
|
||||
...NAVIGATE_PROP,
|
||||
}),
|
||||
},
|
||||
{
|
||||
@@ -258,6 +272,7 @@ export const TOOL_DEFS = [
|
||||
parameters: params(
|
||||
{
|
||||
q: { type: 'string', description: 'Filter query (empty clears)' },
|
||||
...NAVIGATE_PROP,
|
||||
},
|
||||
['q']
|
||||
),
|
||||
@@ -270,6 +285,7 @@ export const TOOL_DEFS = [
|
||||
parameters: params(
|
||||
{
|
||||
chart: { type: 'string', description: 'Seed chart id' },
|
||||
...NAVIGATE_PROP,
|
||||
},
|
||||
['chart']
|
||||
),
|
||||
@@ -279,11 +295,12 @@ export const TOOL_DEFS = [
|
||||
name: 'run_correlations',
|
||||
tier: 'deep',
|
||||
description:
|
||||
'Run Metric Correlations around a chart or timestamp and show results on the Charts wall.',
|
||||
'Run Metric Correlations around a chart or timestamp on the Charts wall.',
|
||||
parameters: params({
|
||||
chart: { type: 'string', description: 'Optional seed chart id' },
|
||||
ts: { type: 'number', description: 'Center timestamp ms (default now)' },
|
||||
window: { type: 'number', description: 'Highlight window seconds' },
|
||||
...NAVIGATE_PROP,
|
||||
}),
|
||||
},
|
||||
{
|
||||
@@ -291,7 +308,7 @@ export const TOOL_DEFS = [
|
||||
name: 'open_view',
|
||||
tier: 'core',
|
||||
description:
|
||||
'Navigate desktop to a view: overview|charts|dashboard|processes|alerts|logs|fleet|settings|qvac',
|
||||
'Switch the user to a desktop view. Only when they asked to go there, or navigate=true / auto-navigate allows. Views: overview|charts|dashboard|processes|alerts|logs|fleet|settings|qvac',
|
||||
parameters: params(
|
||||
{
|
||||
view: {
|
||||
@@ -309,6 +326,7 @@ export const TOOL_DEFS = [
|
||||
'qvac',
|
||||
],
|
||||
},
|
||||
...NAVIGATE_PROP,
|
||||
},
|
||||
['view']
|
||||
),
|
||||
@@ -327,7 +345,7 @@ export const TOOL_DEFS = [
|
||||
name: 'create_dashboard',
|
||||
tier: 'core',
|
||||
description:
|
||||
'Create a custom live dashboard and open it. Pass name + charts (comma ids). Use for "build a dashboard with CPU and RAM".',
|
||||
'Create a custom live dashboard. Pass name + charts. Tab switch only with navigate=true or auto-navigate allow.',
|
||||
parameters: params(
|
||||
{
|
||||
name: { type: 'string', description: 'Dashboard name' },
|
||||
@@ -341,6 +359,7 @@ export const TOOL_DEFS = [
|
||||
description: 'Default tile mode line|area|bar|…',
|
||||
enum: ['line', 'area', 'stacked', 'bar', 'multibar', 'pie'],
|
||||
},
|
||||
...NAVIGATE_PROP,
|
||||
},
|
||||
['name']
|
||||
),
|
||||
@@ -390,6 +409,7 @@ export const TOOL_DEFS = [
|
||||
description: 'Tile chart type',
|
||||
enum: ['line', 'area', 'stacked', 'bar', 'multibar', 'pie'],
|
||||
},
|
||||
...NAVIGATE_PROP,
|
||||
},
|
||||
['charts']
|
||||
),
|
||||
@@ -414,9 +434,11 @@ export const TOOL_DEFS = [
|
||||
type: 'function',
|
||||
name: 'open_dashboard',
|
||||
tier: 'core',
|
||||
description: 'Open the Dashboard tab and select a board by id (or active).',
|
||||
description:
|
||||
'Select a dashboard board. Switches to Dashboard tab only with navigate=true or auto-navigate allow (user asked to open it).',
|
||||
parameters: params({
|
||||
id: { type: 'string', description: 'Dashboard id (optional)' },
|
||||
...NAVIGATE_PROP,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -740,6 +762,53 @@ function wireDefs(defs) {
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve auto-navigate preference: off | ask | on
|
||||
* @param {*} deps
|
||||
*/
|
||||
function autoNavMode(deps) {
|
||||
const raw = deps.getAutoNavigate?.() ?? deps.autoNavigate ?? 'ask'
|
||||
const s = String(raw || 'ask').toLowerCase()
|
||||
if (s === 'on' || s === 'true' || s === 'always') return 'on'
|
||||
if (s === 'off' || s === 'false' || s === 'never') return 'off'
|
||||
return 'ask'
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch desktop view only when allowed.
|
||||
* @param {string} view
|
||||
* @param {*} deps
|
||||
* @param {object} [args]
|
||||
* @returns {Promise<{ navigated: boolean, reason: string }>}
|
||||
*/
|
||||
async function maybeNavigate(view, deps, args = {}) {
|
||||
const force =
|
||||
args.navigate === true ||
|
||||
args.navigate === 'true' ||
|
||||
args.navigate === 1 ||
|
||||
args.navigate === '1'
|
||||
const mode = autoNavMode(deps)
|
||||
const label = String(view || 'that view')
|
||||
|
||||
if (force || mode === 'on') {
|
||||
deps.onOpenView?.(view)
|
||||
return { navigated: true, reason: force ? 'navigate=true' : 'auto_on' }
|
||||
}
|
||||
if (mode === 'ask') {
|
||||
const ok =
|
||||
(await deps.confirmAction?.(
|
||||
`QVAC wants to open the “${label}” view. Switch now?`
|
||||
)) === true
|
||||
if (ok) {
|
||||
deps.onOpenView?.(view)
|
||||
return { navigated: true, reason: 'user_confirmed' }
|
||||
}
|
||||
return { navigated: false, reason: 'user_declined' }
|
||||
}
|
||||
// off
|
||||
return { navigated: false, reason: 'auto_off' }
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* manager: { request: (m: string, a?: object) => Promise<any>, active: any },
|
||||
@@ -748,6 +817,8 @@ function wireDefs(defs) {
|
||||
* getCatalog?: () => Record<string, object>,
|
||||
* onOpenChart?: (chartId: string, ts?: number, opts?: object) => void,
|
||||
* onOpenView?: (view: string) => void,
|
||||
* getAutoNavigate?: () => 'off'|'ask'|'on'|string,
|
||||
* autoNavigate?: 'off'|'ask'|'on'|string,
|
||||
* charts?: {
|
||||
* showCharts?: (opts: object) => object,
|
||||
* setPinned?: (ids: string|string[], opts?: object) => object,
|
||||
@@ -921,9 +992,10 @@ export function createToolRunner(deps) {
|
||||
case 'open_chart': {
|
||||
const chart = String(args.chart || args.id || '')
|
||||
if (!chart) return { error: 'chart required' }
|
||||
deps.onOpenView?.('charts')
|
||||
const nav = await maybeNavigate('charts', deps, args)
|
||||
let result
|
||||
if (chartsApi.showCharts) {
|
||||
return chartsApi.showCharts({
|
||||
result = chartsApi.showCharts({
|
||||
charts: [chart],
|
||||
pin: args.pin !== false,
|
||||
boardOnly: args.pin !== false,
|
||||
@@ -931,26 +1003,34 @@ export function createToolRunner(deps) {
|
||||
ts: args.ts,
|
||||
mode: args.mode,
|
||||
preset: args.preset,
|
||||
openFocus: true,
|
||||
openFocus: nav.navigated,
|
||||
})
|
||||
} else {
|
||||
deps.onOpenChart?.(chart, args.ts, {
|
||||
pin: args.pin !== false,
|
||||
mode: args.mode,
|
||||
preset: args.preset,
|
||||
navigate: nav.navigated,
|
||||
})
|
||||
result = { ok: true, opened: chart }
|
||||
}
|
||||
deps.onOpenChart?.(chart, args.ts, {
|
||||
pin: args.pin !== false,
|
||||
mode: args.mode,
|
||||
preset: args.preset,
|
||||
})
|
||||
return { ok: true, opened: chart }
|
||||
return { ...result, navigated: nav.navigated, navigateReason: nav.reason }
|
||||
}
|
||||
case 'show_charts': {
|
||||
const list = parseChartList(args.charts || args.chart || args.ids)
|
||||
if (!list.length) return { error: 'charts required' }
|
||||
deps.onOpenView?.('charts')
|
||||
const nav = await maybeNavigate('charts', deps, args)
|
||||
if (!chartsApi.showCharts) {
|
||||
// Fallback: open first chart only
|
||||
deps.onOpenChart?.(list[0], args.ts)
|
||||
return { ok: true, charts: list, partial: true }
|
||||
if (nav.navigated) deps.onOpenChart?.(list[0], args.ts)
|
||||
return {
|
||||
ok: true,
|
||||
charts: list,
|
||||
partial: true,
|
||||
navigated: nav.navigated,
|
||||
navigateReason: nav.reason,
|
||||
}
|
||||
}
|
||||
return chartsApi.showCharts({
|
||||
const result = chartsApi.showCharts({
|
||||
charts: list,
|
||||
pin: args.pin !== false,
|
||||
boardOnly: args.boardOnly != null ? Boolean(args.boardOnly) : args.pin !== false,
|
||||
@@ -962,58 +1042,74 @@ export function createToolRunner(deps) {
|
||||
filter: args.filter,
|
||||
related: Boolean(args.related),
|
||||
playing: args.playing,
|
||||
openFocus: list.length === 1,
|
||||
openFocus: nav.navigated && list.length === 1,
|
||||
})
|
||||
return { ...result, navigated: nav.navigated, navigateReason: nav.reason }
|
||||
}
|
||||
case 'pin_charts': {
|
||||
const list = parseChartList(args.charts || args.chart)
|
||||
if (!list.length) return { error: 'charts required' }
|
||||
deps.onOpenView?.('charts')
|
||||
const nav = await maybeNavigate('charts', deps, args)
|
||||
if (!chartsApi.setPinned) return { error: 'charts API unavailable' }
|
||||
return chartsApi.setPinned(list, {
|
||||
const result = chartsApi.setPinned(list, {
|
||||
pin: args.pin !== false && args.pin !== 'false',
|
||||
})
|
||||
return { ...result, navigated: nav.navigated, navigateReason: nav.reason }
|
||||
}
|
||||
case 'set_chart_type': {
|
||||
const chart = String(args.chart || args.id || '')
|
||||
const mode = String(args.mode || args.type || 'line')
|
||||
if (!chart) return { error: 'chart required' }
|
||||
deps.onOpenView?.('charts')
|
||||
const nav = await maybeNavigate('charts', deps, args)
|
||||
if (!chartsApi.setChartMode) return { error: 'charts API unavailable' }
|
||||
return chartsApi.setChartMode(chart, mode)
|
||||
const result = chartsApi.setChartMode(chart, mode)
|
||||
return { ...result, navigated: nav.navigated, navigateReason: nav.reason }
|
||||
}
|
||||
case 'set_time_window': {
|
||||
deps.onOpenView?.('charts')
|
||||
const nav = await maybeNavigate('charts', deps, args)
|
||||
if (!chartsApi.setTimeWindow) return { error: 'charts API unavailable' }
|
||||
return chartsApi.setTimeWindow({
|
||||
const result = chartsApi.setTimeWindow({
|
||||
preset: args.preset,
|
||||
seconds: args.seconds ?? args.after,
|
||||
playing: args.playing,
|
||||
})
|
||||
return { ...result, navigated: nav.navigated, navigateReason: nav.reason }
|
||||
}
|
||||
case 'filter_charts': {
|
||||
deps.onOpenView?.('charts')
|
||||
const nav = await maybeNavigate('charts', deps, args)
|
||||
if (!chartsApi.setFilter) return { error: 'charts API unavailable' }
|
||||
return chartsApi.setFilter(args.q != null ? args.q : args.filter || '')
|
||||
const result = chartsApi.setFilter(args.q != null ? args.q : args.filter || '')
|
||||
return { ...result, navigated: nav.navigated, navigateReason: nav.reason }
|
||||
}
|
||||
case 'show_related_ui': {
|
||||
const chart = String(args.chart || args.id || '')
|
||||
if (!chart) return { error: 'chart required' }
|
||||
deps.onOpenView?.('charts')
|
||||
const nav = await maybeNavigate('charts', deps, args)
|
||||
chartsApi.scrollToChart?.(chart)
|
||||
await chartsApi.showRelated?.(chart)
|
||||
return { ok: true, chart, related: true }
|
||||
return {
|
||||
ok: true,
|
||||
chart,
|
||||
related: true,
|
||||
navigated: nav.navigated,
|
||||
navigateReason: nav.reason,
|
||||
}
|
||||
}
|
||||
case 'run_correlations': {
|
||||
deps.onOpenView?.('charts')
|
||||
const ts =
|
||||
args.ts != null ? Number(args.ts) : Date.now()
|
||||
const nav = await maybeNavigate('charts', deps, args)
|
||||
const ts = args.ts != null ? Number(args.ts) : Date.now()
|
||||
if (chartsApi.correlateAround) {
|
||||
chartsApi.correlateAround(ts, {
|
||||
chart: args.chart,
|
||||
window: args.window,
|
||||
})
|
||||
return { ok: true, ts, chart: args.chart || null }
|
||||
return {
|
||||
ok: true,
|
||||
ts,
|
||||
chart: args.chart || null,
|
||||
navigated: nav.navigated,
|
||||
navigateReason: nav.reason,
|
||||
}
|
||||
}
|
||||
if (chartsApi.runMetricCorrelations) {
|
||||
const res = await chartsApi.runMetricCorrelations({
|
||||
@@ -1021,13 +1117,58 @@ export function createToolRunner(deps) {
|
||||
ts,
|
||||
window: args.window,
|
||||
})
|
||||
return { ok: true, ...(res || {}) }
|
||||
return {
|
||||
ok: true,
|
||||
...(res || {}),
|
||||
navigated: nav.navigated,
|
||||
navigateReason: nav.reason,
|
||||
}
|
||||
}
|
||||
return { error: 'correlations API unavailable' }
|
||||
}
|
||||
case 'open_view': {
|
||||
deps.onOpenView?.(String(args.view || 'overview'))
|
||||
return { ok: true, view: args.view }
|
||||
// Explicit navigation tool — still gated by auto-nav / navigate flag
|
||||
const view = String(args.view || 'overview')
|
||||
const nav = await maybeNavigate(view, deps, {
|
||||
...args,
|
||||
// open_view implies intent to navigate when auto is on/ask;
|
||||
// with auto off, still require navigate=true
|
||||
navigate: args.navigate === true || args.navigate === 'true' ? true : args.navigate,
|
||||
})
|
||||
// When mode is ask/on, maybeNavigate already handled. When off without force, no-op.
|
||||
if (!nav.navigated && autoNavMode(deps) !== 'off') {
|
||||
// ask declined already returned; on should have navigated
|
||||
}
|
||||
// For open_view with auto on, force path already navigated.
|
||||
// With auto off, require navigate=true (maybeNavigate handles).
|
||||
// With auto ask without prior force: maybeNavigate already asked.
|
||||
// Special case: if auto is off and navigate not set, try one confirm as explicit open_view
|
||||
if (!nav.navigated && autoNavMode(deps) === 'off' && args.navigate == null) {
|
||||
const ok =
|
||||
(await deps.confirmAction?.(
|
||||
`Switch to the “${view}” view? (You can enable Auto-navigate in QVAC Settings.)`
|
||||
)) === true
|
||||
if (ok) {
|
||||
deps.onOpenView?.(view)
|
||||
return { ok: true, view, navigated: true, navigateReason: 'user_confirmed' }
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
view,
|
||||
navigated: false,
|
||||
navigateReason: 'user_declined',
|
||||
note: 'Stayed on current tab. Pass navigate=true when the user asks to open a view.',
|
||||
}
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
view,
|
||||
navigated: nav.navigated,
|
||||
navigateReason: nav.reason,
|
||||
note: nav.navigated
|
||||
? undefined
|
||||
: 'View not switched. User did not allow navigation.',
|
||||
}
|
||||
}
|
||||
case 'list_dashboards': {
|
||||
if (!deps.dashboards?.list) return { error: 'dashboards API unavailable' }
|
||||
@@ -1042,8 +1183,8 @@ export function createToolRunner(deps) {
|
||||
mode: args.mode || 'area',
|
||||
tiles: args.tiles,
|
||||
})
|
||||
deps.onOpenView?.('dashboard')
|
||||
return r
|
||||
const nav = await maybeNavigate('dashboard', deps, args)
|
||||
return { ...r, navigated: nav.navigated, navigateReason: nav.reason }
|
||||
}
|
||||
case 'update_dashboard': {
|
||||
if (!deps.dashboards?.update) return { error: 'dashboards API unavailable' }
|
||||
@@ -1068,8 +1209,8 @@ export function createToolRunner(deps) {
|
||||
mode: args.mode,
|
||||
replace: args.replace,
|
||||
})
|
||||
deps.onOpenView?.('dashboard')
|
||||
return r
|
||||
const nav = await maybeNavigate('dashboard', deps, args)
|
||||
return { ...r, navigated: nav.navigated, navigateReason: nav.reason }
|
||||
}
|
||||
case 'remove_dashboard_charts': {
|
||||
if (!deps.dashboards?.removeCharts) return { error: 'dashboards API unavailable' }
|
||||
@@ -1080,10 +1221,29 @@ export function createToolRunner(deps) {
|
||||
}
|
||||
case 'open_dashboard': {
|
||||
if (!deps.dashboards?.open) {
|
||||
deps.onOpenView?.('dashboard')
|
||||
return { ok: true, view: 'dashboard' }
|
||||
const nav = await maybeNavigate('dashboard', deps, {
|
||||
...args,
|
||||
navigate: args.navigate != null ? args.navigate : true,
|
||||
})
|
||||
return {
|
||||
ok: true,
|
||||
view: 'dashboard',
|
||||
navigated: nav.navigated,
|
||||
navigateReason: nav.reason,
|
||||
}
|
||||
}
|
||||
return deps.dashboards.open({ id: args.id || args.dashboardId })
|
||||
// Select board first, then maybe switch tab
|
||||
const r = deps.dashboards.open({
|
||||
id: args.id || args.dashboardId,
|
||||
navigate: false,
|
||||
})
|
||||
const nav = await maybeNavigate('dashboard', deps, {
|
||||
...args,
|
||||
// open_dashboard is an open request: default navigate ask/on, but still confirm
|
||||
navigate: args.navigate != null ? args.navigate : undefined,
|
||||
})
|
||||
// If open always showed view before, prevent double — dashboards.open in app still navigates
|
||||
return { ...r, navigated: nav.navigated, navigateReason: nav.reason }
|
||||
}
|
||||
case 'silence_alert': {
|
||||
if (!args.confirmed) {
|
||||
|
||||
Reference in New Issue
Block a user