@nervur-org/dock 0.5.0 → 0.6.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 +7 -4
- package/api/route.ts +4 -72
- package/beings/avatar.ts +11 -7
- package/beings/carry.ts +129 -116
- package/beings/clock.ts +11 -7
- package/beings/desk.ts +7 -6
- package/beings/doorbell.ts +36 -7
- package/beings/index.ts +17 -4
- package/beings/join.ts +7 -4
- package/beings/link.ts +1 -1
- package/beings/porter.ts +5 -1
- package/beings/presence.ts +15 -5
- package/beings/setup.ts +27 -21
- package/beings/user.ts +26 -17
- package/beings/way.ts +1 -1
- package/{dock → box}/agents.ts +37 -44
- package/{dock → box}/apns.ts +4 -4
- package/box/box.ts +31 -0
- package/box/contract.ts +41 -0
- package/box/dialers.ts +88 -0
- package/box/dock.ts +148 -0
- package/box/envoy.ts +96 -0
- package/box/faculty.ts +111 -0
- package/{dock → box}/fcm.ts +1 -1
- package/box/grants.ts +90 -0
- package/box/http.ts +93 -0
- package/{dock → box}/http2.ts +7 -7
- package/box/index.ts +201 -0
- package/box/join.ts +78 -0
- package/box/local.ts +37 -0
- package/{dock → box}/location.ts +15 -3
- package/{dock → box}/notifications.ts +17 -5
- package/box/push.ts +85 -0
- package/box/ring.ts +85 -0
- package/{dock → box}/service.ts +2 -2
- package/box/timer.ts +150 -0
- package/box/tree.ts +22 -0
- package/{dock → box}/webpush.ts +2 -2
- package/cli/client.ts +1 -1
- package/cli/daemon.ts +101 -103
- package/cli/estate.ts +2 -3
- package/cli/nervur.ts +44 -25
- package/cli/stand.ts +1 -1
- package/dist/api/route.d.ts +1 -2
- package/dist/api/route.js +4 -76
- package/dist/beings/avatar.d.ts +4 -3
- package/dist/beings/avatar.js +9 -6
- package/dist/beings/carry.d.ts +10 -12
- package/dist/beings/carry.js +119 -127
- package/dist/beings/clock.js +10 -7
- package/dist/beings/desk.js +8 -7
- package/dist/beings/doorbell.d.ts +3 -1
- package/dist/beings/doorbell.js +37 -4
- package/dist/beings/index.d.ts +24 -4
- package/dist/beings/index.js +15 -4
- package/dist/beings/join.d.ts +1 -0
- package/dist/beings/join.js +6 -4
- package/dist/beings/link.d.ts +0 -1
- package/dist/beings/link.js +1 -1
- package/dist/beings/porter.js +5 -1
- package/dist/beings/presence.d.ts +1 -0
- package/dist/beings/presence.js +12 -3
- package/dist/beings/setup.d.ts +5 -2
- package/dist/beings/setup.js +16 -15
- package/dist/beings/user.d.ts +4 -3
- package/dist/beings/user.js +18 -11
- package/dist/{dock → box}/agents.d.ts +7 -4
- package/dist/{dock → box}/agents.js +30 -37
- package/dist/{dock → box}/apns.d.ts +1 -1
- package/dist/{dock → box}/apns.js +3 -3
- package/dist/box/box.d.ts +9 -0
- package/dist/box/box.js +18 -0
- package/dist/box/contract.d.ts +6 -0
- package/dist/box/contract.js +35 -0
- package/dist/{dock → box}/dialers.d.ts +7 -4
- package/dist/box/dialers.js +76 -0
- package/dist/box/dock.d.ts +182 -0
- package/dist/box/dock.js +128 -0
- package/dist/box/envoy.d.ts +44 -0
- package/dist/box/envoy.js +75 -0
- package/dist/box/faculty.d.ts +68 -0
- package/dist/box/faculty.js +97 -0
- package/dist/{dock → box}/fcm.d.ts +1 -1
- package/dist/{dock → box}/grants.d.ts +4 -3
- package/dist/box/grants.js +78 -0
- package/dist/box/http.d.ts +26 -0
- package/dist/box/http.js +89 -0
- package/dist/{dock → box}/http2.d.ts +1 -1
- package/dist/{dock → box}/http2.js +6 -6
- package/dist/box/index.d.ts +46 -0
- package/dist/box/index.js +179 -0
- package/dist/box/join.d.ts +19 -0
- package/dist/box/join.js +67 -0
- package/dist/{dock → box}/local.d.ts +3 -2
- package/dist/box/local.js +27 -0
- package/dist/{dock → box}/location.d.ts +3 -0
- package/dist/box/location.js +21 -0
- package/dist/{dock → box}/notifications.d.ts +3 -0
- package/dist/{dock → box}/notifications.js +14 -4
- package/dist/{dock → box}/push.d.ts +12 -18
- package/dist/box/push.js +83 -0
- package/dist/box/ring.d.ts +18 -0
- package/dist/box/ring.js +55 -0
- package/dist/{dock → box}/service.d.ts +1 -1
- package/dist/{dock → box}/service.js +1 -1
- package/dist/{dock → box}/timer.d.ts +2 -0
- package/dist/box/timer.js +127 -0
- package/dist/box/tree.d.ts +5 -0
- package/dist/box/tree.js +14 -0
- package/dist/{dock → box}/webpush.d.ts +1 -1
- package/dist/cli/client.d.ts +1 -0
- package/dist/cli/daemon.d.ts +2 -8
- package/dist/cli/daemon.js +102 -107
- package/dist/cli/estate.js +2 -3
- package/dist/cli/nervur.js +44 -24
- package/dist/cli/stand.d.ts +0 -14
- package/dist/cli/stand.js +1 -1
- package/dist/harbor/browser.d.ts +8 -5
- package/dist/harbor/browser.js +20 -21
- package/dist/harbor/capacitor.d.ts +3 -3
- package/dist/harbor/capacitor.js +9 -8
- package/dist/harbor/disk.d.ts +9 -9
- package/dist/harbor/disk.js +56 -51
- package/dist/harbor/edge/alarm.d.ts +4 -2
- package/dist/harbor/edge/alarm.js +9 -19
- package/dist/harbor/edge/edge.d.ts +7 -6
- package/dist/harbor/edge/edge.js +58 -53
- package/dist/harbor/edge/exercise.js +4 -4
- package/dist/harbor/edge/given.d.ts +0 -1
- package/dist/harbor/edge/given.js +0 -29
- package/dist/harbor/edge/storage.d.ts +0 -2
- package/dist/harbor/edge/storage.js +2 -2
- package/dist/harbor/http.js +4 -2
- package/dist/harbor/sealed.d.ts +0 -5
- package/dist/harbor/sealed.js +0 -39
- package/dist/harbor/tauri.d.ts +2 -2
- package/dist/harbor/tauri.js +13 -10
- package/dist/human/app.d.ts +1 -1
- package/dist/human/app.js +10 -12
- package/dist/human/door.d.ts +0 -1
- package/dist/human/door.js +1 -1
- package/dist/human/html.js +1 -1
- package/dist/human/move.js +1 -1
- package/dist/human/tab.bundle.txt +3629 -2824
- package/dist/human/wake.d.ts +5 -2
- package/dist/human/wake.js +23 -14
- package/dist/human/web.d.ts +0 -1
- package/dist/human/web.js +3 -3
- package/dist/human/worker.bundle.txt +2945 -2118
- package/dist/human/worlds.js +3 -3
- package/dist/mcp/agent.d.ts +0 -1
- package/dist/mcp/agent.js +1 -1
- package/dist/mcp/allow.js +3 -2
- package/dist/mcp/http.d.ts +0 -1
- package/dist/mcp/http.js +1 -1
- package/dist/mcp/oauth.d.ts +3 -4
- package/dist/mcp/oauth.js +4 -4
- package/dist/mcp/route.d.ts +1 -1
- package/dist/mcp/runner.d.ts +0 -1
- package/dist/mcp/runner.js +1 -1
- package/dist/mcp/server.d.ts +0 -1
- package/dist/mcp/server.js +1 -1
- package/harbor/browser.ts +22 -24
- package/harbor/capacitor.ts +9 -8
- package/harbor/disk.ts +53 -48
- package/harbor/edge/alarm.ts +15 -12
- package/harbor/edge/edge.ts +61 -55
- package/harbor/edge/exercise.ts +4 -4
- package/harbor/edge/given.ts +3 -33
- package/harbor/edge/storage.ts +2 -2
- package/harbor/http.ts +5 -3
- package/harbor/sealed.ts +0 -35
- package/harbor/tauri.ts +13 -10
- package/human/app.ts +12 -13
- package/human/door.ts +1 -1
- package/human/html.ts +1 -1
- package/human/local.ts +1 -1
- package/human/move.ts +1 -1
- package/human/tab.bundle.txt +3629 -2824
- package/human/wake.ts +36 -16
- package/human/web.ts +4 -4
- package/human/worker.bundle.txt +2945 -2118
- package/human/worlds.ts +3 -3
- package/mcp/agent.ts +1 -1
- package/mcp/allow.ts +2 -1
- package/mcp/http.ts +1 -1
- package/mcp/oauth.ts +4 -4
- package/mcp/route.ts +1 -1
- package/mcp/runner.ts +1 -1
- package/mcp/server.ts +1 -1
- package/package.json +9 -8
- package/beings/envoy.ts +0 -218
- package/dist/beings/envoy.d.ts +0 -54
- package/dist/beings/envoy.js +0 -211
- package/dist/dock/console.d.ts +0 -6
- package/dist/dock/console.js +0 -20
- package/dist/dock/dialers.js +0 -75
- package/dist/dock/faculty.d.ts +0 -24
- package/dist/dock/faculty.js +0 -142
- package/dist/dock/grants.js +0 -99
- package/dist/dock/index.d.ts +0 -41
- package/dist/dock/index.js +0 -113
- package/dist/dock/local.js +0 -44
- package/dist/dock/location.js +0 -11
- package/dist/dock/push.js +0 -132
- package/dist/dock/timer.js +0 -149
- package/dock/console.ts +0 -23
- package/dock/dialers.ts +0 -85
- package/dock/faculty.ts +0 -148
- package/dock/grants.ts +0 -111
- package/dock/index.ts +0 -133
- package/dock/local.ts +0 -48
- package/dock/push.ts +0 -161
- package/dock/timer.ts +0 -174
- /package/dist/{dock → box}/fcm.js +0 -0
- /package/dist/{dock → box}/webpush.js +0 -0
package/dock/timer.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// The box's clock, and the one being on a device that reads one. A being who
|
|
3
|
-
// could read a clock could not be moved, since the moment she read would be
|
|
4
|
-
// her box's and no other, so the moment reaches every other being the one way
|
|
5
|
-
// anything reaches a being: as an ask at her door, from this faculty, as the
|
|
6
|
-
// occupant she named when she asked to be woken.
|
|
7
|
-
//
|
|
8
|
-
// She arms for the next due moment and for nothing else. Every watcher
|
|
9
|
-
// answers a round with when she is next due, this arms for the earliest of
|
|
10
|
-
// them, and a box whose watchers all say null arms nothing and sleeps until
|
|
11
|
-
// somebody keeps something. So a box with no schedules never ticks, and a
|
|
12
|
-
// home on the edge with a sweep at three in the morning wakes once a night.
|
|
13
|
-
//
|
|
14
|
-
// A round is armed for one moment at a time and never overlaps the one
|
|
15
|
-
// before, and the moment is floored to the minute with half a second after
|
|
16
|
-
// it, since a watcher floors the moment she is handed and a round that fired
|
|
17
|
-
// a hair early would floor to the minute before.
|
|
18
|
-
//
|
|
19
|
-
// One method knows a terrain, `arm`, and a subclass replaces it: a
|
|
20
|
-
// `setTimeout` here, the object's storage alarm on a worker. Nothing else in
|
|
21
|
-
// her reads a platform.
|
|
22
|
-
import type { JsonObject } from 'nervur';
|
|
23
|
-
import { Faculty, type Woke } from './faculty.ts';
|
|
24
|
-
|
|
25
|
-
const MINUTE = 60_000;
|
|
26
|
-
// A timeout further out than this is not trusted, so the arming is capped and
|
|
27
|
-
// made again when it goes off. It is the base class's own bound and no rule
|
|
28
|
-
// of the faculty: a terrain whose alarm holds a month arms for the month.
|
|
29
|
-
const DAY = 86_400_000;
|
|
30
|
-
|
|
31
|
-
export class Timer extends Faculty {
|
|
32
|
-
static override asks = {
|
|
33
|
-
watch: { description: 'wake me when I say I am next due', input: { type: 'object', properties: { invitation: { type: 'object' }, method: { type: 'string' }, args: { type: 'object' } }, required: ['invitation', 'method'] } },
|
|
34
|
-
due: { description: 'bring my next round forward to this moment', input: { type: 'object', properties: { at: { type: 'number' } }, required: ['at'] } },
|
|
35
|
-
now: { description: 'this box’s moment', input: { type: 'object' } },
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
#timeout: ReturnType<typeof setTimeout> | undefined;
|
|
39
|
-
#stopped = false;
|
|
40
|
-
#armed: number | null = null;
|
|
41
|
-
#round: Promise<Woke[]> | null = null;
|
|
42
|
-
|
|
43
|
-
// The moment she is armed for, or null while she is asleep. For the
|
|
44
|
-
// device's own code and for a suite; it crosses no door.
|
|
45
|
-
get armed(): number | null {
|
|
46
|
-
return this.#armed;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// A watcher says she is due sooner than the box knew. It only ever brings
|
|
50
|
-
// the round forward: what fires is decided at the tick, in the watcher's
|
|
51
|
-
// own cells, so an arming that moved later on somebody's word would be a
|
|
52
|
-
// schedule somebody else held silenced. The door is the whole gate here:
|
|
53
|
-
// a standing at a faculty comes from `lend` alone, and this adds no second
|
|
54
|
-
// one.
|
|
55
|
-
due(args: JsonObject): JsonObject {
|
|
56
|
-
const at = args.at;
|
|
57
|
-
if (typeof at !== 'number' || !Number.isFinite(at)) return { error: 'a due carries the moment: { at }' };
|
|
58
|
-
const when = moment(at);
|
|
59
|
-
if (this.#armed === null || when < this.#armed) this.#arm(when);
|
|
60
|
-
return { armed: this.#armed };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Whoever was just filed is ticked at once, and what she answers is what
|
|
64
|
-
// the box arms for. One move covers a box booting, a home moving in and a
|
|
65
|
-
// watcher born long after the box was up: she is never waiting for a round
|
|
66
|
-
// nobody scheduled.
|
|
67
|
-
protected override async welcomed(id: string): Promise<void> {
|
|
68
|
-
await this.round(Date.now(), id);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// The arming went off. A moment still well ahead is the day's cap this
|
|
72
|
-
// class put on its own timeout, so it is armed again rather than fired: a
|
|
73
|
-
// terrain calls this and never has to know how far out the arming was.
|
|
74
|
-
async rang(): Promise<Woke[]> {
|
|
75
|
-
if (this.#stopped) return [];
|
|
76
|
-
if (this.#armed !== null && this.#armed - Date.now() > 1_000) {
|
|
77
|
-
this.arm(this.#armed);
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
return this.fire(Date.now());
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// The moment, read here and handed on. A device's own code may call it at a
|
|
84
|
-
// moment it names, which is how a suite proves a wake without waiting for
|
|
85
|
-
// one and how an operator makes a round happen now.
|
|
86
|
-
fire(now: number): Promise<Woke[]> {
|
|
87
|
-
return this.round(now);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// One round, and never two: a second while one is in flight is handed the
|
|
91
|
-
// one already running. What every watcher answered decides the next
|
|
92
|
-
// arming, and a `due` that landed while the round ran is not lost.
|
|
93
|
-
protected round(now: number, only?: string): Promise<Woke[]> {
|
|
94
|
-
if (this.#round) return this.#round;
|
|
95
|
-
const mine = this.#run(now, only);
|
|
96
|
-
this.#round = mine;
|
|
97
|
-
return mine.finally(() => {
|
|
98
|
-
if (this.#round === mine) this.#round = null;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async #run(now: number, only?: string): Promise<Woke[]> {
|
|
103
|
-
if (only === undefined) this.#arm(null); // the arming is spent, whether it went off or the device called this by hand
|
|
104
|
-
const woke = await this.woke((w) => ({ ...w.args, now }), only);
|
|
105
|
-
if (woke === null) {
|
|
106
|
-
this.stop(); // her ward took her out; there is nobody left to wake
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
// A moment already gone is no arming. Every watcher works out when she is
|
|
110
|
-
// next due from the moment she was handed, so a round fired by hand at a
|
|
111
|
-
// moment that is not this box's answers one that is not this box's
|
|
112
|
-
// either, and a box that armed for it would run a round for a minute long
|
|
113
|
-
// past. A round at the box's own moment always names one still ahead.
|
|
114
|
-
const named = soonest(woke);
|
|
115
|
-
const said = named !== null && named > Date.now() ? named : null;
|
|
116
|
-
const held = this.#armed;
|
|
117
|
-
const at = said === null ? held : held === null ? moment(said) : Math.min(held, moment(said));
|
|
118
|
-
if (at !== null && at !== this.#armed) this.#arm(at);
|
|
119
|
-
else if (at === null && this.#armed !== null) this.#arm(null);
|
|
120
|
-
return woke;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
#arm(when: number | null): void {
|
|
124
|
-
if (this.#stopped) return;
|
|
125
|
-
this.#armed = when;
|
|
126
|
-
this.arm(when);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// The one thing a terrain says about itself: be woken at this moment, or at
|
|
130
|
-
// no moment at all. A subclass replaces this and nothing else of her.
|
|
131
|
-
//
|
|
132
|
-
// Here it is a timeout, capped at a day and armed again when the cap goes
|
|
133
|
-
// off. The box stays up for its work and never for this, so the handle is
|
|
134
|
-
// unreferenced.
|
|
135
|
-
protected arm(when: number | null): void {
|
|
136
|
-
clearTimeout(this.#timeout);
|
|
137
|
-
this.#timeout = undefined;
|
|
138
|
-
if (when === null) return;
|
|
139
|
-
this.#timeout = setTimeout(() => void this.rang(), Math.min(Math.max(when - Date.now(), 0), DAY));
|
|
140
|
-
this.#timeout.unref?.();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// A being her ward took out reaches nobody, so nothing is left to wake. The
|
|
144
|
-
// device calls this when it puts the box down.
|
|
145
|
-
stop(): void {
|
|
146
|
-
this.#stopped = true;
|
|
147
|
-
this.#armed = null;
|
|
148
|
-
this.arm(null);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
now(): JsonObject {
|
|
152
|
-
return { now: Date.now() };
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Half a second past the minute a moment falls in, and never before the
|
|
157
|
-
// moment itself: a watcher floors what she is handed, so a round that fired a
|
|
158
|
-
// hair early would floor to the minute before and fire nothing.
|
|
159
|
-
const moment = (at: number): number => Math.max(at, Math.floor(at / MINUTE) * MINUTE + 500);
|
|
160
|
-
|
|
161
|
-
// What one round learned. Every watcher says when she is next due, and the
|
|
162
|
-
// box arms for the earliest of them. A watcher who named no moment has
|
|
163
|
-
// nothing to be woken for, and so has one who answered something that is no
|
|
164
|
-
// tally at all.
|
|
165
|
-
function soonest(woke: Woke[]): number | null {
|
|
166
|
-
let at: number | null = null;
|
|
167
|
-
for (const w of woke) {
|
|
168
|
-
if (w.out === null || typeof w.out !== 'object') continue;
|
|
169
|
-
const next = (w.out as { next?: unknown }).next;
|
|
170
|
-
if (typeof next !== 'number' || !Number.isFinite(next)) continue;
|
|
171
|
-
if (at === null || next < at) at = next;
|
|
172
|
-
}
|
|
173
|
-
return at;
|
|
174
|
-
}
|
|
File without changes
|
|
File without changes
|