@nervur.org/installer-node 0.0.0-stage → 0.37.2
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 +105 -0
- package/README.md +159 -2
- package/SECURITY.md +8 -0
- package/bin/nervur.js +5 -0
- package/cargo/emscripten-module.wasm +0 -0
- package/cargo/manifest.json +1 -0
- package/cargo/sqlite3.wasm +0 -0
- package/cargo/table-i-i.wasm +0 -0
- package/cargo/table-i-ii.wasm +0 -0
- package/cargo/table-i-iii.wasm +0 -0
- package/cargo/table-i-iiii.wasm +0 -0
- package/cargo/table-i-iiiii.wasm +0 -0
- package/cargo/table-i-iiij.wasm +0 -0
- package/cargo/table-i-ij.wasm +0 -0
- package/cargo/table-v-ii.wasm +0 -0
- package/cargo/table-v-iii.wasm +0 -0
- package/cargo/worker.js +30808 -0
- package/organs/console/node/guard.d.ts +10 -0
- package/organs/console/node/guard.js +52 -0
- package/organs/console/node/index.d.ts +4 -0
- package/organs/console/node/index.js +5 -0
- package/organs/console/node/line.d.ts +16 -0
- package/organs/console/node/line.js +150 -0
- package/organs/console/node/main.js +51 -0
- package/organs/console/node/program.d.ts +1 -0
- package/organs/console/node/program.js +5 -0
- package/organs/console/node/proof.d.ts +15 -0
- package/organs/console/node/proof.js +84 -0
- package/organs/console/node/socket.d.ts +15 -0
- package/organs/console/node/socket.js +99 -0
- package/organs/disk/index.d.ts +1 -0
- package/organs/disk/index.js +2 -0
- package/organs/disk/node/files.js +162 -0
- package/organs/disk/node/main.js +20 -0
- package/organs/disk/node/program.d.ts +1 -0
- package/organs/disk/node/program.js +5 -0
- package/organs/disk/organ.d.ts +5 -0
- package/organs/disk/organ.js +69 -0
- package/organs/network/node/fill.d.ts +21 -0
- package/organs/network/node/fill.js +195 -0
- package/organs/network/node/flows.js +66 -0
- package/organs/network/node/half.js +260 -0
- package/organs/network/node/lines.d.ts +29 -0
- package/organs/network/node/lines.js +236 -0
- package/organs/network/node/link.d.ts +24 -0
- package/organs/network/node/link.js +215 -0
- package/organs/network/node/main.js +41 -0
- package/organs/network/node/moved.d.ts +2 -0
- package/organs/network/node/moved.js +20 -0
- package/organs/network/node/near.d.ts +63 -0
- package/organs/network/node/near.js +263 -0
- package/organs/network/node/program.d.ts +1 -0
- package/organs/network/node/program.js +5 -0
- package/organs/network/node/schemes.d.ts +1 -0
- package/organs/network/node/schemes.js +2 -0
- package/organs/network/node/sent.d.ts +13 -0
- package/organs/network/node/sent.js +101 -0
- package/organs/network/node/served.d.ts +19 -0
- package/organs/network/node/served.js +237 -0
- package/organs/screen/node/client.js +3 -0
- package/organs/screen/node/follow.js +266 -0
- package/organs/screen/node/frames.js +26 -0
- package/organs/screen/node/held.js +27 -0
- package/organs/screen/node/http.js +179 -0
- package/organs/screen/node/lay.js +116 -0
- package/organs/screen/node/leave.js +27 -0
- package/organs/screen/node/linked.js +69 -0
- package/organs/screen/node/listen.js +61 -0
- package/organs/screen/node/look.js +121 -0
- package/organs/screen/node/loop.js +154 -0
- package/organs/screen/node/main.js +74 -0
- package/organs/screen/node/mirror.js +112 -0
- package/organs/screen/node/notice.js +44 -0
- package/organs/screen/node/presser.js +11 -0
- package/organs/screen/node/presses.js +108 -0
- package/organs/screen/node/program.d.ts +1 -0
- package/organs/screen/node/program.js +5 -0
- package/organs/screen/node/shown.js +205 -0
- package/organs/screen/node/standing.js +29 -0
- package/organs/screen/node/state.js +80 -0
- package/organs/screen/node/tell.js +47 -0
- package/organs/screen/node/uid.js +65 -0
- package/organs/screen/node/worn.js +23 -0
- package/organs/shell/index.d.ts +1 -0
- package/organs/shell/index.js +2 -0
- package/organs/shell/node/main.js +26 -0
- package/organs/shell/node/output.js +70 -0
- package/organs/shell/node/pressure.js +14 -0
- package/organs/shell/node/program.d.ts +1 -0
- package/organs/shell/node/program.js +5 -0
- package/organs/shell/node/runs.js +220 -0
- package/organs/shell/node/told.js +70 -0
- package/organs/shell/organ.d.ts +5 -0
- package/organs/shell/organ.js +59 -0
- package/package.json +43 -4
- package/src/command/act.d.ts +31 -0
- package/src/command/act.js +261 -0
- package/src/command/answers.d.ts +3 -0
- package/src/command/answers.js +232 -0
- package/src/command/args.d.ts +14 -0
- package/src/command/args.js +220 -0
- package/src/command/arrive.d.ts +2 -0
- package/src/command/arrive.js +21 -0
- package/src/command/asked.d.ts +18 -0
- package/src/command/asked.js +49 -0
- package/src/command/backup.d.ts +18 -0
- package/src/command/backup.js +261 -0
- package/src/command/before.d.ts +40 -0
- package/src/command/before.js +249 -0
- package/src/command/born.d.ts +27 -0
- package/src/command/born.js +103 -0
- package/src/command/bridge.d.ts +19 -0
- package/src/command/bridge.js +152 -0
- package/src/command/chain.d.ts +9 -0
- package/src/command/chain.js +48 -0
- package/src/command/channel.d.ts +29 -0
- package/src/command/channel.js +263 -0
- package/src/command/choices.d.ts +35 -0
- package/src/command/choices.js +173 -0
- package/src/command/claim.d.ts +12 -0
- package/src/command/claim.js +46 -0
- package/src/command/commands.d.ts +16 -0
- package/src/command/commands.js +257 -0
- package/src/command/ends.d.ts +16 -0
- package/src/command/ends.js +78 -0
- package/src/command/follow.d.ts +12 -0
- package/src/command/follow.js +66 -0
- package/src/command/given.d.ts +39 -0
- package/src/command/given.js +53 -0
- package/src/command/held.d.ts +15 -0
- package/src/command/held.js +56 -0
- package/src/command/index.d.ts +1 -0
- package/src/command/index.js +203 -0
- package/src/command/jailer.d.ts +28 -0
- package/src/command/jailer.js +135 -0
- package/src/command/laid.d.ts +6 -0
- package/src/command/laid.js +31 -0
- package/src/command/left.d.ts +9 -0
- package/src/command/left.js +34 -0
- package/src/command/line.d.ts +7 -0
- package/src/command/line.js +39 -0
- package/src/command/link.d.ts +30 -0
- package/src/command/link.js +123 -0
- package/src/command/lobes.d.ts +1 -0
- package/src/command/lobes.js +10 -0
- package/src/command/locks.d.ts +17 -0
- package/src/command/locks.js +76 -0
- package/src/command/mcp/calls.d.ts +27 -0
- package/src/command/mcp/calls.js +155 -0
- package/src/command/mcp/notices.d.ts +22 -0
- package/src/command/mcp/notices.js +203 -0
- package/src/command/mcp/resources.d.ts +31 -0
- package/src/command/mcp/resources.js +108 -0
- package/src/command/mcp/server.d.ts +19 -0
- package/src/command/mcp/server.js +149 -0
- package/src/command/mcp/tools.d.ts +39 -0
- package/src/command/mcp/tools.js +131 -0
- package/src/command/mcp.d.ts +8 -0
- package/src/command/mcp.js +39 -0
- package/src/command/noticed.d.ts +11 -0
- package/src/command/noticed.js +55 -0
- package/src/command/older.d.ts +11 -0
- package/src/command/older.js +45 -0
- package/src/command/open.d.ts +24 -0
- package/src/command/open.js +107 -0
- package/src/command/passphrase.d.ts +6 -0
- package/src/command/passphrase.js +82 -0
- package/src/command/reclaim.d.ts +7 -0
- package/src/command/reclaim.js +47 -0
- package/src/command/refused.d.ts +4 -0
- package/src/command/refused.js +27 -0
- package/src/command/release.d.ts +27 -0
- package/src/command/release.js +153 -0
- package/src/command/repo.d.ts +31 -0
- package/src/command/repo.js +133 -0
- package/src/command/rewrap.d.ts +16 -0
- package/src/command/rewrap.js +175 -0
- package/src/command/runtime.d.ts +25 -0
- package/src/command/runtime.js +175 -0
- package/src/command/salvage.d.ts +4 -0
- package/src/command/salvage.js +42 -0
- package/src/command/screen.d.ts +14 -0
- package/src/command/screen.js +62 -0
- package/src/command/spawn.d.ts +23 -0
- package/src/command/spawn.js +213 -0
- package/src/command/start.d.ts +34 -0
- package/src/command/start.js +246 -0
- package/src/command/state.d.ts +5 -0
- package/src/command/state.js +39 -0
- package/src/command/token.d.ts +1 -0
- package/src/command/token.js +9 -0
- package/src/command/trial.d.ts +18 -0
- package/src/command/trial.js +108 -0
- package/src/command/undone.d.ts +3 -0
- package/src/command/undone.js +21 -0
- package/src/command/vouch.d.ts +1 -0
- package/src/command/vouch.js +15 -0
- package/src/command/windows-processes.d.ts +2 -0
- package/src/command/windows-processes.js +22 -0
- package/src/command/wipe.d.ts +9 -0
- package/src/command/wipe.js +105 -0
- package/src/command/words.d.ts +5 -0
- package/src/command/words.js +53 -0
- package/src/door/claim.d.ts +5 -0
- package/src/door/claim.js +21 -0
- package/src/door/claimed.d.ts +7 -0
- package/src/door/claimed.js +110 -0
- package/src/door/configuration.d.ts +40 -0
- package/src/door/configuration.js +206 -0
- package/src/door/design.d.ts +13 -0
- package/src/door/design.js +71 -0
- package/src/door/digests.d.ts +7 -0
- package/src/door/digests.js +36 -0
- package/src/door/distribution.d.ts +25 -0
- package/src/door/distribution.js +88 -0
- package/src/door/door.d.ts +41 -0
- package/src/door/door.js +219 -0
- package/src/door/dressed.d.ts +34 -0
- package/src/door/dressed.js +182 -0
- package/src/door/faculties.d.ts +29 -0
- package/src/door/faculties.js +88 -0
- package/src/door/longest.d.ts +6 -0
- package/src/door/longest.js +25 -0
- package/src/fills/account-only.d.ts +3 -0
- package/src/fills/account-only.js +24 -0
- package/src/fills/boot-key.d.ts +21 -0
- package/src/fills/boot-key.js +70 -0
- package/src/fills/boot-move.d.ts +25 -0
- package/src/fills/boot-move.js +86 -0
- package/src/fills/bridge.d.ts +13 -0
- package/src/fills/bridge.js +86 -0
- package/src/fills/chance.d.ts +2 -0
- package/src/fills/chance.js +7 -0
- package/src/fills/crypto.d.ts +2 -0
- package/src/fills/crypto.js +94 -0
- package/src/fills/flushed.d.ts +9 -0
- package/src/fills/flushed.js +80 -0
- package/src/fills/hardware.d.ts +18 -0
- package/src/fills/hardware.js +70 -0
- package/src/fills/held.d.ts +31 -0
- package/src/fills/held.js +171 -0
- package/src/fills/keepers.d.ts +23 -0
- package/src/fills/keepers.js +151 -0
- package/src/fills/keyring.d.ts +19 -0
- package/src/fills/keyring.js +131 -0
- package/src/fills/pages.d.ts +3 -0
- package/src/fills/pages.js +260 -0
- package/src/fills/reserve.d.ts +11 -0
- package/src/fills/reserve.js +72 -0
- package/src/fills/time.d.ts +2 -0
- package/src/fills/time.js +29 -0
- package/src/fills/unlocker.d.ts +6 -0
- package/src/fills/unlocker.js +26 -0
- package/src/fills/vitals.d.ts +8 -0
- package/src/fills/vitals.js +100 -0
- package/src/fills/windows-start.d.ts +2 -0
- package/src/fills/windows-start.js +21 -0
- package/src/halves/build.d.ts +10 -0
- package/src/halves/build.js +219 -0
- package/src/halves/end.d.ts +17 -0
- package/src/halves/end.js +157 -0
- package/src/halves/genome.d.ts +3 -0
- package/src/halves/genome.js +21 -0
- package/src/halves/handler.d.ts +8 -0
- package/src/halves/handler.js +40 -0
- package/src/halves/index.d.ts +5 -0
- package/src/halves/index.js +6 -0
- package/src/halves/laid.d.ts +12 -0
- package/src/halves/laid.js +103 -0
- package/src/halves/lent.d.ts +6 -0
- package/src/halves/lent.js +147 -0
- package/src/halves/native.d.ts +12 -0
- package/src/halves/native.js +53 -0
- package/src/halves/statements.d.ts +23 -0
- package/src/halves/statements.js +165 -0
- package/src/halves/tokens.d.ts +22 -0
- package/src/halves/tokens.js +135 -0
- package/src/link/link.d.ts +4 -0
- package/src/link/link.js +4 -0
- package/src/link/placeholder.d.ts +1 -0
- package/src/link/placeholder.js +21 -0
- package/src/link/steps.d.ts +52 -0
- package/src/link/steps.js +118 -0
- package/src/lobes/calls.d.ts +76 -0
- package/src/lobes/calls.js +61 -0
- package/src/lobes/channel.d.ts +76 -0
- package/src/lobes/channel.js +202 -0
- package/src/lobes/index.d.ts +1 -0
- package/src/lobes/index.js +2 -0
- package/src/lobes/lobes.d.ts +15 -0
- package/src/lobes/lobes.js +244 -0
- package/src/lobes/main.js +107 -0
- package/src/lobes/thread.d.ts +22 -0
- package/src/lobes/thread.js +270 -0
- package/src/organism/act.d.ts +8 -0
- package/src/organism/act.js +63 -0
- package/src/organism/beat.d.ts +5 -0
- package/src/organism/beat.js +45 -0
- package/src/organism/compiled.d.ts +2 -0
- package/src/organism/compiled.js +24 -0
- package/src/organism/folder.d.ts +88 -0
- package/src/organism/folder.js +259 -0
- package/src/organism/main.d.ts +1 -0
- package/src/organism/main.js +11 -0
- package/src/organism/organism.d.ts +1 -0
- package/src/organism/organism.js +220 -0
- package/src/organism/said.d.ts +12 -0
- package/src/organism/said.js +30 -0
- package/src/organism/told.d.ts +5 -0
- package/src/organism/told.js +110 -0
- package/src/organism/unlock.d.ts +8 -0
- package/src/organism/unlock.js +95 -0
- package/src/organism/upgrade.d.ts +24 -0
- package/src/organism/upgrade.js +145 -0
- package/src/organism/via.d.ts +7 -0
- package/src/organism/via.js +20 -0
- package/src/service/body.d.ts +8 -0
- package/src/service/body.js +34 -0
- package/src/service/handler.d.ts +20 -0
- package/src/service/handler.js +128 -0
- package/src/service/index.d.ts +4 -0
- package/src/service/index.js +16 -0
- package/src/service/manager.d.ts +18 -0
- package/src/service/manager.js +185 -0
- package/src/service/service.d.ts +24 -0
- package/src/service/service.js +200 -0
- package/src/service/swap.d.ts +12 -0
- package/src/service/swap.js +74 -0
- package/src/service/watchdog.d.ts +6 -0
- package/src/service/watchdog.js +31 -0
- package/src/tcp/crowd.d.ts +18 -0
- package/src/tcp/crowd.js +85 -0
- package/src/tcp/dial.d.ts +23 -0
- package/src/tcp/dial.js +102 -0
- package/src/tcp/frame.d.ts +23 -0
- package/src/tcp/frame.js +159 -0
- package/src/tcp/listen.d.ts +50 -0
- package/src/tcp/listen.js +207 -0
- package/src/tcp/source.d.ts +2 -0
- package/src/tcp/source.js +26 -0
- package/src/version/index.d.ts +1 -0
- package/src/version/index.js +2 -0
- package/src/version/version.d.ts +1 -0
- package/src/version/version.js +2 -0
- package/src/work/first.d.ts +11 -0
- package/src/work/first.js +91 -0
- package/src/work/index.d.ts +2 -0
- package/src/work/index.js +15 -0
- package/src/work/work.d.ts +20 -0
- package/src/work/work.js +136 -0
- package/src/ws/dial.d.ts +7 -0
- package/src/ws/dial.js +252 -0
- package/src/ws/dialing.d.ts +50 -0
- package/src/ws/dialing.js +72 -0
- package/src/ws/frame.d.ts +32 -0
- package/src/ws/frame.js +124 -0
- package/src/ws/handshake.d.ts +4 -0
- package/src/ws/handshake.js +27 -0
- package/src/ws/line.d.ts +45 -0
- package/src/ws/line.js +250 -0
- package/src/ws/listen.d.ts +42 -0
- package/src/ws/listen.js +272 -0
- package/src/ws/rfc6455.d.ts +18 -0
- package/src/ws/rfc6455.js +187 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { OFFER, offerOf, readLink, redeemedOf, REDEEM } from '@nervur.org/genome/quo';
|
|
3
|
+
import { dataText, error, isFields, readText, result, } from '@nervur.org/genome/standard';
|
|
4
|
+
import { cardOf, joinInvitation, takeLink, } from '../link/steps.js';
|
|
5
|
+
import { answered } from './asked.js';
|
|
6
|
+
import { line } from './line.js';
|
|
7
|
+
import { organismOf, } from './given.js';
|
|
8
|
+
import { runningOf } from './spawn.js';
|
|
9
|
+
import { vouchOf } from './vouch.js';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export const reachesOf = (home ) => ({
|
|
20
|
+
vouch: vouchOf,
|
|
21
|
+
now: () => new Date().toISOString(),
|
|
22
|
+
line: (words) => answered(organismOf(home), words),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const isLink = (word ) => word !== undefined && readLink(word) !== null;
|
|
26
|
+
|
|
27
|
+
const heldAt = async (reaches ) => {
|
|
28
|
+
const heard = await reaches.line(['relations']);
|
|
29
|
+
if ('why' in heard || !Array.isArray(heard.data)) return null;
|
|
30
|
+
return heard.data.flatMap((one) =>
|
|
31
|
+
isFields(one) && typeof one['placeholder'] === 'string' ? [one['placeholder']] : [],
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const portsOf = (reaches ) => ({
|
|
36
|
+
vouch: reaches.vouch,
|
|
37
|
+
now: reaches.now,
|
|
38
|
+
redeem: async (card, reference) => {
|
|
39
|
+
const redeemed = await reaches.line([
|
|
40
|
+
'ask',
|
|
41
|
+
'mouth',
|
|
42
|
+
'once',
|
|
43
|
+
dataText({ card, method: REDEEM, args: { reference } }),
|
|
44
|
+
]);
|
|
45
|
+
if ('why' in redeemed) return error('refused', `the link was not redeemed: ${redeemed.why}`);
|
|
46
|
+
const read = redeemedOf({ result: redeemed.data });
|
|
47
|
+
return 'why' in read ? error('refused', read.why) : result(read);
|
|
48
|
+
},
|
|
49
|
+
held: () => heldAt(reaches),
|
|
50
|
+
accept: async ({ invitation }, placeholder, note) => {
|
|
51
|
+
const accepted = await reaches.line(['accept', placeholder, invitation, dataText(note)]);
|
|
52
|
+
return 'why' in accepted ? error('refused', accepted.why) : result({ text: placeholder });
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const acceptLink = async (words , reaches ) => {
|
|
57
|
+
const [text, named, note] = words;
|
|
58
|
+
if (text === undefined || readLink(text) === null) return { why: 'accept takes a link' };
|
|
59
|
+
const typed = note === undefined ? null : readText(note);
|
|
60
|
+
if (typed !== null && 'why' in typed) return { why: `the note is no JSON: ${typed.why}, in ${note ?? ''}` };
|
|
61
|
+
const fields = typed === null ? null : typed.data;
|
|
62
|
+
if (fields !== null && !isFields(fields))
|
|
63
|
+
return { why: `the note of a link is an object of fields, not ${note ?? ''}` };
|
|
64
|
+
const ports = portsOf(reaches);
|
|
65
|
+
const taken = await takeLink(text, ports);
|
|
66
|
+
if ('why' in taken) return taken;
|
|
67
|
+
const joined = await joinInvitation(taken.invitation, taken.domain, { relation: named ?? null, note: fields }, ports);
|
|
68
|
+
return 'why' in joined ? joined : null;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
export const offerLink = async (
|
|
74
|
+
text ,
|
|
75
|
+
reaches ,
|
|
76
|
+
) => {
|
|
77
|
+
const link = text === undefined ? null : readLink(text);
|
|
78
|
+
if (link === null) return { why: 'offer takes a link' };
|
|
79
|
+
const [domain, given] = 'domain' in link ? [link.domain, null] : [null, link.card];
|
|
80
|
+
const card = await cardOf(domain, given, reaches);
|
|
81
|
+
if ('why' in card) return card;
|
|
82
|
+
const heard = await reaches.line([
|
|
83
|
+
'ask',
|
|
84
|
+
'mouth',
|
|
85
|
+
'once',
|
|
86
|
+
dataText({ card, method: OFFER, args: { reference: link.reference } }),
|
|
87
|
+
]);
|
|
88
|
+
const offer = 'why' in heard ? null : offerOf({ result: heard.data });
|
|
89
|
+
if (offer !== null && !('why' in heard)) {
|
|
90
|
+
const says = isFields(heard.data) ? (heard.data['says'] ?? null) : null;
|
|
91
|
+
return { offer: { says, waits: offer.waits, lives: offer.lives } };
|
|
92
|
+
}
|
|
93
|
+
const why = 'why' in heard ? `: ${heard.why}` : ', what it answered is no offer';
|
|
94
|
+
return { offer: null, said: `The place answered no offer${why}. The link is not spent: accept still takes it.` };
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const offerPrinted = async (given , reaches ) => {
|
|
98
|
+
const read = await offerLink(given.words[1], reaches);
|
|
99
|
+
if ('why' in read) return read;
|
|
100
|
+
if (given.json) given.answer(dataText(read.offer));
|
|
101
|
+
else if (read.offer !== null) for (const one of JSON.stringify(read.offer, null, 2).split('\n')) given.print(one);
|
|
102
|
+
if (read.offer === null) given.print(read.said);
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const offer = async (given ) => {
|
|
107
|
+
if (!isLink(given.words[1])) return { why: 'offer takes <link>' };
|
|
108
|
+
const organism = organismOf(given.home);
|
|
109
|
+
if (runningOf(organism) === null) return { why: 'the organism is not running' };
|
|
110
|
+
return offerPrinted(given, reachesOf(given.home));
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const accept = async (given ) => {
|
|
114
|
+
if (!isLink(given.words[1]))
|
|
115
|
+
return given.words.length < 3
|
|
116
|
+
? { why: 'accept takes <placeholder> <invitation> [note] | <link> [placeholder] [note]' }
|
|
117
|
+
: line(given);
|
|
118
|
+
const organism = organismOf(given.home);
|
|
119
|
+
if (runningOf(organism) === null) return { why: 'the organism is not running' };
|
|
120
|
+
const done = await acceptLink(given.words.slice(1), reachesOf(given.home));
|
|
121
|
+
if (done === null) given.print('Accepted: the link is held.');
|
|
122
|
+
return done;
|
|
123
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isOlder: (version: string | null, than: string) => boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
|
|
3
|
+
const numbersOf = (version ) => version.split('.').map(Number);
|
|
4
|
+
|
|
5
|
+
export const isOlder = (version , than ) => {
|
|
6
|
+
if (version === null) return true;
|
|
7
|
+
const [one, other] = [numbersOf(version), numbersOf(than)];
|
|
8
|
+
const at = one.findIndex((number, index) => number !== other[index]);
|
|
9
|
+
return at !== -1 && (one[at] ?? 0) < (other[at] ?? 0);
|
|
10
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type Why = {
|
|
2
|
+
readonly why: string;
|
|
3
|
+
};
|
|
4
|
+
export type Held = {
|
|
5
|
+
readonly free: () => void;
|
|
6
|
+
};
|
|
7
|
+
export type Taker = {
|
|
8
|
+
readonly handed: string | null;
|
|
9
|
+
readonly parent: number;
|
|
10
|
+
readonly pid: number;
|
|
11
|
+
readonly alive: (pid: number) => boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare const locked: (home: string, taker: Taker) => Held | Why;
|
|
14
|
+
export declare const ACTING = ".nervur-acting";
|
|
15
|
+
export declare const accountHeld: (print: (line: string) => void) => Promise<Held | Why>;
|
|
16
|
+
export declare const heldAt: (file: string, print: (line: string) => void, lives?: (pid: number) => boolean) => Promise<Held | Why>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { closeSync, linkSync, mkdirSync, openSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { freed, lockAt, lockPid } from './before.js';
|
|
5
|
+
import { globalPrefix } from './channel.js';
|
|
6
|
+
import { alive } from './spawn.js';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export const locked = (home , taker ) => {
|
|
20
|
+
const laid = mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
21
|
+
const file = lockAt(home);
|
|
22
|
+
if (taker.handed !== null)
|
|
23
|
+
return lockPid(file) === taker.parent
|
|
24
|
+
? { free: () => undefined }
|
|
25
|
+
: { why: 'the command was handed over to without the update that holds the lock' };
|
|
26
|
+
for (let tries = 0; tries < 2; tries += 1) {
|
|
27
|
+
try {
|
|
28
|
+
closeSync(openSync(file, 'wx', 0o600));
|
|
29
|
+
writeFileSync(file, `${taker.pid}\n`);
|
|
30
|
+
return { free: () => freed(file, home, laid) };
|
|
31
|
+
} catch {
|
|
32
|
+
const holder = lockPid(file);
|
|
33
|
+
if (holder !== null && taker.alive(holder)) return { why: `an update runs already, as process ${holder}` };
|
|
34
|
+
rmSync(file, { force: true });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { why: `${file} cannot be laid` };
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const ACTING = '.nervur-acting';
|
|
41
|
+
|
|
42
|
+
export const accountHeld = async (print ) => {
|
|
43
|
+
const prefix = await globalPrefix();
|
|
44
|
+
return typeof prefix === 'string' ? heldAt(join(prefix, ACTING), print) : prefix;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const heldAt = async (
|
|
48
|
+
file ,
|
|
49
|
+
print ,
|
|
50
|
+
lives = alive,
|
|
51
|
+
) => {
|
|
52
|
+
const laid = `${file}.${process.pid}`;
|
|
53
|
+
let told = false;
|
|
54
|
+
try {
|
|
55
|
+
writeFileSync(laid, `${process.pid}\n`, { mode: 0o600 });
|
|
56
|
+
for (;;) {
|
|
57
|
+
try {
|
|
58
|
+
linkSync(laid, file);
|
|
59
|
+
return { free: () => rmSync(file, { force: true }) };
|
|
60
|
+
} catch (failed) {
|
|
61
|
+
if (!(failed instanceof Error && 'code' in failed && failed.code === 'EEXIST'))
|
|
62
|
+
return { why: `${file} cannot be laid: ${failed instanceof Error ? failed.message : String(failed)}` };
|
|
63
|
+
}
|
|
64
|
+
const holder = lockPid(file);
|
|
65
|
+
if (holder === null || !lives(holder)) {
|
|
66
|
+
rmSync(file, { force: true });
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!told) print(`Another act moves this account's command, as process ${holder}: this one waits for it to end.`);
|
|
70
|
+
told = true;
|
|
71
|
+
await new Promise((done) => setTimeout(done, 250));
|
|
72
|
+
}
|
|
73
|
+
} finally {
|
|
74
|
+
rmSync(laid, { force: true });
|
|
75
|
+
}
|
|
76
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Data, type Fields } from '@nervur.org/genome/standard';
|
|
2
|
+
import { type Typed } from './tools.js';
|
|
3
|
+
export type Client = {
|
|
4
|
+
readonly tasks: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type Called = {
|
|
7
|
+
readonly called: Fields;
|
|
8
|
+
} | {
|
|
9
|
+
readonly task: Fields;
|
|
10
|
+
} | {
|
|
11
|
+
readonly invalid: string;
|
|
12
|
+
};
|
|
13
|
+
export type Calling = {
|
|
14
|
+
readonly type: Typed;
|
|
15
|
+
readonly now: () => number;
|
|
16
|
+
};
|
|
17
|
+
export declare class Calls {
|
|
18
|
+
#private;
|
|
19
|
+
constructor({ type, now }: Calling);
|
|
20
|
+
call(params: Fields, client: Client): Promise<Called>;
|
|
21
|
+
told(taskId: string): boolean;
|
|
22
|
+
task(taskId: Data | undefined): Promise<{
|
|
23
|
+
readonly task: Fields;
|
|
24
|
+
} | {
|
|
25
|
+
readonly invalid: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { dataText, isFields, } from '@nervur.org/genome/standard';
|
|
4
|
+
|
|
5
|
+
import { lobeLink } from './resources.js';
|
|
6
|
+
import { callOf, methodsOf, } from './tools.js';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const FAR_READ_EVERY = 2000;
|
|
15
|
+
|
|
16
|
+
const failed = (text ) => ({ content: [{ type: 'text', text }], isError: true });
|
|
17
|
+
|
|
18
|
+
const NOT_NOW = ['timeout', 'unavailable', 'busy', 'silent'];
|
|
19
|
+
|
|
20
|
+
const whyOf = (result ) => {
|
|
21
|
+
const [first] = Array.isArray(result['content']) ? result['content'] : [];
|
|
22
|
+
return isFields(first) && typeof first['text'] === 'string' ? first['text'] : '';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const resultOf = (heard ) => {
|
|
26
|
+
if ('why' in heard) return failed(heard.why);
|
|
27
|
+
const { answer } = heard;
|
|
28
|
+
if ('error' in answer) return failed(`${answer.error.code}: ${answer.error.message}`);
|
|
29
|
+
const content = [{ type: 'text', text: heard.text }];
|
|
30
|
+
return isFields(answer.result)
|
|
31
|
+
? { content, structuredContent: answer.result, isError: false }
|
|
32
|
+
: { content, isError: false };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const reachedOf = async (
|
|
43
|
+
type ,
|
|
44
|
+
{ placeholder, method, args } ,
|
|
45
|
+
) => {
|
|
46
|
+
const { lobe, method: asked } = args;
|
|
47
|
+
const through = placeholder === 'brain' && method === 'ask' && typeof lobe === 'string' && typeof asked === 'string';
|
|
48
|
+
const at = through ? ['lobe', lobe] : ['ask', placeholder];
|
|
49
|
+
const heard = await type(at);
|
|
50
|
+
if ('why' in heard) return { why: `${at.join(' ')} answered no describe: ${heard.why}` };
|
|
51
|
+
if ('error' in heard.answer) return { why: `${at.join(' ')} answered no describe: ${heard.answer.error.message}` };
|
|
52
|
+
const methods = methodsOf(heard.answer.result);
|
|
53
|
+
const name = through ? asked : method;
|
|
54
|
+
return {
|
|
55
|
+
at,
|
|
56
|
+
method: methods.find(([one]) => one === name)?.[1],
|
|
57
|
+
args: through ? args['args'] : args,
|
|
58
|
+
jobs: methods.some(([one]) => one === 'job'),
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const presentRefusal = async (type , { placeholder, method, args } ) => {
|
|
63
|
+
if (placeholder !== 'brain' || method !== 'version') return null;
|
|
64
|
+
const heard = await type(['ask', 'brain', 'state', '{}']);
|
|
65
|
+
const state = 'answer' in heard && 'result' in heard.answer ? heard.answer.result : undefined;
|
|
66
|
+
const present = isFields(state) ? state['presentLobes'] : undefined;
|
|
67
|
+
if (!Array.isArray(present)) return 'the brain shows no present lobes, so no move of a lobe is typed';
|
|
68
|
+
const lobe = args['lobe'];
|
|
69
|
+
return typeof lobe === 'string' && present.includes(lobe)
|
|
70
|
+
? `the present lobe ${lobe} moves on the word of the person present alone, never a model's`
|
|
71
|
+
: null;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
export class Calls {
|
|
77
|
+
#type ;
|
|
78
|
+
#now ;
|
|
79
|
+
#tasks = new Map ();
|
|
80
|
+
|
|
81
|
+
constructor({ type, now } ) {
|
|
82
|
+
this.#type = type;
|
|
83
|
+
this.#now = now;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async call(params , client ) {
|
|
87
|
+
const call = callOf(params['name'], params['arguments']);
|
|
88
|
+
if ('why' in call) return { invalid: call.why };
|
|
89
|
+
const tool = `${call.placeholder}.${call.method}`;
|
|
90
|
+
const args = dataText(call.args);
|
|
91
|
+
const reached = await reachedOf(this.#type, call);
|
|
92
|
+
if ('why' in reached) return { called: failed(reached.why) };
|
|
93
|
+
const person = await presentRefusal(this.#type, call);
|
|
94
|
+
if (person !== null) return { called: failed(`refused: ${person}`) };
|
|
95
|
+
const result = resultOf(await this.#type(['ask', call.placeholder, call.method, args]));
|
|
96
|
+
const answered = result['structuredContent'];
|
|
97
|
+
const job = isFields(answered) ? answered['job'] : undefined;
|
|
98
|
+
if (client.tasks && reached.jobs && result['isError'] === false && typeof job === 'string')
|
|
99
|
+
return { task: this.#begun(reached.at, job) };
|
|
100
|
+
const made = tool === 'brain.create' && isFields(answered) ? answered['id'] : undefined;
|
|
101
|
+
if (typeof made !== 'string') return { called: result };
|
|
102
|
+
const content = Array.isArray(result['content']) ? result['content'] : [];
|
|
103
|
+
return { called: { ...result, content: [...content, lobeLink(made)] } };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
told(taskId ) {
|
|
107
|
+
return this.#tasks.get(taskId)?.at[0] === 'lobe';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async task(taskId ) {
|
|
111
|
+
const kept = typeof taskId === 'string' ? this.#tasks.get(taskId) : undefined;
|
|
112
|
+
if (typeof taskId !== 'string' || kept === undefined) return { invalid: `no task ${dataText(taskId ?? null)}` };
|
|
113
|
+
const task = {
|
|
114
|
+
taskId,
|
|
115
|
+
createdAt: kept.created,
|
|
116
|
+
lastUpdatedAt: this.#stamp(),
|
|
117
|
+
ttlMs: null,
|
|
118
|
+
...this.#reading(taskId),
|
|
119
|
+
};
|
|
120
|
+
const heard = await this.#type([...kept.at, 'job', dataText({ job: kept.job })]);
|
|
121
|
+
const read = resultOf(heard);
|
|
122
|
+
const record = read['structuredContent'];
|
|
123
|
+
const ended = isFields(record) ? record['ended'] : undefined;
|
|
124
|
+
if ('why' in heard || ('error' in heard.answer && NOT_NOW.includes(heard.answer.error.code)))
|
|
125
|
+
return { task: { ...task, status: 'working', statusMessage: `the job reads not now: ${whyOf(read)}` } };
|
|
126
|
+
if ('error' in heard.answer)
|
|
127
|
+
return {
|
|
128
|
+
task: { ...task, status: 'failed', statusMessage: `the job reads none: ${whyOf(read)}`, result: read },
|
|
129
|
+
};
|
|
130
|
+
if (!isFields(ended)) return { task: { ...task, status: 'working' } };
|
|
131
|
+
return { task: { ...task, status: 'completed', result: { ...read, isError: ended['code'] !== 0 } } };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#reading(taskId ) {
|
|
135
|
+
return this.told(taskId) ? {} : { pollIntervalMs: FAR_READ_EVERY };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
#stamp() {
|
|
139
|
+
return new Date(this.#now()).toISOString();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#begun(at , job ) {
|
|
143
|
+
const taskId = randomUUID();
|
|
144
|
+
const created = this.#stamp();
|
|
145
|
+
this.#tasks.set(taskId, { at, job, created });
|
|
146
|
+
return {
|
|
147
|
+
taskId,
|
|
148
|
+
status: 'working',
|
|
149
|
+
createdAt: created,
|
|
150
|
+
lastUpdatedAt: created,
|
|
151
|
+
ttlMs: null,
|
|
152
|
+
...this.#reading(taskId),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Data, type Fields } from '@nervur.org/genome/standard';
|
|
2
|
+
import type { Watch } from '../../../organs/console/node/index.js';
|
|
3
|
+
import type { Calls } from './calls.js';
|
|
4
|
+
import { type Typed } from './tools.js';
|
|
5
|
+
export type Noticing = {
|
|
6
|
+
readonly type: Typed;
|
|
7
|
+
readonly watch: Watch;
|
|
8
|
+
readonly tasks: Pick<Calls, 'task' | 'told'>;
|
|
9
|
+
readonly send: (message: Data) => void;
|
|
10
|
+
readonly note: (line: string) => void;
|
|
11
|
+
readonly server: Fields;
|
|
12
|
+
};
|
|
13
|
+
export declare class Notices {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(gear: Noticing);
|
|
16
|
+
listen(id: string | number, filter: Data | undefined): Promise<void>;
|
|
17
|
+
cancelled(id: Data | undefined): Promise<void>;
|
|
18
|
+
opened(): Promise<void>;
|
|
19
|
+
heard(): void;
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
settled(): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { isFields, } from '@nervur.org/genome/standard';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { allLobesOf } from './resources.js';
|
|
6
|
+
import { heldOf, toolsOf, } from './tools.js';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const SUBSCRIPTION = 'io.modelcontextprotocol/subscriptionId';
|
|
18
|
+
const TOOLS = 'notifications/tools/list_changed';
|
|
19
|
+
const RESOURCES = 'notifications/resources/list_changed';
|
|
20
|
+
const TASKS = 'notifications/tasks';
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export class Notices {
|
|
26
|
+
#gear ;
|
|
27
|
+
#listens = new Map ();
|
|
28
|
+
#legacy = false;
|
|
29
|
+
#watching = null;
|
|
30
|
+
#last = null;
|
|
31
|
+
#kept = new Map();
|
|
32
|
+
#reading = Promise.resolve();
|
|
33
|
+
|
|
34
|
+
constructor(gear ) {
|
|
35
|
+
this.#gear = gear;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async listen(id , filter ) {
|
|
39
|
+
const named = fieldOf(filter, 'taskIds');
|
|
40
|
+
const taskIds = Array.isArray(named) ? named.filter((one) => typeof one === 'string') : null;
|
|
41
|
+
const told = taskIds?.filter((one) => this.#gear.tasks.told(one)) ?? [];
|
|
42
|
+
const asked = {
|
|
43
|
+
tools: fieldOf(filter, 'toolsListChanged') === true,
|
|
44
|
+
resources: fieldOf(filter, 'resourcesListChanged') === true,
|
|
45
|
+
tasks: new Map(told.map((one) => [one, null])),
|
|
46
|
+
};
|
|
47
|
+
await this.#first();
|
|
48
|
+
this.#listens.set(id, asked);
|
|
49
|
+
this.#gear.send({
|
|
50
|
+
jsonrpc: '2.0',
|
|
51
|
+
method: 'notifications/subscriptions/acknowledged',
|
|
52
|
+
params: {
|
|
53
|
+
notifications: {
|
|
54
|
+
...(asked.tools ? { toolsListChanged: true } : {}),
|
|
55
|
+
...(asked.resources ? { resourcesListChanged: true } : {}),
|
|
56
|
+
...(taskIds === null ? {} : { taskIds: told }),
|
|
57
|
+
},
|
|
58
|
+
_meta: { [SUBSCRIPTION]: id },
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
await this.#watch();
|
|
62
|
+
this.#reading = this.#reading.then(() => this.#tellTasks(id, asked));
|
|
63
|
+
await this.#reading;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async cancelled(id ) {
|
|
67
|
+
if ((typeof id !== 'string' && typeof id !== 'number') || !this.#listens.delete(id)) return;
|
|
68
|
+
if (this.#listens.size === 0 && !this.#legacy) await this.#unwatch();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
opened() {
|
|
72
|
+
this.#legacy = true;
|
|
73
|
+
this.#reading = this.#reading.then(async () => {
|
|
74
|
+
await this.#first();
|
|
75
|
+
await this.#watch();
|
|
76
|
+
});
|
|
77
|
+
return this.#reading;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
heard() {
|
|
81
|
+
if (this.#legacy && this.#watching === null) this.#again();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async close() {
|
|
85
|
+
await this.#reading;
|
|
86
|
+
this.#listens.clear();
|
|
87
|
+
this.#legacy = false;
|
|
88
|
+
await this.#unwatch();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
settled() {
|
|
92
|
+
return this.#reading;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async #watch() {
|
|
96
|
+
if (this.#watching === null) {
|
|
97
|
+
const laid = this.#gear
|
|
98
|
+
.watch(
|
|
99
|
+
(moved) => void this.#changed(moved),
|
|
100
|
+
() => {
|
|
101
|
+
if (this.#watching === laid) this.#ended();
|
|
102
|
+
},
|
|
103
|
+
)
|
|
104
|
+
.then((watched) => {
|
|
105
|
+
if ('close' in watched) return watched;
|
|
106
|
+
this.#gear.note(`nervur mcp: the console is not watched: ${watched.why}`);
|
|
107
|
+
if (this.#watching === laid) this.#watching = null;
|
|
108
|
+
return null;
|
|
109
|
+
});
|
|
110
|
+
this.#watching = laid;
|
|
111
|
+
}
|
|
112
|
+
await this.#watching;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async #unwatch() {
|
|
116
|
+
const watched = await this.#watching;
|
|
117
|
+
this.#watching = null;
|
|
118
|
+
watched?.close();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#changed({ nodes, lobes } ) {
|
|
122
|
+
this.#reading = this.#reading.then(async () => {
|
|
123
|
+
if (nodes.length > 0) await this.#listed();
|
|
124
|
+
if (lobes.length > 0) for (const [id, asked] of this.#listens) await this.#tellTasks(id, asked);
|
|
125
|
+
});
|
|
126
|
+
return this.#reading;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async #listed() {
|
|
130
|
+
const now = await this.#read();
|
|
131
|
+
if ('why' in now) return;
|
|
132
|
+
const last = this.#last;
|
|
133
|
+
this.#last = now;
|
|
134
|
+
if (last === null) return;
|
|
135
|
+
const changed = { tools: now.tools !== last.tools, resources: now.lobes !== last.lobes };
|
|
136
|
+
for (const [method, which] of [
|
|
137
|
+
[TOOLS, 'tools'],
|
|
138
|
+
[RESOURCES, 'resources'],
|
|
139
|
+
] ) {
|
|
140
|
+
if (!changed[which]) continue;
|
|
141
|
+
for (const [id, asked] of this.#listens)
|
|
142
|
+
if (asked[which]) this.#gear.send({ jsonrpc: '2.0', method, params: { _meta: { [SUBSCRIPTION]: id } } });
|
|
143
|
+
if (this.#legacy) this.#gear.send({ jsonrpc: '2.0', method });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async #tellTasks(id , { tasks } ) {
|
|
148
|
+
for (const [taskId, last] of tasks) {
|
|
149
|
+
const read = await this.#gear.tasks.task(taskId);
|
|
150
|
+
if ('invalid' in read) continue;
|
|
151
|
+
const { status } = read.task;
|
|
152
|
+
if (status === last || typeof status !== 'string') continue;
|
|
153
|
+
tasks.set(taskId, status);
|
|
154
|
+
if (status === 'completed' || status === 'failed') tasks.delete(taskId);
|
|
155
|
+
const params = { ...read.task, _meta: { [SUBSCRIPTION]: id } };
|
|
156
|
+
this.#gear.send({ jsonrpc: '2.0', method: TASKS, params });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#again() {
|
|
161
|
+
this.#reading = this.#reading.then(async () => {
|
|
162
|
+
if (!this.#legacy || this.#watching !== null) return;
|
|
163
|
+
await this.#watch();
|
|
164
|
+
if (this.#watching !== null) await this.#listed();
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async #first() {
|
|
169
|
+
if (this.#last !== null) return;
|
|
170
|
+
const read = await this.#read();
|
|
171
|
+
if (!('why' in read)) this.#last = read;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
#ended() {
|
|
175
|
+
this.#watching = null;
|
|
176
|
+
for (const id of this.#listens.keys())
|
|
177
|
+
this.#gear.send({
|
|
178
|
+
jsonrpc: '2.0',
|
|
179
|
+
id,
|
|
180
|
+
result: {
|
|
181
|
+
resultType: 'complete',
|
|
182
|
+
_meta: { 'io.modelcontextprotocol/serverInfo': this.#gear.server, [SUBSCRIPTION]: id },
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
this.#listens.clear();
|
|
186
|
+
this.#again();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async #read() {
|
|
190
|
+
const { type, note } = this.#gear;
|
|
191
|
+
const unread = (why ) => {
|
|
192
|
+
note(`nervur mcp: the lists read not: ${why.why}`);
|
|
193
|
+
return why;
|
|
194
|
+
};
|
|
195
|
+
const held = await heldOf(type, note, this.#kept);
|
|
196
|
+
if ('why' in held) return unread(held);
|
|
197
|
+
const lobes = await allLobesOf(type);
|
|
198
|
+
if ('why' in lobes) return unread(lobes);
|
|
199
|
+
return { tools: JSON.stringify(toolsOf(held)), lobes: JSON.stringify(lobes) };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const fieldOf = (data , field ) => (isFields(data) ? data[field] : undefined);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Fields } from '@nervur.org/genome/standard';
|
|
2
|
+
import type { Typed } from './tools.js';
|
|
3
|
+
export type Lending = {
|
|
4
|
+
readonly type: Typed;
|
|
5
|
+
};
|
|
6
|
+
export type Read = {
|
|
7
|
+
readonly contents: readonly Fields[];
|
|
8
|
+
} | {
|
|
9
|
+
readonly code: number;
|
|
10
|
+
readonly why: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const RESOURCES: readonly Fields[];
|
|
13
|
+
export declare const TEMPLATES: readonly Fields[];
|
|
14
|
+
export type Lobe = {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly blueprint: string;
|
|
17
|
+
readonly faculty: string | null;
|
|
18
|
+
};
|
|
19
|
+
export type Lobes = {
|
|
20
|
+
readonly lobes: readonly Lobe[];
|
|
21
|
+
readonly next: string | null;
|
|
22
|
+
} | {
|
|
23
|
+
readonly why: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const lobesOf: (type: Typed, cursor: string | null) => Promise<Lobes>;
|
|
26
|
+
export declare const allLobesOf: (type: Typed) => Promise<readonly Lobe[] | {
|
|
27
|
+
readonly why: string;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const lobeResource: ({ id, blueprint }: Lobe) => Fields;
|
|
30
|
+
export declare const lobeLink: (id: string) => Fields;
|
|
31
|
+
export declare const readOf: ({ type }: Lending, uri: string) => Promise<Read>;
|