neuralos 3.9.4 → 3.9.6
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/LICENSE +202 -0
- package/README.md +48 -347
- package/cli.js +78 -0
- package/engine.js +124 -0
- package/index.js +160 -0
- package/package.json +37 -43
- package/test.js +20 -0
- package/tools.js +47 -0
- package/bin/gybackend.cjs +0 -398530
- package/plugins/agentspan-bridge/agentspan-bridge.extreme.spec.ts +0 -328
- package/plugins/agentspan-bridge/agentspan-bridge.phase2.extreme.spec.ts +0 -282
- package/plugins/agentspan-bridge/conductorClient.mjs +0 -182
- package/plugins/agentspan-bridge/index.mjs +0 -389
- package/plugins/agentspan-bridge/playbookToWorkflowDef.mjs +0 -209
- package/plugins/agentspan-bridge/plugin.json +0 -27
- package/plugins/fraudops/index.d.mts +0 -9
- package/plugins/fraudops/index.mjs +0 -185
- package/plugins/fraudops/plugin.json +0 -10
- package/plugins/iam-connector/index.d.mts +0 -10
- package/plugins/iam-connector/index.mjs +0 -229
- package/plugins/iam-connector/plugin.json +0 -10
- package/plugins/mitmproxy-bridge/index.d.mts +0 -20
- package/plugins/mitmproxy-bridge/index.mjs +0 -256
- package/plugins/mitmproxy-bridge/plugin.json +0 -17
- package/plugins/monid-bridge/index.mjs +0 -228
- package/plugins/monid-bridge/monid-bridge.extreme.spec.mjs +0 -75
- package/plugins/monid-bridge/plugin.json +0 -15
- package/plugins/netdata-rterm/index.mjs +0 -229
- package/plugins/netdata-rterm/netdata-rterm.extreme.spec.ts +0 -252
- package/plugins/netdata-rterm/plugin.json +0 -22
- package/plugins/netexec-bridge/index.d.mts +0 -28
- package/plugins/netexec-bridge/index.mjs +0 -325
- package/plugins/netexec-bridge/plugin.json +0 -20
- package/plugins/neuralos/index.mjs +0 -137
- package/plugins/neuralos/neuralos.extreme.spec.mts +0 -386
- package/plugins/neuralos/neuralosEngine.mjs +0 -369
- package/plugins/neuralos/plugin.json +0 -15
- package/plugins/numbat-bridge/index.mjs +0 -229
- package/plugins/numbat-bridge/numbat-bridge.extreme.spec.mjs +0 -148
- package/plugins/numbat-bridge/plugin.json +0 -21
- package/plugins/patch-manager/index.d.mts +0 -10
- package/plugins/patch-manager/index.mjs +0 -288
- package/plugins/patch-manager/plugin.json +0 -10
- package/plugins/promptfoo-redteam/index.d.mts +0 -15
- package/plugins/promptfoo-redteam/index.mjs +0 -277
- package/plugins/promptfoo-redteam/plugin.json +0 -16
- package/plugins/reactorpro-bridge/index.mjs +0 -499
- package/plugins/reactorpro-bridge/plugin.json +0 -26
- package/plugins/reactorpro-bridge/reactorpro-bridge.extreme.spec.mts +0 -409
- package/plugins/reactorpro-bridge/reactorproAgent.mjs +0 -399
- package/plugins/request-router/index.d.mts +0 -9
- package/plugins/request-router/index.mjs +0 -239
- package/plugins/request-router/plugin.json +0 -10
- package/plugins/sample-k8s-slo/index.ts +0 -58
- package/plugins/sample-k8s-slo/plugin.json +0 -11
- package/plugins/sop-assistant/index.d.mts +0 -9
- package/plugins/sop-assistant/index.mjs +0 -325
- package/plugins/sop-assistant/plugin.json +0 -10
- package/plugins/synapse-bridge/index.mjs +0 -484
- package/plugins/synapse-bridge/plugin.json +0 -29
- package/plugins/synapse-bridge/synapse-bridge.extreme.spec.mjs +0 -204
- package/plugins/synapse-bridge/synapseAgent.extreme.spec.mjs +0 -236
- package/plugins/synapse-bridge/synapseAgent.mjs +0 -254
- package/plugins/web-intel/index.mjs +0 -381
- package/plugins/web-intel/plugin.json +0 -28
- package/plugins/web-intel/sidecar.mjs +0 -134
- package/plugins/web-intel/web-intel.extreme.spec.ts +0 -263
- package/plugins/web-intel/wigoloClient.mjs +0 -145
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* sidecar.mjs — manages the wigolo daemon lifecycle for RTerm's web-intel
|
|
3
|
-
* plugin: lazily start `wigolo serve` on first use, keep a stock RTerm install
|
|
4
|
-
* lean (no browser-engine/on-device-model download unless the user opts in),
|
|
5
|
-
* and report status. Pure + injectable: process spawning and health-probing are
|
|
6
|
-
* injected so it's fully unit-testable offline.
|
|
7
|
-
*
|
|
8
|
-
* Lean-by-default: we start the daemon with WIGOLO_NO_WARMUP=1 so the ~1.5 GB
|
|
9
|
-
* browser engine + on-device models are NOT downloaded at init — search/fetch/
|
|
10
|
-
* crawl work keyless without them. The heavier models download in the background
|
|
11
|
-
* on first use that actually needs them. `warmupOnInit: true` opts into the full
|
|
12
|
-
* upfront download (a background `wigolo init` run).
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export const DEFAULT_PORT = 3333
|
|
16
|
-
export const DEFAULT_HOST = '127.0.0.1'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Build the spawn plan for the wigolo daemon.
|
|
20
|
-
* @param {{ port?: number, host?: string, warmup?: boolean, token?: string }} cfg
|
|
21
|
-
* @returns {{ command: string, args: string[], env: Record<string,string> }}
|
|
22
|
-
*/
|
|
23
|
-
export function buildServePlan(cfg = {}) {
|
|
24
|
-
const port = cfg.port ?? DEFAULT_PORT
|
|
25
|
-
const host = cfg.host ?? DEFAULT_HOST
|
|
26
|
-
const env = { ...process.env }
|
|
27
|
-
// Lean by default: skip the browser-engine/model warmup unless explicitly on.
|
|
28
|
-
if (cfg.warmup !== true) env.WIGOLO_NO_WARMUP = '1'
|
|
29
|
-
if (cfg.token) env.WIGOLO_API_TOKEN = cfg.token
|
|
30
|
-
return {
|
|
31
|
-
command: 'npx',
|
|
32
|
-
args: ['-y', 'wigolo', 'serve', '--port', String(port), '--host', host],
|
|
33
|
-
env,
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Build the background `wigolo init` plan (the full ~1.5 GB warmup). */
|
|
38
|
-
export function buildInitPlan(cfg = {}) {
|
|
39
|
-
const env = { ...process.env }
|
|
40
|
-
if (cfg.token) env.WIGOLO_API_TOKEN = cfg.token
|
|
41
|
-
return { command: 'npx', args: ['-y', 'wigolo', 'init'], env }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export class WigoloSidecar {
|
|
45
|
-
/**
|
|
46
|
-
* @param {{
|
|
47
|
-
* spawnImpl?: (cmd: string, args: string[], opts: object) => any,
|
|
48
|
-
* healthImpl?: () => Promise<boolean>,
|
|
49
|
-
* log?: (line: string) => void,
|
|
50
|
-
* config?: { port?: number, host?: string, warmup?: boolean, token?: string, autoStart?: boolean },
|
|
51
|
-
* now?: () => number,
|
|
52
|
-
* }} deps — all injectable; defaults are real (child_process + a health probe).
|
|
53
|
-
*/
|
|
54
|
-
constructor(deps = {}) {
|
|
55
|
-
this.config = deps.config ?? {}
|
|
56
|
-
this.spawnImpl = deps.spawnImpl
|
|
57
|
-
this.healthImpl = deps.healthImpl
|
|
58
|
-
this.log = deps.log ?? (() => {})
|
|
59
|
-
this.now = deps.now ?? (() => Date.now())
|
|
60
|
-
this.process = null
|
|
61
|
-
this.startedAt = 0
|
|
62
|
-
this.lastError = undefined
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Whether the daemon process is believed to be running. */
|
|
66
|
-
isRunning() {
|
|
67
|
-
return this.process != null
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** Start the daemon (idempotent). Returns the base URL it's expected on. */
|
|
71
|
-
async start() {
|
|
72
|
-
if (this.process) return this.baseUrl()
|
|
73
|
-
if (typeof this.spawnImpl !== 'function') {
|
|
74
|
-
this.lastError = 'no spawnImpl (sidecar spawn not available in this runtime)'
|
|
75
|
-
throw new Error(this.lastError)
|
|
76
|
-
}
|
|
77
|
-
const plan = buildServePlan(this.config)
|
|
78
|
-
this.log(`[web-intel] starting wigolo daemon: ${plan.command} ${plan.args.join(' ')}`)
|
|
79
|
-
try {
|
|
80
|
-
this.process = this.spawnImpl(plan.command, plan.args, {
|
|
81
|
-
env: plan.env,
|
|
82
|
-
detached: true,
|
|
83
|
-
stdio: 'ignore',
|
|
84
|
-
})
|
|
85
|
-
// Detach so the daemon outlives the plugin turn (it serves many agents).
|
|
86
|
-
this.process?.unref?.()
|
|
87
|
-
this.startedAt = this.now()
|
|
88
|
-
this.lastError = undefined
|
|
89
|
-
} catch (e) {
|
|
90
|
-
this.lastError = e?.message ?? String(e)
|
|
91
|
-
this.process = null
|
|
92
|
-
throw e
|
|
93
|
-
}
|
|
94
|
-
return this.baseUrl()
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Kick off the full ~1.5 GB warmup in the background (opt-in). */
|
|
98
|
-
async warmupInBackground() {
|
|
99
|
-
if (typeof this.spawnImpl !== 'function') return false
|
|
100
|
-
const plan = buildInitPlan(this.config)
|
|
101
|
-
try {
|
|
102
|
-
const p = this.spawnImpl(plan.command, plan.args, { env: plan.env, detached: true, stdio: 'ignore' })
|
|
103
|
-
p?.unref?.()
|
|
104
|
-
this.log('[web-intel] background wigolo init (browser engine + models) started')
|
|
105
|
-
return true
|
|
106
|
-
} catch {
|
|
107
|
-
return false
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** Stop the daemon. */
|
|
112
|
-
async stop() {
|
|
113
|
-
if (!this.process) return
|
|
114
|
-
try { this.process.kill?.() } catch { /* best-effort */ }
|
|
115
|
-
this.process = null
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** Status snapshot for the health tool / panel. */
|
|
119
|
-
status() {
|
|
120
|
-
return {
|
|
121
|
-
running: this.isRunning(),
|
|
122
|
-
baseUrl: this.baseUrl(),
|
|
123
|
-
startedAt: this.startedAt || undefined,
|
|
124
|
-
lastError: this.lastError,
|
|
125
|
-
warmup: this.config.warmup === true ? 'full' : 'lean (no warmup)',
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
baseUrl() {
|
|
130
|
-
const host = this.config.host ?? DEFAULT_HOST
|
|
131
|
-
const port = this.config.port ?? DEFAULT_PORT
|
|
132
|
-
return `http://${host}:${port}`
|
|
133
|
-
}
|
|
134
|
-
}
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* web-intel.extreme.spec.ts — exhaustive offline tests for the web-intel plugin:
|
|
3
|
-
* the dependency-free wigolo REST client (URL building, auth header, error
|
|
4
|
-
* mapping, every endpoint), the sidecar lifecycle (lean-by-default spawn plan,
|
|
5
|
-
* start/stop/status), and the plugin glue (config resolution, tool wiring,
|
|
6
|
-
* unreachable-daemon resilience, result normalization, trigger match). No
|
|
7
|
-
* network — fetch is mocked; spawn is injected/mocked.
|
|
8
|
-
*/
|
|
9
|
-
import { test } from 'node:test'
|
|
10
|
-
import assert from 'node:assert/strict'
|
|
11
|
-
import { WigoloClient, WigoloApiError, buildHeaders, joinUrl, DEFAULT_BASE_URL } from './wigoloClient.mjs'
|
|
12
|
-
import { WigoloSidecar, buildServePlan, buildInitPlan } from './sidecar.mjs'
|
|
13
|
-
import {
|
|
14
|
-
register,
|
|
15
|
-
resolveConfig,
|
|
16
|
-
buildClient,
|
|
17
|
-
toResultRows,
|
|
18
|
-
toPageSummary,
|
|
19
|
-
toResearchBrief,
|
|
20
|
-
toWatchRows,
|
|
21
|
-
isPageChangedEvent,
|
|
22
|
-
} from './index.mjs'
|
|
23
|
-
|
|
24
|
-
// ─── mock fetch ─────────────────────────────────────────────────────────────
|
|
25
|
-
function mockFetch(respond) {
|
|
26
|
-
const calls = []
|
|
27
|
-
const fn = async (url, init) => {
|
|
28
|
-
calls.push({ url, init })
|
|
29
|
-
const r = typeof respond === 'function' ? respond(url, init, calls.length) : respond
|
|
30
|
-
return { ok: r.ok !== false && (r.status ?? 200) < 400, status: r.status ?? 200, text: async () => r.text ?? (r.json !== undefined ? JSON.stringify(r.json) : '') }
|
|
31
|
-
}
|
|
32
|
-
fn.calls = calls
|
|
33
|
-
return fn
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// ─── wigoloClient ───────────────────────────────────────────────────────────
|
|
37
|
-
|
|
38
|
-
test('joinUrl joins base + path with a single slash', () => {
|
|
39
|
-
assert.equal(joinUrl('http://x:3333/', '/health'), 'http://x:3333/health')
|
|
40
|
-
assert.equal(joinUrl('http://x:3333', 'health'), 'http://x:3333/health')
|
|
41
|
-
assert.equal(joinUrl('', '/v1/search'), `${DEFAULT_BASE_URL}/v1/search`)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('buildHeaders adds bearer token only when set', () => {
|
|
45
|
-
assert.equal(buildHeaders().authorization, undefined)
|
|
46
|
-
assert.equal(buildHeaders('tok').authorization, 'Bearer tok')
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
test('client.health() GETs /health without auth and maps ok/error', async () => {
|
|
50
|
-
const up = mockFetch({ json: { status: 'ok', searxng: 'not_configured' } })
|
|
51
|
-
const c = new WigoloClient({ fetchImpl: up })
|
|
52
|
-
const h = await c.health()
|
|
53
|
-
assert.equal(h.ok, true)
|
|
54
|
-
assert.equal(up.calls[0].url, `${DEFAULT_BASE_URL}/health`)
|
|
55
|
-
|
|
56
|
-
const down = mockFetch(() => { throw new Error('ECONNREFUSED') })
|
|
57
|
-
const h2 = await new WigoloClient({ fetchImpl: down }).health()
|
|
58
|
-
assert.equal(h2.ok, false)
|
|
59
|
-
assert.match(h2.error, /ECONNREFUSED/)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('client.search() POSTs query (+ array) to /v1/search with token header', async () => {
|
|
63
|
-
const f = mockFetch({ json: { results: [] } })
|
|
64
|
-
const c = new WigoloClient({ token: 'tok', fetchImpl: f })
|
|
65
|
-
await c.search(['a', 'b'], { time_range: 'week', max_results: 5 })
|
|
66
|
-
assert.equal(f.calls[0].url, `${DEFAULT_BASE_URL}/v1/search`)
|
|
67
|
-
assert.equal(f.calls[0].init.method, 'POST')
|
|
68
|
-
assert.equal(f.calls[0].init.headers.authorization, 'Bearer tok')
|
|
69
|
-
const body = JSON.parse(f.calls[0].init.body)
|
|
70
|
-
assert.deepEqual(body.query, ['a', 'b'])
|
|
71
|
-
assert.equal(body.time_range, 'week')
|
|
72
|
-
assert.equal(body.max_results, 5)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test('client maps non-2xx to WigoloApiError with status', async () => {
|
|
76
|
-
const f = mockFetch({ status: 500, text: 'boom' })
|
|
77
|
-
const c = new WigoloClient({ fetchImpl: f })
|
|
78
|
-
await assert.rejects(() => c.fetch('https://x'), (e) => {
|
|
79
|
-
assert.ok(e instanceof WigoloApiError)
|
|
80
|
-
assert.equal(e.status, 500)
|
|
81
|
-
return true
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
test('client.watch() sends action + url for create/list/remove', async () => {
|
|
86
|
-
const f = mockFetch({ json: { id: 'w1' } })
|
|
87
|
-
const c = new WigoloClient({ fetchImpl: f })
|
|
88
|
-
await c.watch('create', { url: 'https://x', interval: '1h' })
|
|
89
|
-
assert.equal(JSON.parse(f.calls[0].init.body).action, 'create')
|
|
90
|
-
await c.watch('list')
|
|
91
|
-
assert.equal(JSON.parse(f.calls[1].init.body).action, 'list')
|
|
92
|
-
await c.watch('remove', { id: 'w1' })
|
|
93
|
-
assert.equal(JSON.parse(f.calls[2].init.body).action, 'remove')
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
// ─── sidecar ────────────────────────────────────────────────────────────────
|
|
97
|
-
|
|
98
|
-
test('buildServePlan is lean by default (WIGOLO_NO_WARMUP=1, no token)', () => {
|
|
99
|
-
const p = buildServePlan({})
|
|
100
|
-
assert.equal(p.command, 'npx')
|
|
101
|
-
assert.deepEqual(p.args.slice(0, 3), ['-y', 'wigolo', 'serve'])
|
|
102
|
-
assert.equal(p.env.WIGOLO_NO_WARMUP, '1')
|
|
103
|
-
assert.equal(p.env.WIGOLO_API_TOKEN, undefined)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test('buildServePlan honors port/host/token and warmup=true omits the no-warmup flag', () => {
|
|
107
|
-
const p = buildServePlan({ port: 3477, host: '0.0.0.0', token: 't', warmup: true })
|
|
108
|
-
assert.ok(p.args.includes('3477'))
|
|
109
|
-
assert.equal(p.env.WIGOLO_NO_WARMUP, undefined)
|
|
110
|
-
assert.equal(p.env.WIGOLO_API_TOKEN, 't')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
test('sidecar.start() spawns detached + unref and is idempotent', async () => {
|
|
114
|
-
const spawned = []
|
|
115
|
-
const spawnImpl = (cmd, args, opts) => { spawned.push({ cmd, args, opts }); return { unref() {}, kill() {} } }
|
|
116
|
-
const sc = new WigoloSidecar({ spawnImpl, log: () => {} })
|
|
117
|
-
await sc.start()
|
|
118
|
-
await sc.start() // idempotent — no second spawn
|
|
119
|
-
assert.equal(spawned.length, 1)
|
|
120
|
-
assert.equal(spawned[0].opts.detached, true)
|
|
121
|
-
assert.equal(sc.isRunning(), true)
|
|
122
|
-
assert.equal(sc.status().warmup, 'lean (no warmup)')
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
test('sidecar.stop() kills the process', async () => {
|
|
126
|
-
let killed = false
|
|
127
|
-
const spawnImpl = () => ({ unref() {}, kill() { killed = true } })
|
|
128
|
-
const sc = new WigoloSidecar({ spawnImpl, log: () => {} })
|
|
129
|
-
await sc.start()
|
|
130
|
-
await sc.stop()
|
|
131
|
-
assert.equal(killed, true)
|
|
132
|
-
assert.equal(sc.isRunning(), false)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
// ─── plugin glue ────────────────────────────────────────────────────────────
|
|
136
|
-
|
|
137
|
-
function makeCtx(fetchImpl, settings = {}, spawnProcess) {
|
|
138
|
-
const tools = new Map()
|
|
139
|
-
const triggers = []
|
|
140
|
-
const panels = []
|
|
141
|
-
const logs = []
|
|
142
|
-
const ctx = {
|
|
143
|
-
settings: { webIntel: settings },
|
|
144
|
-
fetchImpl,
|
|
145
|
-
registerTool: (t) => tools.set(t.name, t),
|
|
146
|
-
registerTrigger: (t) => triggers.push(t),
|
|
147
|
-
registerPanel: (p) => panels.push(p),
|
|
148
|
-
log: (l) => logs.push(l),
|
|
149
|
-
...(spawnProcess ? { spawnProcess } : {}),
|
|
150
|
-
}
|
|
151
|
-
return { tools, triggers, panels, logs, ctx }
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
test('resolveConfig reads the webIntel block with lean defaults', () => {
|
|
155
|
-
const c = resolveConfig({ settings: { webIntel: { restUrl: ' http://x:3477/ ', warmupOnInit: true, autoStart: false } } })
|
|
156
|
-
assert.equal(c.restUrl, 'http://x:3477', 'restUrl trimmed of whitespace + trailing slash')
|
|
157
|
-
assert.equal(c.warmupOnInit, true)
|
|
158
|
-
assert.equal(c.autoStart, false)
|
|
159
|
-
const d = resolveConfig({ settings: {} })
|
|
160
|
-
assert.equal(d.enabled, true)
|
|
161
|
-
assert.equal(d.autoStart, true)
|
|
162
|
-
assert.equal(d.warmupOnInit, false)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
test('register wires 9 tools, 1 trigger, 1 panel', () => {
|
|
166
|
-
const { tools, triggers, panels, ctx } = makeCtx(mockFetch({ json: {} }))
|
|
167
|
-
register(ctx)
|
|
168
|
-
assert.equal(tools.size, 9)
|
|
169
|
-
for (const n of ['webintel_health', 'web_search', 'web_fetch', 'web_crawl', 'web_research', 'web_find_similar', 'web_watch_add', 'web_watch_list', 'web_watch_remove']) assert.ok(tools.has(n), `missing ${n}`)
|
|
170
|
-
assert.equal(triggers.length, 1)
|
|
171
|
-
assert.equal(panels.length, 1)
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
test('web_search returns normalized ranked results', async () => {
|
|
175
|
-
const f = mockFetch((url) => url.endsWith('/health')
|
|
176
|
-
? { json: { status: 'ok' } }
|
|
177
|
-
: { json: { results: [{ title: 'A', url: 'https://a', excerpt: 'x'.repeat(300), citation_id: 'src-1', evidence_score: { final: 0.9 } }], freshness_signal: { published: '2026-07-01' } } })
|
|
178
|
-
const { tools, ctx } = makeCtx(f)
|
|
179
|
-
register(ctx)
|
|
180
|
-
const r = await tools.get('web_search').handler({ query: 'cisco bgp error' })
|
|
181
|
-
assert.equal(r.results.length, 1)
|
|
182
|
-
assert.equal(r.results[0].citation, 'src-1')
|
|
183
|
-
assert.equal(r.results[0].score, 0.9)
|
|
184
|
-
assert.ok(r.results[0].excerpt.length <= 240)
|
|
185
|
-
assert.equal(r.freshness.published, '2026-07-01')
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
test('web_research returns the evidence brief (synthesis left to RTerm agent)', async () => {
|
|
189
|
-
const f = mockFetch((url) => url.endsWith('/health')
|
|
190
|
-
? { json: { status: 'ok' } }
|
|
191
|
-
: { json: { question: 'q', evidence: [{ title: 'S', url: 'https://s', snippet: 'ev' }], citations: [{ id: 'src-1', url: 'https://s' }] } })
|
|
192
|
-
const { tools, ctx } = makeCtx(f)
|
|
193
|
-
register(ctx)
|
|
194
|
-
const r = await tools.get('web_research').handler({ question: 'is rijndael128-cbc safe' })
|
|
195
|
-
assert.equal(r.evidence.length, 1)
|
|
196
|
-
assert.equal(r.citations.length, 1)
|
|
197
|
-
assert.match(r.note, /RTerm agent/)
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
test('web_fetch surfaces a blocked page honestly', async () => {
|
|
201
|
-
const f = mockFetch((url) => url.endsWith('/health')
|
|
202
|
-
? { json: { status: 'ok' } }
|
|
203
|
-
: { json: { url: 'https://x', blocked_by_challenge: true, markdown: '' } })
|
|
204
|
-
const { tools, ctx } = makeCtx(f)
|
|
205
|
-
register(ctx)
|
|
206
|
-
const r = await tools.get('web_fetch').handler({ url: 'https://x' })
|
|
207
|
-
assert.equal(r.blocked, true)
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
test('every web_* tool returns error+hint when daemon is down and no spawn (no throw)', async () => {
|
|
211
|
-
const down = mockFetch(() => { throw new Error('ECONNREFUSED') })
|
|
212
|
-
const { tools, ctx } = makeCtx(down, { autoStart: true }) // no spawnProcess → can't start
|
|
213
|
-
register(ctx)
|
|
214
|
-
const r = await tools.get('web_search').handler({ query: 'x' })
|
|
215
|
-
assert.ok(r.error)
|
|
216
|
-
assert.match(r.hint, /wigolo daemon/)
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
test('web_search auto-starts the daemon via spawnProcess then serves', async () => {
|
|
220
|
-
let healthy = false
|
|
221
|
-
const spawned = []
|
|
222
|
-
const f = mockFetch((url) => url.endsWith('/health')
|
|
223
|
-
? (healthy ? { json: { status: 'ok' } } : (() => { throw new Error('down') })())
|
|
224
|
-
: { json: { results: [] } })
|
|
225
|
-
const spawnProcess = (cmd, args, opts) => { spawned.push(true); healthy = true; return { unref() {}, kill() {} } }
|
|
226
|
-
const { tools, ctx } = makeCtx(f, { autoStart: true }, spawnProcess)
|
|
227
|
-
register(ctx)
|
|
228
|
-
const r = await tools.get('web_search').handler({ query: 'x' })
|
|
229
|
-
assert.equal(spawned.length, 1)
|
|
230
|
-
assert.ok(Array.isArray(r.results))
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
test('webintel_page_changed trigger matches only webintel change events', () => {
|
|
234
|
-
const { triggers, ctx } = makeCtx(mockFetch({ json: {} }))
|
|
235
|
-
register(ctx)
|
|
236
|
-
const m = triggers[0].match
|
|
237
|
-
assert.equal(m({ source: 'webintel', changed: true }), true)
|
|
238
|
-
assert.equal(m({ source: 'webintel', kind: 'page_changed' }), true)
|
|
239
|
-
assert.equal(m({ source: 'agentspan', changed: true }), false)
|
|
240
|
-
assert.equal(m({ source: 'webintel', changed: false }), false)
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
// ─── normalization helpers ─────────────────────────────────────────────────
|
|
244
|
-
|
|
245
|
-
test('toResultRows normalizes + truncates excerpts', () => {
|
|
246
|
-
const rows = toResultRows({ results: [{ url: 'https://a', description: 'y'.repeat(400) }] })
|
|
247
|
-
assert.equal(rows.length, 1)
|
|
248
|
-
assert.ok(rows[0].excerpt.length <= 240)
|
|
249
|
-
assert.equal(toResultRows({}).length, 0)
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
test('toResearchBrief handles empty payload', () => {
|
|
253
|
-
assert.deepEqual(toResearchBrief(null).evidence, [])
|
|
254
|
-
assert.equal(toResearchBrief({ evidence: [] }).evidence.length, 0)
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
test('toWatchRows normalizes watch entries', () => {
|
|
258
|
-
const rows = toWatchRows({ watches: [{ id: 'w1', url: 'https://x', changed: true, last_checked: '2026-07-28' }] })
|
|
259
|
-
assert.equal(rows.length, 1)
|
|
260
|
-
assert.equal(rows[0].changed, true)
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
console.log('web-intel: all cases passed')
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* wigoloClient.mjs — a minimal, dependency-free HTTP client for the wigolo web
|
|
3
|
-
* intelligence daemon (`wigolo serve`, default http://127.0.0.1:3333).
|
|
4
|
-
*
|
|
5
|
-
* wigolo exposes one REST route per tool: POST /v1/{search,fetch,crawl,cache,
|
|
6
|
-
* extract,find_similar,research,agent,diff,watch}, GET /health, GET /v1/tools.
|
|
7
|
-
* This client is pure + injectable (a `fetchImpl` is passed in) so it is fully
|
|
8
|
-
* unit-testable offline with a mocked fetch — no runtime network baked in.
|
|
9
|
-
*
|
|
10
|
-
* Auth: when the daemon is started with WIGOLO_API_TOKEN, every /v1 request
|
|
11
|
-
* needs `Authorization: Bearer <token>` (/health stays open). The client sends
|
|
12
|
-
* the header only when a token is provided.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export const DEFAULT_BASE_URL = 'http://127.0.0.1:3333'
|
|
16
|
-
|
|
17
|
-
/** Build request headers (adds the bearer token only when set). */
|
|
18
|
-
export function buildHeaders(token) {
|
|
19
|
-
const h = { 'content-type': 'application/json', accept: 'application/json' }
|
|
20
|
-
if (token) h.authorization = `Bearer ${token}`
|
|
21
|
-
return h
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Join a base URL + path safely (single slash). */
|
|
25
|
-
export function joinUrl(base, path) {
|
|
26
|
-
const b = String(base || DEFAULT_BASE_URL).replace(/\/+$/, '')
|
|
27
|
-
const p = String(path || '').startsWith('/') ? String(path) : `/${path}`
|
|
28
|
-
return `${b}${p}`
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function parseBody(res) {
|
|
32
|
-
const text = await res.text()
|
|
33
|
-
if (!text) return null
|
|
34
|
-
try { return JSON.parse(text) } catch { return text }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class WigoloApiError extends Error {
|
|
38
|
-
constructor(status, path, body) {
|
|
39
|
-
super(`wigolo ${status} ${path}: ${typeof body === 'string' ? body.slice(0, 300) : JSON.stringify(body)?.slice(0, 300)}`)
|
|
40
|
-
this.status = status
|
|
41
|
-
this.path = path
|
|
42
|
-
this.body = body
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export class WigoloClient {
|
|
47
|
-
/**
|
|
48
|
-
* @param {{ baseUrl?: string, token?: string, fetchImpl: Function }} opts
|
|
49
|
-
* fetchImpl(url, {method, headers, body}) -> Promise<{ok,status,text:()=>Promise<string>}>
|
|
50
|
-
*/
|
|
51
|
-
constructor(opts = {}) {
|
|
52
|
-
if (typeof opts.fetchImpl !== 'function') throw new Error('WigoloClient needs a fetchImpl')
|
|
53
|
-
this.baseUrl = opts.baseUrl || DEFAULT_BASE_URL
|
|
54
|
-
this.token = opts.token
|
|
55
|
-
this.fetchImpl = opts.fetchImpl
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async #post(path, payload) {
|
|
59
|
-
const res = await this.fetchImpl(joinUrl(this.baseUrl, path), {
|
|
60
|
-
method: 'POST',
|
|
61
|
-
headers: buildHeaders(this.token),
|
|
62
|
-
body: JSON.stringify(payload ?? {}),
|
|
63
|
-
})
|
|
64
|
-
const body = await parseBody(res)
|
|
65
|
-
if (!res.ok) throw new WigoloApiError(res.status, path, body)
|
|
66
|
-
return body
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async #get(path) {
|
|
70
|
-
const res = await this.fetchImpl(joinUrl(this.baseUrl, path), {
|
|
71
|
-
method: 'GET',
|
|
72
|
-
headers: buildHeaders(this.token),
|
|
73
|
-
})
|
|
74
|
-
const body = await parseBody(res)
|
|
75
|
-
if (!res.ok) throw new WigoloApiError(res.status, path, body)
|
|
76
|
-
return body
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Liveness + component status. Always open (no token). */
|
|
80
|
-
async health() {
|
|
81
|
-
try {
|
|
82
|
-
const body = await this.#get('/health')
|
|
83
|
-
return { ok: true, status: body }
|
|
84
|
-
} catch (e) {
|
|
85
|
-
return { ok: false, error: e?.message ?? String(e) }
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** List the daemon's tools (descriptions + endpoints). */
|
|
90
|
-
async tools() {
|
|
91
|
-
return this.#get('/v1/tools')
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Multi-engine web search. `query` is a string or an array (parallel breadth). */
|
|
95
|
-
async search(query, opts = {}) {
|
|
96
|
-
return this.#post('/v1/search', { query, ...opts })
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Fetch one URL as clean markdown (tiered router escalates to the browser engine). */
|
|
100
|
-
async fetch(url, opts = {}) {
|
|
101
|
-
return this.#post('/v1/fetch', { url, ...opts })
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Multi-page crawl (BFS/DFS/sitemap/map-only). */
|
|
105
|
-
async crawl(url, opts = {}) {
|
|
106
|
-
return this.#post('/v1/crawl', { url, ...opts })
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Structured extraction (tables, metadata, JSON-LD, named/custom schema). */
|
|
110
|
-
async extract(url, opts = {}) {
|
|
111
|
-
return this.#post('/v1/extract', { url, ...opts })
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** Pages similar to a URL/concept (keyword + semantic + live web fusion). */
|
|
115
|
-
async findSimilar(input, opts = {}) {
|
|
116
|
-
return this.#post('/v1/find_similar', typeof input === 'string' ? { url: input, ...opts } : { ...input, ...opts })
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Query the local cache of everything already seen (keyword or hybrid semantic). */
|
|
120
|
-
async cache(opts = {}) {
|
|
121
|
-
return this.#post('/v1/cache', opts)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** Decompose → fan out → fetch → return a structured brief + evidence.
|
|
125
|
-
* (Synthesis is done by the HOST agent, not wigolo's LLM — we pass no LLM key,
|
|
126
|
-
* so wigolo returns the raw brief + evidence and RTerm's agent writes the answer.) */
|
|
127
|
-
async research(question, opts = {}) {
|
|
128
|
-
return this.#post('/v1/research', { question, ...opts })
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** Autonomous gather loop (plan → search → fetch → extract) with a step log. */
|
|
132
|
-
async agent(goal, opts = {}) {
|
|
133
|
-
return this.#post('/v1/agent', { goal, ...opts })
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** Diff two page snapshots (or a page vs its last-seen cached version). */
|
|
137
|
-
async diff(input, opts = {}) {
|
|
138
|
-
return this.#post('/v1/diff', typeof input === 'string' ? { url: input, ...opts } : { ...input, ...opts })
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** Watch management: action=create|list|remove. */
|
|
142
|
-
async watch(action, opts = {}) {
|
|
143
|
-
return this.#post('/v1/watch', { action, ...opts })
|
|
144
|
-
}
|
|
145
|
-
}
|