@fibscope/agent 0.1.0
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/.env.example +7 -0
- package/PUBLISH.md +27 -0
- package/README.md +123 -0
- package/index.mjs +3244 -0
- package/lib/bridge/recommendation.mjs +311 -0
- package/lib/fnn-discovery.mjs +293 -0
- package/lib/observe/collector.mjs +1039 -0
- package/lib/pulse/engine.mjs +21 -0
- package/lib/pulse/index.mjs +6 -0
- package/lib/pulse/intelligence.mjs +154 -0
- package/lib/pulse/providers.mjs +321 -0
- package/lib/pulse/server.mjs +54 -0
- package/lib/pulse/snapshot.mjs +155 -0
- package/lib/route/route.mjs +1053 -0
- package/package.json +29 -0
package/.env.example
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# fibscope agent defaults for a node owner's machine.
|
|
2
|
+
# The Fibscope endpoint is built into the published agent.
|
|
3
|
+
FIBKEY=replace-with-token-issued-by-platform
|
|
4
|
+
FIBSCOPE_AGENT_CHAIN=testnet
|
|
5
|
+
FIBSCOPE_AGENT_FIBER_RPC_URL=http://127.0.0.1:8227
|
|
6
|
+
FIBSCOPE_AGENT_PUSH_INTERVAL_MS=15000
|
|
7
|
+
FIBSCOPE_AGENT_PUBLIC_PROFILE=false
|
package/PUBLISH.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Publish Checklist
|
|
2
|
+
|
|
3
|
+
Run from the repository root unless noted.
|
|
4
|
+
|
|
5
|
+
```powershell
|
|
6
|
+
npm --prefix packages/agent run check
|
|
7
|
+
npm --prefix packages/agent run pack:dry-run
|
|
8
|
+
cd packages/agent
|
|
9
|
+
npm publish --dry-run --access public
|
|
10
|
+
npm login
|
|
11
|
+
npm publish --access public
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
After publish:
|
|
15
|
+
|
|
16
|
+
```powershell
|
|
17
|
+
npx @fibscope/agent --help
|
|
18
|
+
npx @fibscope/agent init
|
|
19
|
+
npx @fibscope/agent status
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Notes:
|
|
23
|
+
|
|
24
|
+
- Package name: `@fibscope/agent`
|
|
25
|
+
- Commands: `agent` and `fibscope-agent`
|
|
26
|
+
- Reads config from `agent/.env`, `.env`, or `.fiber/agent.json` in the current working directory.
|
|
27
|
+
- FNN RPC should stay bound to localhost.
|
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Fibscope Agent
|
|
2
|
+
|
|
3
|
+
Independent Node.js ESM agent for Fiber node owners.
|
|
4
|
+
|
|
5
|
+
It runs beside an existing Fiber node, collects local Fiber state, builds an observability report, and pushes that report to Fibscope.
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
Fiber RPC -> Agent -> Fibscope HTTPS endpoint
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The agent is the only component that talks to local Fiber RPC. Fibscope never reaches into the node owner's machine; it only receives pushed reports from this agent.
|
|
12
|
+
|
|
13
|
+
## Config
|
|
14
|
+
|
|
15
|
+
Local personal-development defaults live in `agent/.env`:
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
FIBKEY=raw-token-issued-by-platform
|
|
19
|
+
FIBSCOPE_AGENT_CHAIN=testnet
|
|
20
|
+
FIBSCOPE_AGENT_FIBER_RPC_URL=http://127.0.0.1:8247
|
|
21
|
+
FIBSCOPE_AGENT_PUSH_INTERVAL_MS=15000
|
|
22
|
+
FIBSCOPE_AGENT_PUBLIC_PROFILE=false
|
|
23
|
+
FIBSCOPE_AGENT_OVERWRITE_NODE_REGISTRATION=false
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
This file belongs to the node owner's machine. The Fibscope service endpoint is built into the published agent, so node owners do not need to configure a report URL.
|
|
27
|
+
|
|
28
|
+
The agent also supports `.fiber/agent.json`:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"agentToken": "raw-token-issued-by-platform",
|
|
33
|
+
"chain": "testnet",
|
|
34
|
+
"fiberRpcUrl": "http://127.0.0.1:8247",
|
|
35
|
+
"peerAddress": "/ip4/127.0.0.1/tcp/8248",
|
|
36
|
+
"pushIntervalMs": 15000,
|
|
37
|
+
"publicProfileEnabled": true,
|
|
38
|
+
"overwriteNodeRegistration": false,
|
|
39
|
+
"publicFields": {
|
|
40
|
+
"node": true,
|
|
41
|
+
"peers": true,
|
|
42
|
+
"channels": true,
|
|
43
|
+
"liquidity": true,
|
|
44
|
+
"diagnostics": true,
|
|
45
|
+
"health": true,
|
|
46
|
+
"metrics": true,
|
|
47
|
+
"alerts": true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`peerAddress` is the Fiber dial address advertised to Fibscope for public routing and channel creation. For local duo development this is usually a loopback multiaddr like `/ip4/127.0.0.1/tcp/8228`; for an internet-facing public node, set it to an address other nodes can actually dial.
|
|
53
|
+
|
|
54
|
+
## Commands
|
|
55
|
+
|
|
56
|
+
```powershell
|
|
57
|
+
npm run agent:init
|
|
58
|
+
npm run agent:start
|
|
59
|
+
npm run agent:once
|
|
60
|
+
npm run agent:status
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Direct usage:
|
|
64
|
+
|
|
65
|
+
```powershell
|
|
66
|
+
node packages/agent/index.mjs init
|
|
67
|
+
node packages/agent/index.mjs start
|
|
68
|
+
node packages/agent/index.mjs once
|
|
69
|
+
node packages/agent/index.mjs status
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Push Payload
|
|
73
|
+
|
|
74
|
+
The agent pushes to `POST /agent/v1/report` with:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"agentVersion": "0.1.0",
|
|
79
|
+
"chain": "testnet",
|
|
80
|
+
"collectedAt": 1710000000000,
|
|
81
|
+
"node": {},
|
|
82
|
+
"peers": [],
|
|
83
|
+
"channels": [],
|
|
84
|
+
"liquidity": {},
|
|
85
|
+
"diagnostics": [],
|
|
86
|
+
"health": {},
|
|
87
|
+
"metrics": {},
|
|
88
|
+
"alerts": []
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Fibscope authenticates this with `x-agent-token`. This is an agent key for local node reporting, not the external application API key that apps will use for quote and payment execution.
|
|
93
|
+
|
|
94
|
+
Before the first push, the agent registers the local Fiber node with `POST /agent/v1/register`. That saves the node owner, Fiber node id, display name, chain, public profile setting, and the latest local node details in the hosted database. If the agent key is already attached to a different registered Fiber node, set `overwriteNodeRegistration` to `true` only when you intentionally want this agent to replace that old node binding.
|
|
95
|
+
|
|
96
|
+
## Resilience
|
|
97
|
+
|
|
98
|
+
Collection and transmission are independent loops:
|
|
99
|
+
|
|
100
|
+
- collection runs every `pushIntervalMs`
|
|
101
|
+
- transmission retries retained reports independently
|
|
102
|
+
- failed pushes stay in memory
|
|
103
|
+
- backoff doubles up to 5 minutes
|
|
104
|
+
- `409 Conflict` is treated as a stale report response
|
|
105
|
+
|
|
106
|
+
The local status file is `.fiber/agent-status.json`.
|
|
107
|
+
|
|
108
|
+
## NPM Usage
|
|
109
|
+
|
|
110
|
+
```powershell
|
|
111
|
+
npm install -g @fibscope/agent
|
|
112
|
+
agent init
|
|
113
|
+
agent start
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Or run without a global install:
|
|
117
|
+
|
|
118
|
+
```powershell
|
|
119
|
+
npx @fibscope/agent init
|
|
120
|
+
npx @fibscope/agent start
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The package reads `agent/.env`, `.env`, or `.fiber/agent.json` from the directory where you run the command. Keep FNN RPC local, for example `http://127.0.0.1:8227`.
|