@johnhenry/browsermesh-apps 0.11.0 → 0.13.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/README.md +645 -12
- package/package.json +3 -1
- package/src/index.mjs +15 -5
- package/src/mesh-bootstrap.mjs +12 -6
- package/src/mesh-orchestrator-tools.mjs +77 -10
- package/src/mesh-orchestrator.mjs +1 -1
- package/src/mesh-torrent.mjs +306 -53
- package/src/orchestrator.mjs +895 -6
- package/src/payments.mjs +20 -9
- package/src/peer-escrow.mjs +49 -11
- package/src/peer-payments.mjs +16 -9
- package/src/peer-timestamp.mjs +11 -3
- package/src/peer-torrent.mjs +58 -28
- package/src/pod-host-gateway.mjs +372 -0
- package/src/pod-host-routes.mjs +630 -0
- package/src/pod-host-service.mjs +732 -0
- package/src/pod-supervisor.mjs +784 -0
- package/src/resources.mjs +107 -2
- package/src/tools.mjs +73 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/browsermesh-apps",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Application layer: marketplace, chat, payments, compute, orchestration, and agent tools for BrowserMesh",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@johnhenry/browsermesh-primitives": ">=0.2.0 <1.0.0",
|
|
31
|
+
"@johnhenry/browsermesh-pod": ">=0.1.0 <1.0.0",
|
|
31
32
|
"@johnhenry/browsermesh-core": ">=0.5.0 <1.0.0",
|
|
32
33
|
"@johnhenry/browsermesh-transport": ">=0.1.0 <1.0.0",
|
|
33
34
|
"@johnhenry/browsermesh-sync": ">=0.0.0 <1.0.0",
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"@johnhenry/andbox": ">=0.0.1 <1.0.0",
|
|
62
|
+
"@johnhenry/browsermesh-pod": "^0.1.0",
|
|
61
63
|
"node-datachannel": "^0.33.4",
|
|
62
64
|
"fake-indexeddb": "^6.2.5",
|
|
63
65
|
"webgpu": "^0.6.1"
|
package/src/index.mjs
CHANGED
|
@@ -62,6 +62,10 @@ export * from './serverless-peer-select.mjs';
|
|
|
62
62
|
export * from './serverless-sites.mjs';
|
|
63
63
|
export * from './observability-bridge.mjs';
|
|
64
64
|
export * from './mesh-kv.mjs';
|
|
65
|
+
export * from './pod-host-service.mjs';
|
|
66
|
+
export * from './pod-host-routes.mjs';
|
|
67
|
+
export * from './pod-host-gateway.mjs';
|
|
68
|
+
export * from './pod-supervisor.mjs';
|
|
65
69
|
export * from './peer-payments.mjs';
|
|
66
70
|
export * from './peer-registry.mjs';
|
|
67
71
|
export * from './peer-routing.mjs';
|
|
@@ -75,10 +79,16 @@ export { BrowserTool, BrowserToolRegistry } from './compat.mjs';
|
|
|
75
79
|
export * from './agent-runtime.mjs';
|
|
76
80
|
export * from './mesh-orchestrator-tools.mjs';
|
|
77
81
|
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
82
|
+
// One implementation per public name:
|
|
83
|
+
//
|
|
84
|
+
// CreditLedger payments.mjs single owner: one pod, one balance
|
|
85
|
+
// EscrowManager peer-escrow.mjs conditional escrow that moves funds
|
|
86
|
+
//
|
|
87
|
+
// The other two models keep their own, unambiguous names (also exported through
|
|
88
|
+
// the `export *` lines above): `MultiPartyCreditLedger` (peer-payments.mjs, a
|
|
89
|
+
// book of every peer's balance) and `SimpleEscrowBook` (payments.mjs, the flat
|
|
90
|
+
// record `PaymentRouter` keeps). Neither module defines a `CreditLedger` or
|
|
91
|
+
// `EscrowManager` any more, so no `export *` here is ambiguous; the explicit
|
|
92
|
+
// lines below just say which file each canonical name comes from.
|
|
83
93
|
export { CreditLedger } from './payments.mjs';
|
|
84
94
|
export { EscrowManager } from './peer-escrow.mjs';
|
package/src/mesh-bootstrap.mjs
CHANGED
|
@@ -578,7 +578,8 @@ import { registerOrchestratorTools } from './mesh-orchestrator-tools.mjs'
|
|
|
578
578
|
* Passed straight through to `createTorrentService()`
|
|
579
579
|
* (`trackerUrl`/`chunkSize`/`envelopeType`/`manifestTimeoutMs`/`chunkTimeoutMs`,
|
|
580
580
|
* plus the hooks `chunkStore`/`manifestStore`/`authorize`/`maxConcurrentServes`/
|
|
581
|
-
* `maxConcurrentServesPerPeer`/`maxBytesPerPeerPerSec`/`maxAnnouncesPerPeerPerMinute
|
|
581
|
+
* `maxConcurrentServesPerPeer`/`maxBytesPerPeerPerSec`/`maxAnnouncesPerPeerPerMinute`,
|
|
582
|
+
* and `downloadConcurrency`/`maxManifestChunks`/`maxManifestSize`/`maxRemoteManifests`/`webtorrent`).
|
|
582
583
|
* @param {boolean} [options.enableEscrow=false] - Attach `peer-escrow.mjs`'s
|
|
583
584
|
* `createEscrowService()` (issue #117): real escrow-contract create/
|
|
584
585
|
* release/refund/dispute against `escrowOptions.creditLedger`, with
|
|
@@ -590,9 +591,9 @@ import { registerOrchestratorTools } from './mesh-orchestrator-tools.mjs'
|
|
|
590
591
|
* @param {object} [options.escrowOptions] - Required when `enableEscrow`.
|
|
591
592
|
* Passed straight through to `createEscrowService()`
|
|
592
593
|
* (`creditLedger`/`onLog`/`envelopeType`/`requestTimeoutMs`) -- see that
|
|
593
|
-
* function's own doc comment. `escrowOptions.creditLedger` (
|
|
594
|
-
* `
|
|
595
|
-
* if it's missing.
|
|
594
|
+
* function's own doc comment. `escrowOptions.creditLedger` (a `CreditLedger`
|
|
595
|
+
* or `MultiPartyCreditLedger`, or anything `EscrowManager` accepts) is
|
|
596
|
+
* required; this function throws if it's missing.
|
|
596
597
|
* @param {boolean} [options.enableChat=false] - Attach `peer-chat.mjs`'s
|
|
597
598
|
* `createChatService()` (issue #84, Phase 9): P2P chat with optional
|
|
598
599
|
* message signing/verification, history, typing indicators, and an
|
|
@@ -1229,6 +1230,11 @@ export async function createMeshNode(options = {}) {
|
|
|
1229
1230
|
maxConcurrentServesPerPeer: torrentOptions?.maxConcurrentServesPerPeer,
|
|
1230
1231
|
maxBytesPerPeerPerSec: torrentOptions?.maxBytesPerPeerPerSec,
|
|
1231
1232
|
maxAnnouncesPerPeerPerMinute: torrentOptions?.maxAnnouncesPerPeerPerMinute,
|
|
1233
|
+
downloadConcurrency: torrentOptions?.downloadConcurrency,
|
|
1234
|
+
maxManifestChunks: torrentOptions?.maxManifestChunks,
|
|
1235
|
+
maxManifestSize: torrentOptions?.maxManifestSize,
|
|
1236
|
+
maxRemoteManifests: torrentOptions?.maxRemoteManifests,
|
|
1237
|
+
webtorrent: torrentOptions?.webtorrent,
|
|
1232
1238
|
onLog,
|
|
1233
1239
|
})
|
|
1234
1240
|
const torrentHandle = attachService(node, servicesNetwork, torrentDescriptor)
|
|
@@ -1272,7 +1278,7 @@ export async function createMeshNode(options = {}) {
|
|
|
1272
1278
|
if (!escrowOptions?.creditLedger) {
|
|
1273
1279
|
throw new Error(
|
|
1274
1280
|
'createMeshNode: options.escrowOptions.creditLedger is required when enableEscrow is true ' +
|
|
1275
|
-
'(
|
|
1281
|
+
'(a CreditLedger, a MultiPartyCreditLedger, or anything with debit()/credit() or charge()/credit() -- see peer-escrow.mjs\'s EscrowManager).',
|
|
1276
1282
|
)
|
|
1277
1283
|
}
|
|
1278
1284
|
const escrowDescriptor = createEscrowService({
|
|
@@ -1476,7 +1482,7 @@ export async function createMeshNode(options = {}) {
|
|
|
1476
1482
|
// exists (and is always empty at minimum) when this flag is set, so a
|
|
1477
1483
|
// caller wanting only its own non-orchestrator BrowserTools never has to
|
|
1478
1484
|
// opt into orchestrator wiring it doesn't want. Only pre-populated with the
|
|
1479
|
-
//
|
|
1485
|
+
// 15 real Meshctl*Tools when enableOrchestrator was ALSO set -- see
|
|
1480
1486
|
// mesh-orchestrator-tools.mjs's own doc comment for exactly which of those
|
|
1481
1487
|
// route through the orchestrator service's gated wire dispatch.
|
|
1482
1488
|
if (enableAgentRuntime) {
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* mesh-orchestrator-tools.mjs -- Phase 4 of the agent-runtime plan (issues
|
|
3
|
-
* #90/#92): registers `orchestrator.mjs`'s
|
|
3
|
+
* #90/#92): registers `orchestrator.mjs`'s 15 real `Meshctl*Tool` classes
|
|
4
4
|
* (`MeshctlPodsTool`/`MeshctlStatusTool`/`MeshctlExecTool`/`MeshctlDeployTool`/
|
|
5
5
|
* `MeshctlTopTool`/`MeshctlComputeTool`/`MeshctlExposeTool`/`MeshctlDrainTool`,
|
|
6
|
-
*
|
|
6
|
+
* plus issue #185 §8a item 4's hosted-pods control surface five --
|
|
7
|
+
* `MeshctlSpawnTool`/`MeshctlSnapshotTool`/`MeshctlRestoreTool`/
|
|
8
|
+
* `MeshctlHostedPodsTool`/`MeshctlHostsTool` -- plus item 6's supervisor two
|
|
9
|
+
* -- `MeshctlSuperviseTool`/`MeshctlSupervisedTool` -- built via that file's
|
|
10
|
+
* own `createMeshctlTools(orchestrator)` helper) into a
|
|
7
11
|
* `compat.mjs` `BrowserToolRegistry` (Phase 1), wired against a real, attached
|
|
8
12
|
* `MeshOrchestrator` (Phase 3, `mesh-orchestrator.mjs`'s `createOrchestratorService()`).
|
|
9
13
|
* Once registered, `agent-runtime.mjs`'s `createAgentRuntime({registry, llmFn})`
|
|
@@ -112,6 +116,52 @@
|
|
|
112
116
|
* protocol first (out of scope here, exactly per this plan's Phase 4 section).
|
|
113
117
|
*
|
|
114
118
|
* ---------------------------------------------------------------------------
|
|
119
|
+
* `meshctl_spawn`/`meshctl_snapshot`/`meshctl_restore`/`meshctl_hosted_pods`/
|
|
120
|
+
* `meshctl_hosts` -- issue #185 §8a item 4's hosted-pods control surface,
|
|
121
|
+
* ALSO ALWAYS WIRED STRAIGHT TO THE RAW INSTANCE, BUT FOR A DIFFERENT REASON
|
|
122
|
+
* THAN COMPUTE/EXPOSE
|
|
123
|
+
*
|
|
124
|
+
* `MeshctlSpawnTool`/`MeshctlSnapshotTool`/`MeshctlRestoreTool`/
|
|
125
|
+
* `MeshctlHostedPodsTool` call `orchestrator.spawnPod()`/`.snapshotPod()`/
|
|
126
|
+
* `.restorePod()`/`.listHostedPods()`; `MeshctlHostsTool` calls
|
|
127
|
+
* `orchestrator.listPodHosts()`. Like compute/expose, none of these five are
|
|
128
|
+
* part of `mesh-orchestrator.mjs`'s `RISKY_ACTIONS` wire protocol (still
|
|
129
|
+
* exactly `['exec', 'deploy', 'drain']`), so there is no `api.spawnPod`/etc.
|
|
130
|
+
* gated equivalent to prefer -- they are wired straight to the raw
|
|
131
|
+
* instance's own methods here regardless of which input shape is supplied.
|
|
132
|
+
*
|
|
133
|
+
* Unlike compute/expose, this is NOT a gating gap: `spawnPod()`/
|
|
134
|
+
* `snapshotPod()`/`restorePod()`/`listHostedPods()` dispatch over `pod-host-
|
|
135
|
+
* service.mjs`'s OWN mesh protocol (`createPodHostClient()` -> a real
|
|
136
|
+
* `sendTo()` round trip to the target host), and that service gates every
|
|
137
|
+
* verb itself via `ctx.registry.checkAccess(pubKey, resource, verb)` on the
|
|
138
|
+
* HOST side -- the real authorization path for hosted pods, independent of
|
|
139
|
+
* `mesh-orchestrator.mjs`'s own `RISKY_ACTIONS` gate entirely. An EACCES
|
|
140
|
+
* from a refused host surfaces through these tools exactly as it does
|
|
141
|
+
* calling `spawnPod()` directly (see `orchestrator.mjs`'s
|
|
142
|
+
* `formatPodHostError()`); nothing here re-adds or bypasses that gate.
|
|
143
|
+
* `meshctl_hosts` is the one read with no gate anywhere, by design -- it
|
|
144
|
+
* reads `describe()`-derived runtime-registry peers, and `describe()`
|
|
145
|
+
* itself is deliberately ungated (`pod-host-service.mjs`'s module doc
|
|
146
|
+
* comment: a peer must be able to find a host before asking to be granted
|
|
147
|
+
* anything on it).
|
|
148
|
+
*
|
|
149
|
+
* ---------------------------------------------------------------------------
|
|
150
|
+
* `meshctl_supervise`/`meshctl_supervised` -- issue #185 item 6, SAME
|
|
151
|
+
* REASONING AS THE FIVE ABOVE, ONE LEVEL UP
|
|
152
|
+
*
|
|
153
|
+
* `MeshctlSuperviseTool`/`MeshctlSupervisedTool` call
|
|
154
|
+
* `orchestrator.getSupervisor()` and then the returned `PodSupervisor`'s own
|
|
155
|
+
* `supervise()`/`list()` (`pod-supervisor.mjs`). `getSupervisor()` is
|
|
156
|
+
* ALWAYS wired straight to the raw instance here too -- not part of
|
|
157
|
+
* `RISKY_ACTIONS`, same as `spawnPod()` and friends. The gate a restart
|
|
158
|
+
* actually goes through is still `pod-host-service.mjs`'s `checkAccess()`,
|
|
159
|
+
* because `PodSupervisor#supervise()`/its restart path call
|
|
160
|
+
* `orchestrator.spawnPod()` internally -- "a restart is a new spawn request
|
|
161
|
+
* the host may refuse" (`pod-supervisor.mjs`'s own module doc comment)
|
|
162
|
+
* means there is nothing new to gate here either.
|
|
163
|
+
*
|
|
164
|
+
* ---------------------------------------------------------------------------
|
|
115
165
|
* No browser-only imports at module level.
|
|
116
166
|
*/
|
|
117
167
|
|
|
@@ -179,6 +229,21 @@ function buildToolFacade(orchestrator) {
|
|
|
179
229
|
// instance either way.
|
|
180
230
|
runComputeTask: (...args) => raw.runComputeTask(...args),
|
|
181
231
|
exposePod: (...args) => raw.exposePod(...args),
|
|
232
|
+
// meshctl_spawn/meshctl_snapshot/meshctl_restore/meshctl_hosted_pods/
|
|
233
|
+
// meshctl_hosts (issue #185 §8a item 4) -- gated by pod-host-
|
|
234
|
+
// service.mjs's own checkAccess() on the host side, not by this
|
|
235
|
+
// service's RISKY_ACTIONS; straight to the raw instance either way
|
|
236
|
+
// (see module doc comment's dedicated section for these five).
|
|
237
|
+
spawnPod: (...args) => raw.spawnPod(...args),
|
|
238
|
+
snapshotPod: (...args) => raw.snapshotPod(...args),
|
|
239
|
+
restorePod: (...args) => raw.restorePod(...args),
|
|
240
|
+
listHostedPods: (...args) => raw.listHostedPods(...args),
|
|
241
|
+
listPodHosts: (...args) => raw.listPodHosts(...args),
|
|
242
|
+
// meshctl_supervise/meshctl_supervised (issue #185 item 6) -- see the
|
|
243
|
+
// dedicated section above.
|
|
244
|
+
getSupervisor: (...args) => raw.getSupervisor(...args),
|
|
245
|
+
// MeshctlSpawnTool's auto host selection reads this too.
|
|
246
|
+
listComputeCandidates: (...args) => raw.listComputeCandidates(...args),
|
|
182
247
|
// MeshctlExposeTool reads `this.#orchestrator.peerNode` directly for
|
|
183
248
|
// its own default-podId fallback.
|
|
184
249
|
get peerNode() { return raw.peerNode },
|
|
@@ -200,11 +265,12 @@ function buildToolFacade(orchestrator) {
|
|
|
200
265
|
}
|
|
201
266
|
|
|
202
267
|
/**
|
|
203
|
-
* Construct all
|
|
268
|
+
* Construct all 15 `Meshctl*Tool` instances (`orchestrator.mjs`'s own
|
|
204
269
|
* `createMeshctlTools()`) against `orchestrator` and register each into
|
|
205
270
|
* `registry`. See module doc comment for the full design writeup (the two
|
|
206
|
-
* accepted `orchestrator` shapes, the exec/deploy/drain gating decision,
|
|
207
|
-
*
|
|
271
|
+
* accepted `orchestrator` shapes, the exec/deploy/drain gating decision, the
|
|
272
|
+
* compute/expose "not wired by Phase 3 at all" note, and the hosted-pods
|
|
273
|
+
* control surface's own gating section, including the supervisor pair).
|
|
208
274
|
*
|
|
209
275
|
* @param {import('./compat.mjs').BrowserToolRegistry} registry - REQUIRED.
|
|
210
276
|
* Duck-typed (`.register` a function), matching this package's established
|
|
@@ -213,9 +279,10 @@ function buildToolFacade(orchestrator) {
|
|
|
213
279
|
* @param {object} orchestrator - REQUIRED. Either `mesh-orchestrator.mjs`'s
|
|
214
280
|
* service `api` (recommended -- e.g. `node.orchestrator.api`) or a raw
|
|
215
281
|
* `MeshOrchestrator` instance -- see module doc comment.
|
|
216
|
-
* @returns {import('./orchestrator.mjs').BrowserTool[]} the
|
|
217
|
-
* instances, in `createMeshctlTools()`'s own order (pods, status,
|
|
218
|
-
* deploy, top, compute, expose, drain
|
|
282
|
+
* @returns {import('./orchestrator.mjs').BrowserTool[]} the 15 registered
|
|
283
|
+
* tool instances, in `createMeshctlTools()`'s own order (pods, status,
|
|
284
|
+
* exec, deploy, top, compute, expose, drain, spawn, snapshot, restore,
|
|
285
|
+
* hosted_pods, hosts, supervise, supervised).
|
|
219
286
|
*/
|
|
220
287
|
export function registerOrchestratorTools(registry, orchestrator) {
|
|
221
288
|
if (!registry || typeof registry.register !== 'function') {
|
|
@@ -235,11 +302,11 @@ export function registerOrchestratorTools(registry, orchestrator) {
|
|
|
235
302
|
|
|
236
303
|
/**
|
|
237
304
|
* Convenience factory: build a brand-new `BrowserToolRegistry` and
|
|
238
|
-
* pre-populate it with all
|
|
305
|
+
* pre-populate it with all 15 `Meshctl*Tool`s via `registerOrchestratorTools()`.
|
|
239
306
|
* Equivalent to `registerOrchestratorTools(new BrowserToolRegistry(), orchestrator)`,
|
|
240
307
|
* for a caller who doesn't already have a registry of their own to reuse (see
|
|
241
308
|
* `registerOrchestratorTools()` directly if you do -- e.g. to add
|
|
242
|
-
* non-orchestrator tools into the same registry alongside these
|
|
309
|
+
* non-orchestrator tools into the same registry alongside these 15).
|
|
243
310
|
*
|
|
244
311
|
* @param {object} orchestrator - See `registerOrchestratorTools()`.
|
|
245
312
|
* @returns {import('./compat.mjs').BrowserToolRegistry}
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
* arbitrary content deployed to this node's filesystem-adjacent skill
|
|
73
73
|
* store, and forcibly disconnecting/migrating this node's own workload,
|
|
74
74
|
* respectively) -- exactly `orchestrator.mjs`'s own header comment's
|
|
75
|
-
* "
|
|
75
|
+
* "thirteen `meshctl`-CLI-shaped agent tools", the three whose `BrowserTool`
|
|
76
76
|
* subclasses (`MeshctlExecTool`/`MeshctlDeployTool`/`MeshctlDrainTool`)
|
|
77
77
|
* already declare `get permission() { return 'network' }` (vs. `'read'` for
|
|
78
78
|
* the pods/status/top query tools). Before honoring an inbound
|