@serene-pub/sdk 0.6.0-pr-1
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/NOTICE +17 -0
- package/README.md +368 -0
- package/dist/actions.d.ts +572 -0
- package/dist/actions.js +829 -0
- package/dist/annexFields.d.ts +234 -0
- package/dist/annexFields.js +413 -0
- package/dist/announce.d.ts +464 -0
- package/dist/announce.js +426 -0
- package/dist/attributes.d.ts +670 -0
- package/dist/attributes.js +904 -0
- package/dist/bands.d.ts +125 -0
- package/dist/bands.js +256 -0
- package/dist/builder.d.ts +683 -0
- package/dist/builder.js +677 -0
- package/dist/candidates.d.ts +109 -0
- package/dist/candidates.js +118 -0
- package/dist/capabilities.d.ts +744 -0
- package/dist/capabilities.js +679 -0
- package/dist/channels.d.ts +106 -0
- package/dist/channels.js +129 -0
- package/dist/clauses.d.ts +40 -0
- package/dist/clauses.js +43 -0
- package/dist/component.d.ts +33 -0
- package/dist/component.js +27 -0
- package/dist/componentBuild.d.ts +48 -0
- package/dist/componentBuild.js +84 -0
- package/dist/componentClient.d.ts +100 -0
- package/dist/componentClient.js +13 -0
- package/dist/componentImports.d.ts +51 -0
- package/dist/componentImports.js +106 -0
- package/dist/componentModule.d.ts +8 -0
- package/dist/componentModule.js +270 -0
- package/dist/componentWire.d.ts +130 -0
- package/dist/componentWire.js +280 -0
- package/dist/config.d.ts +295 -0
- package/dist/config.js +231 -0
- package/dist/connections.d.ts +89 -0
- package/dist/connections.js +131 -0
- package/dist/declarations.d.ts +290 -0
- package/dist/declarations.js +794 -0
- package/dist/descriptors.d.ts +1774 -0
- package/dist/descriptors.js +1329 -0
- package/dist/dev.d.ts +136 -0
- package/dist/dev.js +161 -0
- package/dist/document.d.ts +202 -0
- package/dist/document.js +312 -0
- package/dist/engines.d.ts +117 -0
- package/dist/engines.js +203 -0
- package/dist/eventMapLaws.d.ts +63 -0
- package/dist/eventMapLaws.js +128 -0
- package/dist/events.d.ts +554 -0
- package/dist/events.js +633 -0
- package/dist/executor.d.ts +771 -0
- package/dist/executor.js +1829 -0
- package/dist/extension.d.ts +448 -0
- package/dist/extension.js +315 -0
- package/dist/facets.d.ts +53 -0
- package/dist/facets.js +60 -0
- package/dist/foldedSections.d.ts +74 -0
- package/dist/foldedSections.js +161 -0
- package/dist/genres.d.ts +507 -0
- package/dist/genres.js +633 -0
- package/dist/guardedConnection.d.ts +138 -0
- package/dist/guardedConnection.js +341 -0
- package/dist/handlebarsReach.d.ts +122 -0
- package/dist/handlebarsReach.js +222 -0
- package/dist/hash.d.ts +146 -0
- package/dist/hash.js +166 -0
- package/dist/hookGrants.d.ts +47 -0
- package/dist/hookGrants.js +68 -0
- package/dist/hooks.d.ts +290 -0
- package/dist/hooks.js +113 -0
- package/dist/hostElements.d.ts +447 -0
- package/dist/hostElements.js +702 -0
- package/dist/i18n.d.ts +94 -0
- package/dist/i18n.js +123 -0
- package/dist/identity.d.ts +93 -0
- package/dist/identity.js +135 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +176 -0
- package/dist/layout.d.ts +194 -0
- package/dist/layout.js +40 -0
- package/dist/media.d.ts +202 -0
- package/dist/media.js +70 -0
- package/dist/messageBlocks.d.ts +487 -0
- package/dist/messageBlocks.js +683 -0
- package/dist/migration.d.ts +128 -0
- package/dist/migration.js +261 -0
- package/dist/names.d.ts +78 -0
- package/dist/names.js +136 -0
- package/dist/nodeInput.d.ts +399 -0
- package/dist/nodeInput.js +178 -0
- package/dist/participants.d.ts +291 -0
- package/dist/participants.js +252 -0
- package/dist/personGate.d.ts +62 -0
- package/dist/personGate.js +77 -0
- package/dist/pick.d.ts +84 -0
- package/dist/pick.js +103 -0
- package/dist/pluginHarness.d.ts +235 -0
- package/dist/pluginHarness.js +558 -0
- package/dist/pluginPermissions.d.ts +25 -0
- package/dist/pluginPermissions.js +97 -0
- package/dist/pluginRuleRef.d.ts +13 -0
- package/dist/pluginRuleRef.js +10 -0
- package/dist/predicates.d.ts +182 -0
- package/dist/predicates.js +249 -0
- package/dist/preview.d.ts +120 -0
- package/dist/preview.js +82 -0
- package/dist/promptBlocks.d.ts +130 -0
- package/dist/promptBlocks.js +197 -0
- package/dist/rankingDecisions.d.ts +60 -0
- package/dist/rankingDecisions.js +48 -0
- package/dist/receipt.d.ts +313 -0
- package/dist/receipt.js +60 -0
- package/dist/receiverRules.d.ts +24 -0
- package/dist/receiverRules.js +94 -0
- package/dist/refs.d.ts +117 -0
- package/dist/refs.js +137 -0
- package/dist/registry.d.ts +230 -0
- package/dist/registry.js +273 -0
- package/dist/review.d.ts +108 -0
- package/dist/review.js +97 -0
- package/dist/sampling.d.ts +152 -0
- package/dist/sampling.js +712 -0
- package/dist/scope.d.ts +65 -0
- package/dist/scope.js +128 -0
- package/dist/scripts.d.ts +243 -0
- package/dist/scripts.js +326 -0
- package/dist/sessionLayout.d.ts +339 -0
- package/dist/sessionLayout.js +503 -0
- package/dist/sessionSettings.d.ts +70 -0
- package/dist/sessionSettings.js +2 -0
- package/dist/settings.d.ts +501 -0
- package/dist/settings.js +604 -0
- package/dist/settingsSlot.d.ts +108 -0
- package/dist/settingsSlot.js +166 -0
- package/dist/shapes.d.ts +373 -0
- package/dist/shapes.js +408 -0
- package/dist/sheets.d.ts +165 -0
- package/dist/sheets.js +251 -0
- package/dist/statShapes.d.ts +96 -0
- package/dist/statShapes.js +112 -0
- package/dist/status.d.ts +103 -0
- package/dist/status.js +125 -0
- package/dist/storage.d.ts +145 -0
- package/dist/storage.js +33 -0
- package/dist/storyTime.d.ts +308 -0
- package/dist/storyTime.js +560 -0
- package/dist/surfaces.d.ts +501 -0
- package/dist/surfaces.js +292 -0
- package/dist/template.d.ts +312 -0
- package/dist/template.js +554 -0
- package/dist/templateCheck.d.ts +60 -0
- package/dist/templateCheck.js +516 -0
- package/dist/templateFit.d.ts +157 -0
- package/dist/templateFit.js +349 -0
- package/dist/templateIds.d.ts +138 -0
- package/dist/templateIds.js +144 -0
- package/dist/templateScopeAt.d.ts +131 -0
- package/dist/templateScopeAt.js +354 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.js +383 -0
- package/dist/tokenizers.d.ts +113 -0
- package/dist/tokenizers.js +184 -0
- package/dist/turnLock.d.ts +96 -0
- package/dist/turnLock.js +79 -0
- package/dist/turnOrder.d.ts +143 -0
- package/dist/turnOrder.js +128 -0
- package/dist/validate.d.ts +74 -0
- package/dist/validate.js +1399 -0
- package/dist/values.d.ts +212 -0
- package/dist/values.js +390 -0
- package/dist/variables.d.ts +493 -0
- package/dist/variables.js +662 -0
- package/dist/verdicts.d.ts +275 -0
- package/dist/verdicts.js +348 -0
- package/dist/widgetDecls.d.ts +88 -0
- package/dist/widgetDecls.js +119 -0
- package/dist/widgets.d.ts +1527 -0
- package/dist/widgets.js +208 -0
- package/dist/wire.d.ts +126 -0
- package/dist/wire.js +140 -0
- package/dist/worldinfo.d.ts +150 -0
- package/dist/worldinfo.js +212 -0
- package/host-elements.d.ts +914 -0
- package/package.json +67 -0
package/dist/pick.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pick hash and the rendezvous pick — one implementation, three callers.
|
|
3
|
+
*
|
|
4
|
+
* A genre that wants a fact *chosen* rather than authored — which suspect did
|
|
5
|
+
* it, which lorebook entry the answer is — needs a rule that is a pure
|
|
6
|
+
* function of the session and the candidates. Nothing may be written down:
|
|
7
|
+
* the only per-session store a spec can reach is the attribute-slot ledger,
|
|
8
|
+
* which a player's own state panel renders, so an answer stored there is an
|
|
9
|
+
* answer on screen. Derived, the create run and every later turn reach the
|
|
10
|
+
* same choice with nothing recorded anywhere.
|
|
11
|
+
*
|
|
12
|
+
* Two plugins and one core genre each wrote this function out before it lived
|
|
13
|
+
* here — Twenty Questions' `pickSecretEntry`, Whodunit's `pickCulprit`, and
|
|
14
|
+
* `core:task/pick-by-hash@1`'s binding in the app. Three copies of a hash is
|
|
15
|
+
* three chances for one of them to drift, and a drifted copy does not fail:
|
|
16
|
+
* it quietly picks a different suspect than the receipt of the same session
|
|
17
|
+
* from last week.
|
|
18
|
+
*
|
|
19
|
+
* ## Rendezvous, not modulo
|
|
20
|
+
*
|
|
21
|
+
* `ids[hash(key) % ids.length]` is the obvious version and it has the wrong
|
|
22
|
+
* failure: every id moves when the list length changes. Seating a fifth
|
|
23
|
+
* suspect halfway through a case would move the answer in four sessions out
|
|
24
|
+
* of five. Rendezvous hashing scores each candidate *on its own* —
|
|
25
|
+
* `hash(key + '#' + itemKey)` — and takes the maximum, so a new candidate
|
|
26
|
+
* displaces the pick exactly when its own score wins: probability 1/n, and
|
|
27
|
+
* the other n-1 sessions are undisturbed. Removing a candidate moves only the
|
|
28
|
+
* sessions that had picked it.
|
|
29
|
+
*
|
|
30
|
+
* ## ⚠ The finalizer is not optional, and leaving it off is a real bug
|
|
31
|
+
*
|
|
32
|
+
* The pick compares whole hashes, so what matters is how the **high** bits are
|
|
33
|
+
* distributed — and plain FNV-1a over strings differing only in their last
|
|
34
|
+
* character or two leaves those bits systematic. Measured over three ids
|
|
35
|
+
* differing in the last digit, plain FNV handed the first of them the answer
|
|
36
|
+
* in 49% of sessions instead of 33%, and a fourth added mid-game displaced it
|
|
37
|
+
* half the time rather than a quarter. The murmur3 `fmix32` tail below puts
|
|
38
|
+
* both back where the arithmetic says they should be. `sdk-tests/pick.test.ts`
|
|
39
|
+
* is what catches it coming back.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* FNV-1a, 32 bits, with murmur3's `fmix32` avalanche on the end. Small,
|
|
43
|
+
* dependency-free, and identical on every machine — the same number in the
|
|
44
|
+
* app's binding, in a plugin's sandbox and in a test.
|
|
45
|
+
*
|
|
46
|
+
* Not `contentHash` from `hash.ts`, and the two must never be confused: that
|
|
47
|
+
* one answers *is this the same declaration?* over a canonical JSON form and
|
|
48
|
+
* is free to change whenever the registries agree to re-project. This one is
|
|
49
|
+
* a **stored answer** in everything but name — change it and every session in
|
|
50
|
+
* flight silently picks somebody else — so it is frozen by its tests.
|
|
51
|
+
* @experimental
|
|
52
|
+
*/
|
|
53
|
+
export declare function pickHash32(text: string): number;
|
|
54
|
+
/** What the pick answers: the winning item, where it sat, and the key it won under. @public */
|
|
55
|
+
export interface RendezvousPick<T> {
|
|
56
|
+
item: T;
|
|
57
|
+
/** Its index in the list **as handed in**, not among the candidates. */
|
|
58
|
+
index: number;
|
|
59
|
+
/** The identity it was scored under — what a later comparison compares against. */
|
|
60
|
+
key: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The highest-scoring candidate for this key, or `null` when nothing
|
|
64
|
+
* identifiable was offered.
|
|
65
|
+
*
|
|
66
|
+
* Deterministic in both arguments and in **neither's order**: each candidate
|
|
67
|
+
* is scored on its own, and a tie is settled by the lower item key rather
|
|
68
|
+
* than by arrival, so a query that happened to return its rows the other way
|
|
69
|
+
* round reaches the same answer. (A tie needs two keys colliding in all 32
|
|
70
|
+
* bits; the rule exists so that the *answer* does not depend on row order
|
|
71
|
+
* even then.)
|
|
72
|
+
*
|
|
73
|
+
* `keyOf` answers `null` for an entry with no identity — a hole in the list,
|
|
74
|
+
* a row the caller cannot name — and those are skipped rather than scored
|
|
75
|
+
* under `'undefined'`, which would make every nameless entry the same
|
|
76
|
+
* candidate.
|
|
77
|
+
*
|
|
78
|
+
* ⚠ `key` is the session's own address (`session:41`) or something equally
|
|
79
|
+
* durable. It must **not** be a run's seed: that is a different string every
|
|
80
|
+
* turn, and a pick keyed on it would move between two questions.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export declare function rendezvousPick<T>(items: readonly T[], key: string, keyOf: (item: T, index: number) => string | null): RendezvousPick<T> | null;
|
|
84
|
+
//# sourceMappingURL=pick.d.ts.map
|
package/dist/pick.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pick hash and the rendezvous pick — one implementation, three callers.
|
|
3
|
+
*
|
|
4
|
+
* A genre that wants a fact *chosen* rather than authored — which suspect did
|
|
5
|
+
* it, which lorebook entry the answer is — needs a rule that is a pure
|
|
6
|
+
* function of the session and the candidates. Nothing may be written down:
|
|
7
|
+
* the only per-session store a spec can reach is the attribute-slot ledger,
|
|
8
|
+
* which a player's own state panel renders, so an answer stored there is an
|
|
9
|
+
* answer on screen. Derived, the create run and every later turn reach the
|
|
10
|
+
* same choice with nothing recorded anywhere.
|
|
11
|
+
*
|
|
12
|
+
* Two plugins and one core genre each wrote this function out before it lived
|
|
13
|
+
* here — Twenty Questions' `pickSecretEntry`, Whodunit's `pickCulprit`, and
|
|
14
|
+
* `core:task/pick-by-hash@1`'s binding in the app. Three copies of a hash is
|
|
15
|
+
* three chances for one of them to drift, and a drifted copy does not fail:
|
|
16
|
+
* it quietly picks a different suspect than the receipt of the same session
|
|
17
|
+
* from last week.
|
|
18
|
+
*
|
|
19
|
+
* ## Rendezvous, not modulo
|
|
20
|
+
*
|
|
21
|
+
* `ids[hash(key) % ids.length]` is the obvious version and it has the wrong
|
|
22
|
+
* failure: every id moves when the list length changes. Seating a fifth
|
|
23
|
+
* suspect halfway through a case would move the answer in four sessions out
|
|
24
|
+
* of five. Rendezvous hashing scores each candidate *on its own* —
|
|
25
|
+
* `hash(key + '#' + itemKey)` — and takes the maximum, so a new candidate
|
|
26
|
+
* displaces the pick exactly when its own score wins: probability 1/n, and
|
|
27
|
+
* the other n-1 sessions are undisturbed. Removing a candidate moves only the
|
|
28
|
+
* sessions that had picked it.
|
|
29
|
+
*
|
|
30
|
+
* ## ⚠ The finalizer is not optional, and leaving it off is a real bug
|
|
31
|
+
*
|
|
32
|
+
* The pick compares whole hashes, so what matters is how the **high** bits are
|
|
33
|
+
* distributed — and plain FNV-1a over strings differing only in their last
|
|
34
|
+
* character or two leaves those bits systematic. Measured over three ids
|
|
35
|
+
* differing in the last digit, plain FNV handed the first of them the answer
|
|
36
|
+
* in 49% of sessions instead of 33%, and a fourth added mid-game displaced it
|
|
37
|
+
* half the time rather than a quarter. The murmur3 `fmix32` tail below puts
|
|
38
|
+
* both back where the arithmetic says they should be. `sdk-tests/pick.test.ts`
|
|
39
|
+
* is what catches it coming back.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* FNV-1a, 32 bits, with murmur3's `fmix32` avalanche on the end. Small,
|
|
43
|
+
* dependency-free, and identical on every machine — the same number in the
|
|
44
|
+
* app's binding, in a plugin's sandbox and in a test.
|
|
45
|
+
*
|
|
46
|
+
* Not `contentHash` from `hash.ts`, and the two must never be confused: that
|
|
47
|
+
* one answers *is this the same declaration?* over a canonical JSON form and
|
|
48
|
+
* is free to change whenever the registries agree to re-project. This one is
|
|
49
|
+
* a **stored answer** in everything but name — change it and every session in
|
|
50
|
+
* flight silently picks somebody else — so it is frozen by its tests.
|
|
51
|
+
* @experimental
|
|
52
|
+
*/
|
|
53
|
+
export function pickHash32(text) {
|
|
54
|
+
let h = 0x811c9dc5;
|
|
55
|
+
for (let i = 0; i < text.length; i++) {
|
|
56
|
+
h ^= text.charCodeAt(i);
|
|
57
|
+
h = Math.imul(h, 0x01000193) >>> 0;
|
|
58
|
+
}
|
|
59
|
+
h ^= h >>> 16;
|
|
60
|
+
h = Math.imul(h, 0x85ebca6b) >>> 0;
|
|
61
|
+
h ^= h >>> 13;
|
|
62
|
+
h = Math.imul(h, 0xc2b2ae35) >>> 0;
|
|
63
|
+
h ^= h >>> 16;
|
|
64
|
+
return h >>> 0;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The highest-scoring candidate for this key, or `null` when nothing
|
|
68
|
+
* identifiable was offered.
|
|
69
|
+
*
|
|
70
|
+
* Deterministic in both arguments and in **neither's order**: each candidate
|
|
71
|
+
* is scored on its own, and a tie is settled by the lower item key rather
|
|
72
|
+
* than by arrival, so a query that happened to return its rows the other way
|
|
73
|
+
* round reaches the same answer. (A tie needs two keys colliding in all 32
|
|
74
|
+
* bits; the rule exists so that the *answer* does not depend on row order
|
|
75
|
+
* even then.)
|
|
76
|
+
*
|
|
77
|
+
* `keyOf` answers `null` for an entry with no identity — a hole in the list,
|
|
78
|
+
* a row the caller cannot name — and those are skipped rather than scored
|
|
79
|
+
* under `'undefined'`, which would make every nameless entry the same
|
|
80
|
+
* candidate.
|
|
81
|
+
*
|
|
82
|
+
* ⚠ `key` is the session's own address (`session:41`) or something equally
|
|
83
|
+
* durable. It must **not** be a run's seed: that is a different string every
|
|
84
|
+
* turn, and a pick keyed on it would move between two questions.
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
export function rendezvousPick(items, key, keyOf) {
|
|
88
|
+
let best = null;
|
|
89
|
+
let bestScore = -1;
|
|
90
|
+
for (let i = 0; i < items.length; i++) {
|
|
91
|
+
const item = items[i];
|
|
92
|
+
const itemKey = keyOf(item, i);
|
|
93
|
+
if (typeof itemKey !== 'string' || !itemKey)
|
|
94
|
+
continue;
|
|
95
|
+
const score = pickHash32(`${key}#${itemKey}`);
|
|
96
|
+
if (score > bestScore || (score === bestScore && best !== null && itemKey < best.key)) {
|
|
97
|
+
best = { item, index: i, key: itemKey };
|
|
98
|
+
bestScore = score;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return best;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=pick.js.map
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The **plugin sandbox's context, in the author's harness** (plans 29 §14 D-3).
|
|
3
|
+
*
|
|
4
|
+
* The SDK's executor builds a node's context itself — `{ signal, progress,
|
|
5
|
+
* status, log, countTokens }`, plus `read` for a Query, `call` for an Oracle and
|
|
6
|
+
* `commit` for an Outlet. That is the context a **core** handler runs against,
|
|
7
|
+
* and it is *not* the one a **plugin's** handler ever sees. At install a
|
|
8
|
+
* plugin's node handlers do not go through that path at all: the app's
|
|
9
|
+
* `pipelines/runtime/pluginBindings.ts` calls `RuntimeManager.callHook`, which
|
|
10
|
+
* runs the hook inside the plugin's sandbox against a context the sandbox
|
|
11
|
+
* builds — `{ random, now, log, storage, fetch, signal }` — and commits its rows
|
|
12
|
+
* afterwards.
|
|
13
|
+
*
|
|
14
|
+
* Two packages paid for that gap before it was written down:
|
|
15
|
+
*
|
|
16
|
+
* - **Twenty Questions shipped a dead Query.** Its `ctx.read` worked in the
|
|
17
|
+
* harness, because the executor endows `read` for every Query whoever wrote
|
|
18
|
+
* it. No sandbox endows it, so the query would have read nothing at install.
|
|
19
|
+
* - **Battleship had to write its own fake store.** Nothing in the harness
|
|
20
|
+
* endows `ctx.storage`, so a package whose whole point is that one handler
|
|
21
|
+
* reads back what another wrote could not run its own handlers without
|
|
22
|
+
* hand-wrapping every binding.
|
|
23
|
+
*
|
|
24
|
+
* So this module endows the *sandbox's* surface, and endows **only** that: a
|
|
25
|
+
* plugin Query's `ctx.read` is `undefined` here exactly as it is at install, and
|
|
26
|
+
* a test written against it fails the way the install would. The executor's own
|
|
27
|
+
* conveniences — `progress`, `status`, `countTokens`, `iteration`, `scripts` —
|
|
28
|
+
* are absent for the same reason: no sandbox has ever defined them.
|
|
29
|
+
*
|
|
30
|
+
* ⚠ **Not the real sandbox.** No opaque origin, no worker, no QuickJS, no
|
|
31
|
+
* membrane; the handler runs in this process with ordinary references. What is
|
|
32
|
+
* reproduced is the *shape* — which members exist, which are withheld, what a
|
|
33
|
+
* refusal says, and where the randomness and the clock come from — because that
|
|
34
|
+
* is what a handler can be written against and get wrong.
|
|
35
|
+
*/
|
|
36
|
+
import { type Bindings, type Result } from './executor.js';
|
|
37
|
+
import type { HookFetchInit, HookFetchResponse } from './hooks.js';
|
|
38
|
+
import type { ExtensionStorage } from './storage.js';
|
|
39
|
+
import { type HookCtxGrants, type HookCtxKind } from './hookGrants.js';
|
|
40
|
+
export { HOOK_CTX_KINDS, hookCtxGrants, hookCtxKeysFor, isHookCtxKind, type HookCtxGrants, type HookCtxKind } from './hookGrants.js';
|
|
41
|
+
/**
|
|
42
|
+
* The sandbox's RNG — xfnv1a over the seed label, then mulberry32.
|
|
43
|
+
*
|
|
44
|
+
* ⚠ **Not `seededRandom`.** The executor's RNG (executor.ts) is a different
|
|
45
|
+
* algorithm over a different seed, and the two produce different streams from
|
|
46
|
+
* the same word. That is a fact about the two codebases, not a design: a plugin
|
|
47
|
+
* handler's rolls come from the *sandbox's* stream, so a golden over a handler
|
|
48
|
+
* that rolls is only reproducible against this one. Kept byte-for-byte in step
|
|
49
|
+
* with `buildProgram` in the app's `QuickJsSandbox.ts` / `SesWorkerSandbox.ts`.
|
|
50
|
+
* @experimental
|
|
51
|
+
*/
|
|
52
|
+
export declare function pluginSeededRandom(label: string): () => number;
|
|
53
|
+
/**
|
|
54
|
+
* djb2 over the serialized input — the app's per-call address, so the seed
|
|
55
|
+
* label a harness composes is the label an install composes (`pluginBindings.ts`).
|
|
56
|
+
* @experimental
|
|
57
|
+
*/
|
|
58
|
+
export declare function inputDigest(v: unknown): string;
|
|
59
|
+
/**
|
|
60
|
+
* The seed label a plugin node handler's RNG is derived from, as the app
|
|
61
|
+
* composes it: the run seed, the pin, and a digest of the exact input — so
|
|
62
|
+
* replays roll the same and two same-typed nodes in one run (or one node under
|
|
63
|
+
* `each`) get distinct streams without depending on completion order.
|
|
64
|
+
* @experimental
|
|
65
|
+
*/
|
|
66
|
+
export declare const nodeSeedLabel: (seed: string, pin: string, input: unknown) => string;
|
|
67
|
+
/** The prelude's `__fmtLog`: `[level] message detail…`, or `[log] …`. @experimental */
|
|
68
|
+
export declare function formatHookLog(args: unknown[]): string;
|
|
69
|
+
/**
|
|
70
|
+
* The row half of the grant, as a fraction of it — mirrors `rowQuotaFor` in the
|
|
71
|
+
* app's `storageHost.ts`, which is the arithmetic the sandbox actually applies.
|
|
72
|
+
* Rows live in the database and files on disk; one budget is what an author can
|
|
73
|
+
* reason about, and the sub-cap is what stops a plugin putting megabytes in the
|
|
74
|
+
* database.
|
|
75
|
+
* @experimental
|
|
76
|
+
*/
|
|
77
|
+
export declare function rowQuotaFor(quotaBytes: number): number;
|
|
78
|
+
/** The grant a sandbox falls back to when the manifest declares none. @experimental */
|
|
79
|
+
export declare const DEFAULT_STORAGE_QUOTA_BYTES: number;
|
|
80
|
+
/**
|
|
81
|
+
* The clock this harness pins when a caller names none.
|
|
82
|
+
*
|
|
83
|
+
* Deliberately the same instant as `EXAMPLE_CLOCK` in `testing.ts`, so a
|
|
84
|
+
* handler run inside an executed example and the same handler run in a unit
|
|
85
|
+
* test report the same `ctx.now()` — a golden that moved between the two would
|
|
86
|
+
* be a golden nobody keeps. Defined here rather than imported because
|
|
87
|
+
* `testing.ts` re-exports this module, and a test pins that the two agree.
|
|
88
|
+
* @experimental
|
|
89
|
+
*/
|
|
90
|
+
export declare const HARNESS_CLOCK = 1700000000000;
|
|
91
|
+
/** @experimental */
|
|
92
|
+
export interface MemoryStorageOptions {
|
|
93
|
+
/** The grant, in bytes. The sandbox's own fallback by default. */
|
|
94
|
+
quotaBytes?: number;
|
|
95
|
+
/** The sub-cap on the row half. Derived from `quotaBytes` by default. */
|
|
96
|
+
rowQuotaBytes?: number;
|
|
97
|
+
/** Rows to start with, for a test that wants a game already in progress. */
|
|
98
|
+
seed?: Record<string, unknown>;
|
|
99
|
+
/**
|
|
100
|
+
* The call's pinned clock, which is what stamps a row's `updatedAt`.
|
|
101
|
+
*
|
|
102
|
+
* Pinned, not ticking, because that is what install does: the sandbox stamps
|
|
103
|
+
* every row a call writes with the run's clock, so rows written in one call
|
|
104
|
+
* share a timestamp and `query({ order: 'newest' })` falls back to key order
|
|
105
|
+
* among them. A test that wants distinct stamps supplies a clock that moves.
|
|
106
|
+
*/
|
|
107
|
+
now?: () => number;
|
|
108
|
+
}
|
|
109
|
+
/** @experimental */
|
|
110
|
+
export interface MemoryStorage extends ExtensionStorage {
|
|
111
|
+
/** Every key currently held with its value, key-sorted — for asserting on the shape of the store. */
|
|
112
|
+
snapshot(): Record<string, unknown>;
|
|
113
|
+
/** How many times `put` has been called. A cheap way to pin "this handler wrote once". */
|
|
114
|
+
readonly writes: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* An in-memory `ExtensionStorage` — the half the SDK's harness cannot otherwise
|
|
118
|
+
* supply, with the refusals install actually makes.
|
|
119
|
+
*
|
|
120
|
+
* Faithful in the ways a handler can depend on: `get` answers `undefined` for a
|
|
121
|
+
* key nobody wrote; a row costs its key as well as its value; a write past the
|
|
122
|
+
* row budget or the whole grant comes back as `err` rather than throwing, and
|
|
123
|
+
* comes back **whole** so a handler that prunes and retries can; a key that is
|
|
124
|
+
* not a key, and a value JSON cannot carry, throw with the sandbox's sentence.
|
|
125
|
+
*
|
|
126
|
+
* ⚠ Not faithful about: transactions (install commits a call's rows together,
|
|
127
|
+
* this writes as it goes), the database, and the bytes a row costs on disk.
|
|
128
|
+
* What it does reproduce is the one property a package like Battleship exists
|
|
129
|
+
* to demonstrate — a row one handler writes is a row the next handler reads.
|
|
130
|
+
*
|
|
131
|
+
* **Isolation is structural.** One call is one namespace; two plugins get two
|
|
132
|
+
* calls and neither can name the other's keys, because there is no shared map
|
|
133
|
+
* to name them in.
|
|
134
|
+
* @experimental
|
|
135
|
+
*/
|
|
136
|
+
export declare function memoryStorage(opts?: MemoryStorageOptions): MemoryStorage;
|
|
137
|
+
/** What `ctx.fetch` answers with once the allowlist has let a call through. @experimental */
|
|
138
|
+
export type HookFetchAnswer = (url: string, init?: HookFetchInit) => HookFetchResponse | Promise<HookFetchResponse>;
|
|
139
|
+
/**
|
|
140
|
+
* What a plugin's handler is handed — the sandbox's six, no more.
|
|
141
|
+
*
|
|
142
|
+
* `storage` and `fetch` are optional here for the reason they are absent there:
|
|
143
|
+
* a member a kind is not granted is **absent**, not a stub that refuses, so
|
|
144
|
+
* `Object.keys(ctx)` says exactly what the hook may reach.
|
|
145
|
+
* @experimental
|
|
146
|
+
*/
|
|
147
|
+
export interface PluginHandlerContext {
|
|
148
|
+
/** Seeded from the run seed (`pluginSeededRandom`). Never `Math.random`. */
|
|
149
|
+
random(): number;
|
|
150
|
+
/** The run's clock, pinned. Two calls in one run return the same number. */
|
|
151
|
+
now(): number;
|
|
152
|
+
log(...args: unknown[]): void;
|
|
153
|
+
storage?: ExtensionStorage;
|
|
154
|
+
fetch?(url: string, init?: HookFetchInit): Promise<HookFetchResponse>;
|
|
155
|
+
signal: AbortSignal;
|
|
156
|
+
}
|
|
157
|
+
/** @experimental */
|
|
158
|
+
export interface PluginHandlerContextOptions {
|
|
159
|
+
/** The extension's address, for the sentences a refusal writes. */
|
|
160
|
+
pluginId: string;
|
|
161
|
+
/**
|
|
162
|
+
* The RNG's seed label. `pluginNodeBindings` composes the app's
|
|
163
|
+
* (`nodeSeedLabel`); a test calling this directly passes whatever it wants
|
|
164
|
+
* to be able to reproduce.
|
|
165
|
+
*/
|
|
166
|
+
seed?: string;
|
|
167
|
+
/** The hook kind, which decides the grants (R-3). Omitted: both granted. */
|
|
168
|
+
kind?: HookCtxKind;
|
|
169
|
+
/** Override the kind's grants — for pinning what a handler does without one. */
|
|
170
|
+
grants?: Partial<HookCtxGrants>;
|
|
171
|
+
/** The extension's store. A fresh `memoryStorage()` when the grant holds and none is given. */
|
|
172
|
+
storage?: ExtensionStorage;
|
|
173
|
+
/** The pinned clock, in milliseconds. */
|
|
174
|
+
now?: number;
|
|
175
|
+
signal?: AbortSignal;
|
|
176
|
+
/** The hosts the manifest declares under `permissions.network.hosts`. */
|
|
177
|
+
network?: readonly string[];
|
|
178
|
+
/** What an allowed call answers with. Absent: an allowed call still refuses, and says so. */
|
|
179
|
+
fetch?: HookFetchAnswer;
|
|
180
|
+
/** Where `ctx.log` lines land, formatted as the sandbox prelude formats them. */
|
|
181
|
+
logs?: string[];
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Build the context a plugin's handler runs against at install.
|
|
185
|
+
*
|
|
186
|
+
* The one-liner `examples/fixtures.ts` in a plugin repo should not have to
|
|
187
|
+
* write: pass it to a handler and the handler sees what the sandbox gives it,
|
|
188
|
+
* including the absences.
|
|
189
|
+
* @experimental
|
|
190
|
+
*/
|
|
191
|
+
export declare function pluginHandlerContext(opts: PluginHandlerContextOptions): PluginHandlerContext;
|
|
192
|
+
/** A plugin's node handler: `(input, ctx)`, with the sandbox's ctx. @experimental */
|
|
193
|
+
export type PluginNodeHandler = (input: any, ctx: PluginHandlerContext) => Result | Promise<Result>;
|
|
194
|
+
/** @experimental */
|
|
195
|
+
export interface PluginNodeBindingOptions {
|
|
196
|
+
/** The extension's address — one store, one seed namespace, one set of grants. */
|
|
197
|
+
pluginId: string;
|
|
198
|
+
/** `definitionId@version` → the handler the manifest's `nodeDefinitions` names. */
|
|
199
|
+
handlers: Record<string, PluginNodeHandler>;
|
|
200
|
+
/**
|
|
201
|
+
* The extension's store, shared by every handler below — which is the whole
|
|
202
|
+
* point: one plugin is one namespace, so a row `place` writes is a row
|
|
203
|
+
* `fire` reads. A fresh `memoryStorage()` when none is given.
|
|
204
|
+
*/
|
|
205
|
+
storage?: ExtensionStorage;
|
|
206
|
+
/** The run seed the RNG labels derive from. */
|
|
207
|
+
seed?: string;
|
|
208
|
+
/** The pinned clock. */
|
|
209
|
+
now?: number;
|
|
210
|
+
network?: readonly string[];
|
|
211
|
+
fetch?: HookFetchAnswer;
|
|
212
|
+
logs?: string[];
|
|
213
|
+
/**
|
|
214
|
+
* The hook ctx kind per pin, for a definition this process has not
|
|
215
|
+
* registered. A registered one is read off its descriptor, which is the
|
|
216
|
+
* answer install reads off the registry row.
|
|
217
|
+
*/
|
|
218
|
+
kinds?: Record<string, HookCtxKind>;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Project a plugin's handlers into executor bindings that run them against the
|
|
222
|
+
* **sandbox's** context — the harness's counterpart of the app's
|
|
223
|
+
* `pluginNodeBindings` (`pipelines/runtime/pluginBindings.ts`), which does the
|
|
224
|
+
* same projection over a real sandbox.
|
|
225
|
+
*
|
|
226
|
+
* The executor's own context reaches the handler in exactly one respect: its
|
|
227
|
+
* `signal`, because at install the host fires the sandbox's abort from the same
|
|
228
|
+
* place. Everything else it built — `read`, `call`, `commit`, `progress`,
|
|
229
|
+
* `status`, `countTokens` — is dropped, because no sandbox has ever endowed it.
|
|
230
|
+
* A plugin Query reaching for `ctx.read` therefore fails here exactly as it
|
|
231
|
+
* fails at install, which is the whole reason this exists (G13).
|
|
232
|
+
* @experimental
|
|
233
|
+
*/
|
|
234
|
+
export declare function pluginNodeBindings(opts: PluginNodeBindingOptions): Bindings;
|
|
235
|
+
//# sourceMappingURL=pluginHarness.d.ts.map
|