@spellkave/world-events 0.0.0-bootstrap → 0.0.0-stage
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 +3 -0
- package/package.json +4 -25
- package/LICENSE +0 -89
- package/src/act-result.ts +0 -172
- package/src/fanout.ts +0 -66
- package/src/index.ts +0 -32
- package/src/world-events.ts +0 -429
package/README.md
ADDED
package/package.json
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spellkave/world-events",
|
|
3
|
-
"version": "0.0.0-
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"types": "./src/index.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./src/index.ts",
|
|
11
|
-
"default": "./src/index.ts"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"src"
|
|
16
|
-
],
|
|
17
|
-
"license": "PolyForm-Shield-1.0.0",
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/b4mad-technologies/sk-sdk.git",
|
|
21
|
-
"directory": "packages/spellkave-world-events"
|
|
22
|
-
},
|
|
23
|
-
"publishConfig": {
|
|
24
|
-
"access": "public",
|
|
25
|
-
"registry": "https://registry.npmjs.org/"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
3
|
+
"version": "0.0.0-stage",
|
|
4
|
+
"stub": true,
|
|
5
|
+
"description": "Temporary package placeholder for staged publishing"
|
|
6
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# PolyForm Shield License 1.0.0
|
|
2
|
-
|
|
3
|
-
<https://polyformproject.org/licenses/shield/1.0.0>
|
|
4
|
-
|
|
5
|
-
## Acceptance
|
|
6
|
-
|
|
7
|
-
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
8
|
-
|
|
9
|
-
## Copyright License
|
|
10
|
-
|
|
11
|
-
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
12
|
-
|
|
13
|
-
## Distribution License
|
|
14
|
-
|
|
15
|
-
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
16
|
-
|
|
17
|
-
## Notices
|
|
18
|
-
|
|
19
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
20
|
-
|
|
21
|
-
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
22
|
-
|
|
23
|
-
## Changes and New Works License
|
|
24
|
-
|
|
25
|
-
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
26
|
-
|
|
27
|
-
## Patent License
|
|
28
|
-
|
|
29
|
-
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
30
|
-
|
|
31
|
-
## Noncompete
|
|
32
|
-
|
|
33
|
-
Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
|
|
34
|
-
|
|
35
|
-
## Competition
|
|
36
|
-
|
|
37
|
-
Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
|
|
38
|
-
|
|
39
|
-
## New Products
|
|
40
|
-
|
|
41
|
-
If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
|
|
42
|
-
|
|
43
|
-
## Discontinued Products
|
|
44
|
-
|
|
45
|
-
You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
|
|
46
|
-
|
|
47
|
-
> Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
|
|
48
|
-
|
|
49
|
-
## Sales of Business
|
|
50
|
-
|
|
51
|
-
If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
|
|
52
|
-
|
|
53
|
-
## Fair Use
|
|
54
|
-
|
|
55
|
-
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
56
|
-
|
|
57
|
-
## No Other Rights
|
|
58
|
-
|
|
59
|
-
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
60
|
-
|
|
61
|
-
## Patent Defense
|
|
62
|
-
|
|
63
|
-
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
64
|
-
|
|
65
|
-
## Violations
|
|
66
|
-
|
|
67
|
-
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
68
|
-
|
|
69
|
-
## No Liability
|
|
70
|
-
|
|
71
|
-
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
72
|
-
|
|
73
|
-
## Definitions
|
|
74
|
-
|
|
75
|
-
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
76
|
-
|
|
77
|
-
A **product** can be a good or service, or a combination of them.
|
|
78
|
-
|
|
79
|
-
**You** refers to the individual or entity agreeing to these terms.
|
|
80
|
-
|
|
81
|
-
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
|
|
82
|
-
|
|
83
|
-
**Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
|
|
84
|
-
|
|
85
|
-
**Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
86
|
-
|
|
87
|
-
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
88
|
-
|
|
89
|
-
**Use** means anything you do with the software requiring one of your licenses.
|
package/src/act-result.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Closed player-facing classification of one PLAYER act-tool envelope.
|
|
3
|
-
*
|
|
4
|
-
* A reader, not a sniffer: discriminators are modelled fields
|
|
5
|
-
* (`receipt.outcome`, `observation === null` + `observation_gap`,
|
|
6
|
-
* `conversation.response.text`). The default arm is `undescribable`.
|
|
7
|
-
* Quiet cannot be the default. See
|
|
8
|
-
* `ledger/designs/play-act-result-vocabulary.md`.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export type ActPlayerResult =
|
|
12
|
-
| {
|
|
13
|
-
kind: "rejected";
|
|
14
|
-
admission: "rejected" | "unobserved" | "not_offered" | "in_flight";
|
|
15
|
-
player_message: string | null;
|
|
16
|
-
reason: string | null;
|
|
17
|
-
}
|
|
18
|
-
| {
|
|
19
|
-
kind: "happened";
|
|
20
|
-
observation: string | null;
|
|
21
|
-
spoken_by_player: string | null;
|
|
22
|
-
reply: { speaker_name: string | null; text: string } | null;
|
|
23
|
-
awaiting_response: boolean;
|
|
24
|
-
resolution_message: string | null;
|
|
25
|
-
}
|
|
26
|
-
| { kind: "quiet"; gap: string }
|
|
27
|
-
| { kind: "undescribable"; keys: string[] };
|
|
28
|
-
|
|
29
|
-
const PREDISPATCH = new Set([
|
|
30
|
-
"unknown_handle",
|
|
31
|
-
"ambiguous_handle",
|
|
32
|
-
"invalid_sensing_descriptor",
|
|
33
|
-
"unsupported_verb_class",
|
|
34
|
-
"move_in_flight",
|
|
35
|
-
]);
|
|
36
|
-
|
|
37
|
-
const VERB_KEYS = ["manipulate", "communicate", "sense"] as const;
|
|
38
|
-
|
|
39
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
40
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function ownKeys(value: unknown): string[] {
|
|
44
|
-
return isRecord(value) ? Object.keys(value).sort() : [];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function unwrapDetails(input: unknown): unknown {
|
|
48
|
-
if (isRecord(input) && "details" in input) return input.details;
|
|
49
|
-
return input;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function nonEmptyString(value: unknown): string | null {
|
|
53
|
-
return typeof value === "string" && value.trim() !== "" ? value : null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function nestedVerb(receipt: Record<string, unknown>): Record<string, unknown> | null {
|
|
57
|
-
for (const key of VERB_KEYS) {
|
|
58
|
-
const inner = receipt[key];
|
|
59
|
-
if (isRecord(inner)) return inner;
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function readReply(
|
|
65
|
-
conversation: Record<string, unknown> | null,
|
|
66
|
-
): { speaker_name: string | null; text: string } | null {
|
|
67
|
-
if (conversation === null || !isRecord(conversation.response)) return null;
|
|
68
|
-
const text = nonEmptyString(conversation.response.text);
|
|
69
|
-
if (text === null) return null;
|
|
70
|
-
const name = nonEmptyString(conversation.response.speaker_name);
|
|
71
|
-
return { speaker_name: name, text };
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function happenedFields(details: Record<string, unknown>, receipt: Record<string, unknown>) {
|
|
75
|
-
const conversation = isRecord(details.conversation) ? details.conversation : null;
|
|
76
|
-
const spoken = conversation === null ? null : nonEmptyString(conversation.spoken_by_player);
|
|
77
|
-
const verb = nestedVerb(receipt);
|
|
78
|
-
return {
|
|
79
|
-
observation: nonEmptyString(details.observation),
|
|
80
|
-
spoken_by_player: spoken,
|
|
81
|
-
reply: readReply(conversation),
|
|
82
|
-
awaiting_response: conversation?.awaiting_response === true,
|
|
83
|
-
resolution_message: verb === null ? null : nonEmptyString(verb.player_message),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function classifyActResult(input: unknown): ActPlayerResult {
|
|
88
|
-
const details = unwrapDetails(input);
|
|
89
|
-
if (!isRecord(details)) return { kind: "undescribable", keys: [] };
|
|
90
|
-
|
|
91
|
-
const receipt = details.receipt;
|
|
92
|
-
if (isRecord(receipt) && receipt.status === "dispatched") {
|
|
93
|
-
const outcome = receipt.outcome;
|
|
94
|
-
if (outcome === "rejected" || outcome === "unobserved") {
|
|
95
|
-
const verb = nestedVerb(receipt);
|
|
96
|
-
return {
|
|
97
|
-
kind: "rejected",
|
|
98
|
-
admission: outcome,
|
|
99
|
-
player_message: verb === null ? null : nonEmptyString(verb.player_message),
|
|
100
|
-
reason: verb === null ? nonEmptyString(details.reason) : nonEmptyString(verb.reason),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
if (outcome === "travelling") {
|
|
104
|
-
return { kind: "happened", ...happenedFields(details, receipt) };
|
|
105
|
-
}
|
|
106
|
-
if (outcome === "accepted") {
|
|
107
|
-
const fields = happenedFields(details, receipt);
|
|
108
|
-
if (
|
|
109
|
-
fields.reply !== null ||
|
|
110
|
-
fields.observation !== null ||
|
|
111
|
-
fields.resolution_message !== null
|
|
112
|
-
) {
|
|
113
|
-
return { kind: "happened", ...fields };
|
|
114
|
-
}
|
|
115
|
-
const gap = nonEmptyString(details.observation_gap);
|
|
116
|
-
if (details.observation === null && gap !== null) {
|
|
117
|
-
return { kind: "quiet", gap };
|
|
118
|
-
}
|
|
119
|
-
return { kind: "undescribable", keys: ownKeys(details) };
|
|
120
|
-
}
|
|
121
|
-
return { kind: "undescribable", keys: ownKeys(details) };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (typeof details.status === "string" && PREDISPATCH.has(details.status)) {
|
|
125
|
-
return {
|
|
126
|
-
kind: "rejected",
|
|
127
|
-
admission: details.status === "move_in_flight" ? "in_flight" : "not_offered",
|
|
128
|
-
player_message: null,
|
|
129
|
-
reason: nonEmptyString(details.reason),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return { kind: "undescribable", keys: ownKeys(details) };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function renderActResultLine(result: ActPlayerResult): string {
|
|
137
|
-
switch (result.kind) {
|
|
138
|
-
case "rejected":
|
|
139
|
-
if (result.player_message !== null) return result.player_message;
|
|
140
|
-
if (
|
|
141
|
-
(result.admission === "not_offered" || result.admission === "in_flight") &&
|
|
142
|
-
result.reason !== null
|
|
143
|
-
) {
|
|
144
|
-
return result.reason;
|
|
145
|
-
}
|
|
146
|
-
return "The world refused.";
|
|
147
|
-
case "happened":
|
|
148
|
-
if (result.reply !== null) {
|
|
149
|
-
const who = result.reply.speaker_name ?? "Someone";
|
|
150
|
-
return `${who} says: "${result.reply.text}"`;
|
|
151
|
-
}
|
|
152
|
-
// The observation says what the actor DID (the authored outcome
|
|
153
|
-
// prose); the resolution message says how a stochastic act CAME OUT.
|
|
154
|
-
// A client that printed only the first could not tell a success
|
|
155
|
-
// from a failure (seen live, sk-jay0.1.8.63.40). Both are the
|
|
156
|
-
// world's own words, printed as opaque prose, in that order.
|
|
157
|
-
if (result.observation !== null) {
|
|
158
|
-
return result.resolution_message === null ||
|
|
159
|
-
result.observation.includes(result.resolution_message)
|
|
160
|
-
? result.observation
|
|
161
|
-
: `${result.observation} ${result.resolution_message}`;
|
|
162
|
-
}
|
|
163
|
-
if (result.resolution_message !== null) return result.resolution_message;
|
|
164
|
-
if (result.awaiting_response) return "You spoke. No reply yet.";
|
|
165
|
-
if (result.spoken_by_player !== null) return result.spoken_by_player;
|
|
166
|
-
return "The world answered, but this client cannot render it.";
|
|
167
|
-
case "quiet":
|
|
168
|
-
return "Nothing you notice changes.";
|
|
169
|
-
case "undescribable":
|
|
170
|
-
return "The world answered, but this client cannot render it.";
|
|
171
|
-
}
|
|
172
|
-
}
|
package/src/fanout.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { WorldEvent, WorldEventBuilder } from "./world-events.ts";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* One inner cursor, many consumers.
|
|
5
|
-
*
|
|
6
|
-
* `observe()` is the only call that advances the inner builder. Every event
|
|
7
|
-
* it pulls is copied onto a display tap (`drainObserved`) AND into the claim
|
|
8
|
-
* hold. `takeWhere` claims from the hold; leftover `diffAndAdvance` empties
|
|
9
|
-
* whatever was not claimed.
|
|
10
|
-
*
|
|
11
|
-
* Display vs claim are different deliveries of the same occurrence:
|
|
12
|
-
* - **Display** (`drainObserved`): the Play chronicle. A claimed
|
|
13
|
-
* `speech_heard` still appears here — otherwise Aldwin's line vanishes
|
|
14
|
-
* when the reply window takes it and `messageForAct` falls through.
|
|
15
|
-
* - **Claim** (`takeWhere` then leftover): single-delivery between the
|
|
16
|
-
* reply window and a piggyback leftover drain. Leftover must not run
|
|
17
|
-
* while a claim is in flight.
|
|
18
|
-
*/
|
|
19
|
-
export interface WorldEventFanout extends WorldEventBuilder {
|
|
20
|
-
/** Pull newly derived events into the hold and the display tap. */
|
|
21
|
-
observe(): void;
|
|
22
|
-
/**
|
|
23
|
-
* Every event `observe()` (including `takeWhere`'s own observe) pulled
|
|
24
|
-
* since the last drain. Includes events `takeWhere` later claimed.
|
|
25
|
-
*/
|
|
26
|
-
drainObserved(): WorldEvent[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function createWorldEventFanout(inner: WorldEventBuilder): WorldEventFanout {
|
|
30
|
-
let hold: WorldEvent[] = [];
|
|
31
|
-
let observed: WorldEvent[] = [];
|
|
32
|
-
|
|
33
|
-
function observe(): void {
|
|
34
|
-
const fresh = inner.diffAndAdvance();
|
|
35
|
-
if (fresh.length === 0) return;
|
|
36
|
-
hold = hold.length === 0 ? fresh : [...hold, ...fresh];
|
|
37
|
-
observed = observed.length === 0 ? fresh : [...observed, ...fresh];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function drainObserved(): WorldEvent[] {
|
|
41
|
-
const out = observed;
|
|
42
|
-
observed = [];
|
|
43
|
-
return out;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function takeWhere(predicate: (event: WorldEvent) => boolean): WorldEvent[] {
|
|
47
|
-
observe();
|
|
48
|
-
const matched: WorldEvent[] = [];
|
|
49
|
-
const unmatched: WorldEvent[] = [];
|
|
50
|
-
for (const event of hold) {
|
|
51
|
-
if (predicate(event)) matched.push(event);
|
|
52
|
-
else unmatched.push(event);
|
|
53
|
-
}
|
|
54
|
-
hold = unmatched;
|
|
55
|
-
return matched;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function diffAndAdvance(): WorldEvent[] {
|
|
59
|
-
observe();
|
|
60
|
-
const leftover = hold;
|
|
61
|
-
hold = [];
|
|
62
|
-
return leftover;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return { observe, drainObserved, takeWhere, diffAndAdvance };
|
|
66
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
type ActPlayerResult,
|
|
3
|
-
classifyActResult,
|
|
4
|
-
renderActResultLine,
|
|
5
|
-
} from "./act-result.ts";
|
|
6
|
-
export {
|
|
7
|
-
createWorldEventFanout,
|
|
8
|
-
type WorldEventFanout,
|
|
9
|
-
} from "./fanout.ts";
|
|
10
|
-
export {
|
|
11
|
-
type AdvancementAvailableEvent,
|
|
12
|
-
collectConsequences,
|
|
13
|
-
type DealtConditionEvent,
|
|
14
|
-
type DealtHitEvent,
|
|
15
|
-
isCausedByActor,
|
|
16
|
-
type ReactionWindowEvent,
|
|
17
|
-
renderWorldEventLine,
|
|
18
|
-
type SelfConditionChangedEvent,
|
|
19
|
-
type SelfHitEvent,
|
|
20
|
-
type SelfResourceSpentEvent,
|
|
21
|
-
type SessionLifecycleEvent,
|
|
22
|
-
type SpeechHeardEvent,
|
|
23
|
-
shapeConsequences,
|
|
24
|
-
type TraceAddressedEvent,
|
|
25
|
-
type TurnTransitionEvent,
|
|
26
|
-
type WorldEvent,
|
|
27
|
-
type WorldEventBuilder,
|
|
28
|
-
type WorldEventCoordinatorPort,
|
|
29
|
-
type WorldEventDeltaSource,
|
|
30
|
-
type WorldEventSource,
|
|
31
|
-
type XpGainedEvent,
|
|
32
|
-
} from "./world-events.ts";
|
package/src/world-events.ts
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser-safe vocabulary for host-observed world consequences (ADR-0093
|
|
3
|
-
* D-2). This closed union is a delivery protocol over already-authorized host
|
|
4
|
-
* projections, not a gameplay or authoring vocabulary: event producers remain
|
|
5
|
-
* responsible for perception and row admission, while this package owns one
|
|
6
|
-
* exhaustive portable result/renderer shape.
|
|
7
|
-
*
|
|
8
|
-
* Zero runtime dependencies so both `@spellkave/sdk` and
|
|
9
|
-
* `@spellkave/tool-runtime` can import it without inverting their graph.
|
|
10
|
-
*/
|
|
11
|
-
export interface SessionLifecycleEvent {
|
|
12
|
-
kind: "session_lifecycle";
|
|
13
|
-
session_id: string;
|
|
14
|
-
phase: "opened" | "closed";
|
|
15
|
-
participants: string[];
|
|
16
|
-
opened_by: string;
|
|
17
|
-
observed_at_tick: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface TurnTransitionEvent {
|
|
21
|
-
kind: "turn_transition";
|
|
22
|
-
session_id: string;
|
|
23
|
-
from_actor: string | null;
|
|
24
|
-
to_actor: string;
|
|
25
|
-
observed_at_tick: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface SelfHitEvent {
|
|
29
|
-
kind: "self_hit";
|
|
30
|
-
resource_id: string;
|
|
31
|
-
amount: number;
|
|
32
|
-
new_value?: number;
|
|
33
|
-
attack_kind: string;
|
|
34
|
-
attacker_id: string | null;
|
|
35
|
-
/**
|
|
36
|
-
* The attacker's name, resolved by the producer when the event is emitted,
|
|
37
|
-
* from the same name source `dealt_hit.target_name` uses. Optional and
|
|
38
|
-
* additive: the key is ABSENT when the producer resolved no name, when
|
|
39
|
-
* `attacker_id` is `null`, and when the attacker is this actor itself.
|
|
40
|
-
* Never an id and never a placeholder.
|
|
41
|
-
*/
|
|
42
|
-
attacker_name?: string;
|
|
43
|
-
observed_at_tick: number;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface DealtHitEvent {
|
|
47
|
-
kind: "dealt_hit";
|
|
48
|
-
target_name: string;
|
|
49
|
-
amount: number;
|
|
50
|
-
attacker_id: string | null;
|
|
51
|
-
observed_at_tick: number;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface SelfConditionChangedEvent {
|
|
55
|
-
kind: "self_condition_changed";
|
|
56
|
-
condition_id: string;
|
|
57
|
-
applied: boolean;
|
|
58
|
-
source_entity_id: string | null;
|
|
59
|
-
observed_at_tick: number;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface DealtConditionEvent {
|
|
63
|
-
kind: "dealt_condition";
|
|
64
|
-
target_name: string;
|
|
65
|
-
condition_id: string;
|
|
66
|
-
applied: boolean;
|
|
67
|
-
source_entity_id: string | null;
|
|
68
|
-
observed_at_tick: number;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface XpGainedEvent {
|
|
72
|
-
kind: "xp_gained";
|
|
73
|
-
amount: number;
|
|
74
|
-
new_value?: number;
|
|
75
|
-
observed_at_tick: number;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* This actor's own pool went down and the actor caused it (or nobody is named
|
|
80
|
-
* as the cause). A change another entity caused on this actor's pool is not a
|
|
81
|
-
* spend and the producer does not emit it.
|
|
82
|
-
*/
|
|
83
|
-
export interface SelfResourceSpentEvent {
|
|
84
|
-
kind: "self_resource_spent";
|
|
85
|
-
resource_id: string;
|
|
86
|
-
amount: number;
|
|
87
|
-
new_value?: number;
|
|
88
|
-
source: string;
|
|
89
|
-
observed_at_tick: number;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface ReactionWindowEvent {
|
|
93
|
-
kind: "reaction_window";
|
|
94
|
-
window_kind: "reaction" | "intervention";
|
|
95
|
-
phase: "opened" | "closed";
|
|
96
|
-
pending_id: string;
|
|
97
|
-
originating_action_id: string;
|
|
98
|
-
originating_actor: string;
|
|
99
|
-
observed_at_tick: number;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface AdvancementAvailableEvent {
|
|
103
|
-
kind: "advancement_available";
|
|
104
|
-
action_id: string;
|
|
105
|
-
display_name: string;
|
|
106
|
-
observed_at_tick: number;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface SpeechHeardEvent {
|
|
110
|
-
kind: "speech_heard";
|
|
111
|
-
trace_id: string;
|
|
112
|
-
trace_kind: string;
|
|
113
|
-
text: string;
|
|
114
|
-
action_id?: string;
|
|
115
|
-
/** Optional causal response history, disclosed from visible occurrence facts. */
|
|
116
|
-
response?: { action_id: string; slot: number; occurrence_id?: string; label?: string };
|
|
117
|
-
/**
|
|
118
|
-
* The tick the trace was INSCRIBED, straight off the row — never the tick
|
|
119
|
-
* the hearer observed it (`observed_at_tick`). The two differ whenever a
|
|
120
|
-
* drain lags behind the world clock, so an age rule that wants "how old is
|
|
121
|
-
* this utterance" must read this field.
|
|
122
|
-
*/
|
|
123
|
-
inscribed_at: number;
|
|
124
|
-
inscribed_by: string | null;
|
|
125
|
-
/**
|
|
126
|
-
* A name only when the hearer can currently perceive the speaker. A known
|
|
127
|
-
* raw id without a perceivable name stays anonymous in the renderer.
|
|
128
|
-
*/
|
|
129
|
-
inscribed_by_name: string | null;
|
|
130
|
-
/**
|
|
131
|
-
* The entity id this trace's payload named as addressee (`srd/speak-to`'s
|
|
132
|
-
* `carry_addressee` — payload only, never routing: an addressed hearer
|
|
133
|
-
* perceives this the same as anyone else at the anchor,
|
|
134
|
-
* `directed-speech-anchor.md`). `undefined` when the underlying speech
|
|
135
|
-
* carried no addressee at all (broadcast/self-shaped speech, e.g.
|
|
136
|
-
* `srd/speak-aloud`) — a genuinely absent key, not a known-but-unaddressed
|
|
137
|
-
* `null`.
|
|
138
|
-
*/
|
|
139
|
-
addressee?: number | null;
|
|
140
|
-
/**
|
|
141
|
-
* A name only when the hearer can currently perceive the addressee — same
|
|
142
|
-
* "honest absence, never fabricated" rule as `inscribed_by_name`. Present
|
|
143
|
-
* (possibly `null`) exactly when `addressee` is present.
|
|
144
|
-
*/
|
|
145
|
-
addressee_name?: string | null;
|
|
146
|
-
location_kind: string;
|
|
147
|
-
location_ref: string;
|
|
148
|
-
observed_at_tick: number;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export interface TraceAddressedEvent {
|
|
152
|
-
kind: "trace_addressed";
|
|
153
|
-
trace_id: string;
|
|
154
|
-
/** The authored trace kind, carried verbatim. Consumers that care about a
|
|
155
|
-
* specific vocabulary match on this; this package never does. */
|
|
156
|
-
trace_kind: string;
|
|
157
|
-
/**
|
|
158
|
-
* The payload as inscribed. Always includes `addressee`; never includes a
|
|
159
|
-
* string `text` (such rows are `speech_heard`).
|
|
160
|
-
*/
|
|
161
|
-
payload: Readonly<Record<string, unknown>>;
|
|
162
|
-
inscribed_by: string | null;
|
|
163
|
-
/**
|
|
164
|
-
* A name only when this actor can currently perceive the inscriber. Same
|
|
165
|
-
* "honest absence, never fabricated" rule as `SpeechHeardEvent`.
|
|
166
|
-
*/
|
|
167
|
-
inscribed_by_name: string | null;
|
|
168
|
-
/**
|
|
169
|
-
* The tick the trace was INSCRIBED. Never conflate with
|
|
170
|
-
* `observed_at_tick`: an age or staleness rule reads this field, because
|
|
171
|
-
* observation can lag inscription by an unbounded number of ticks.
|
|
172
|
-
*/
|
|
173
|
-
inscribed_at: number;
|
|
174
|
-
/** The entity id the payload named as addressee (payload, not routing). */
|
|
175
|
-
addressee: number;
|
|
176
|
-
/** A name only when this actor can currently perceive the addressee. */
|
|
177
|
-
addressee_name: string | null;
|
|
178
|
-
/**
|
|
179
|
-
* True when THIS actor — the one this event was built for — IS the
|
|
180
|
-
* addressee (`addressee` resolves to the drain's own connected actor).
|
|
181
|
-
* Structural: derived by the producer from comparing ids, never read out
|
|
182
|
-
* of the payload. The renderer below reads this instead of
|
|
183
|
-
* `addressee_name` so a trace directed at the perceiving actor reads
|
|
184
|
-
* "…you" rather than reflecting their own third-person name back at them
|
|
185
|
-
* (sk-jay0.1.8.63.40 — a gap `SpeechHeardEvent`'s `addressee_name` still
|
|
186
|
-
* carries, out of scope here).
|
|
187
|
-
*/
|
|
188
|
-
addressed_at_self: boolean;
|
|
189
|
-
/**
|
|
190
|
-
* An optional authored display string from the payload's `label` key —
|
|
191
|
-
* the ONE well-known, generic key this otherwise payload-blind event
|
|
192
|
-
* reads, the same "one deliberate escape hatch" idiom
|
|
193
|
-
* `AdvancementAvailableEvent.display_name` already uses. A bundle opts
|
|
194
|
-
* into a legible line by inscribing a fixed, non-SRD-specific string here
|
|
195
|
-
* (e.g. an action's own display name plus its outcome, "Ranged Attack
|
|
196
|
-
* misses") — every OTHER payload key stays unread by this renderer
|
|
197
|
-
* (module header's PAYLOAD-BLIND rule, unchanged for anything but this
|
|
198
|
-
* key). `undefined` when the payload carried no string `label` — never
|
|
199
|
-
* fabricated, and the renderer falls back to the generic `trace_kind`
|
|
200
|
-
* line below.
|
|
201
|
-
*/
|
|
202
|
-
label?: string;
|
|
203
|
-
location_kind: string;
|
|
204
|
-
location_ref: string;
|
|
205
|
-
observed_at_tick: number;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export interface TraceDepartureEvent {
|
|
209
|
-
kind: "trace_departure";
|
|
210
|
-
trace_id: string;
|
|
211
|
-
/** The authored trace kind, carried verbatim. Consumers that care about a
|
|
212
|
-
* specific vocabulary match on this; this package never does. */
|
|
213
|
-
trace_kind: string;
|
|
214
|
-
/** Entity id of the body that left (payload `mover`). */
|
|
215
|
-
mover: number;
|
|
216
|
-
/**
|
|
217
|
-
* A name only when this actor can currently perceive the mover — the same
|
|
218
|
-
* "honest absence, never fabricated" rule as `SpeechHeardEvent`'s
|
|
219
|
-
* `inscribed_by_name`. A body that walked out of sight is often exactly
|
|
220
|
-
* the case where this is `null`.
|
|
221
|
-
*/
|
|
222
|
-
mover_name: string | null;
|
|
223
|
-
/** The node the departure was inscribed at — the node LEFT. Equal to
|
|
224
|
-
* `location_ref`, named for the consumer that reads it as a place. */
|
|
225
|
-
from_place_node_id: string;
|
|
226
|
-
/** The place edge taken, as the payload's opaque string handle. */
|
|
227
|
-
via_place_edge_id: string;
|
|
228
|
-
/** The exit's label as the kernel knew it (a pose-derived direction).
|
|
229
|
-
* Empty string when the world could not derive one. */
|
|
230
|
-
exit_label: string;
|
|
231
|
-
/**
|
|
232
|
-
* The tick the trace was INSCRIBED. Never conflate with
|
|
233
|
-
* `observed_at_tick`: a trail perceived on arrival can be several ticks
|
|
234
|
-
* old, and a staleness or ordering rule must read this field.
|
|
235
|
-
*/
|
|
236
|
-
inscribed_at: number;
|
|
237
|
-
location_kind: string;
|
|
238
|
-
location_ref: string;
|
|
239
|
-
observed_at_tick: number;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export type WorldEvent =
|
|
243
|
-
| SessionLifecycleEvent
|
|
244
|
-
| TurnTransitionEvent
|
|
245
|
-
| SelfHitEvent
|
|
246
|
-
| DealtHitEvent
|
|
247
|
-
| XpGainedEvent
|
|
248
|
-
| SelfResourceSpentEvent
|
|
249
|
-
| ReactionWindowEvent
|
|
250
|
-
| AdvancementAvailableEvent
|
|
251
|
-
| SpeechHeardEvent
|
|
252
|
-
| TraceAddressedEvent
|
|
253
|
-
| TraceDepartureEvent
|
|
254
|
-
| SelfConditionChangedEvent
|
|
255
|
-
| DealtConditionEvent;
|
|
256
|
-
|
|
257
|
-
/** The single serialized delta source supplied by an SDK-owning host. */
|
|
258
|
-
export interface WorldEventDeltaSource {
|
|
259
|
-
takeWhere(predicate: (event: WorldEvent) => boolean): WorldEvent[];
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/** Compatibility-friendly name for a host's event-delta source. */
|
|
263
|
-
export type WorldEventSource = WorldEventDeltaSource;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Single-consumer cursor over derived world events. `takeWhere` and
|
|
267
|
-
* `diffAndAdvance` compete for the same sequence: an event flows through
|
|
268
|
-
* exactly once.
|
|
269
|
-
*/
|
|
270
|
-
export interface WorldEventBuilder extends WorldEventDeltaSource {
|
|
271
|
-
diffAndAdvance(): WorldEvent[];
|
|
272
|
-
takeWhere(predicate: (event: WorldEvent) => boolean): WorldEvent[];
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/** Runtime-facing capability port for collecting events caused by one call. */
|
|
276
|
-
export interface WorldEventCoordinatorPort {
|
|
277
|
-
source: WorldEventDeltaSource;
|
|
278
|
-
actorEntityId: string;
|
|
279
|
-
tick: number;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Take each matching event exactly once from the host source. The source owns
|
|
284
|
-
* subscriptions and buffering; the runtime owns common attribution and result
|
|
285
|
-
* shaping without importing the SDK or a transport.
|
|
286
|
-
*/
|
|
287
|
-
export function collectConsequences(port: WorldEventCoordinatorPort): WorldEvent[] {
|
|
288
|
-
return port.source.takeWhere((event) => isCausedByActor(event, port.actorEntityId, port.tick));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/** Add the stable `consequences` result field only when a host wired a port. */
|
|
292
|
-
export function shapeConsequences<TResult extends object>(
|
|
293
|
-
result: TResult,
|
|
294
|
-
port: WorldEventCoordinatorPort | undefined,
|
|
295
|
-
): TResult | (TResult & { consequences: WorldEvent[] }) {
|
|
296
|
-
return port === undefined ? result : { ...result, consequences: collectConsequences(port) };
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export function isCausedByActor(event: WorldEvent, actorEntityId: string, tick: number): boolean {
|
|
300
|
-
// Attribution is deliberately stricter than temporal coincidence. Own-body
|
|
301
|
-
// observations, heard speech, turn changes, and newly visible affordances
|
|
302
|
-
// never become consequences merely because they share the reducer tick.
|
|
303
|
-
if (event.observed_at_tick !== tick) return false;
|
|
304
|
-
switch (event.kind) {
|
|
305
|
-
case "dealt_hit":
|
|
306
|
-
return event.attacker_id === actorEntityId;
|
|
307
|
-
case "dealt_condition":
|
|
308
|
-
return event.source_entity_id === actorEntityId;
|
|
309
|
-
case "self_resource_spent":
|
|
310
|
-
case "xp_gained":
|
|
311
|
-
return true;
|
|
312
|
-
case "reaction_window":
|
|
313
|
-
return event.phase === "opened" && event.originating_actor === actorEntityId;
|
|
314
|
-
case "session_lifecycle":
|
|
315
|
-
return event.phase === "opened" && event.opened_by === actorEntityId;
|
|
316
|
-
case "self_hit":
|
|
317
|
-
case "self_condition_changed":
|
|
318
|
-
case "turn_transition":
|
|
319
|
-
case "advancement_available":
|
|
320
|
-
case "speech_heard":
|
|
321
|
-
case "trace_addressed":
|
|
322
|
-
case "trace_departure":
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* One terse 🌍-voiced line per event, shared by browser and Node hosts.
|
|
329
|
-
* The exhaustive switch keeps the world's narration distinct from agent
|
|
330
|
-
* thought and tool detail. It never invents redacted values or exposes a raw
|
|
331
|
-
* speaker id: an attributed but unperceivable speaker remains "unseen".
|
|
332
|
-
*/
|
|
333
|
-
export function renderWorldEventLine(event: WorldEvent): string {
|
|
334
|
-
switch (event.kind) {
|
|
335
|
-
case "session_lifecycle":
|
|
336
|
-
return event.phase === "opened"
|
|
337
|
-
? `🌍 A session opens (${event.participants.length} participant${event.participants.length === 1 ? "" : "s"}).`
|
|
338
|
-
: "🌍 The session closes.";
|
|
339
|
-
case "turn_transition":
|
|
340
|
-
return event.from_actor === null
|
|
341
|
-
? `🌍 The turn opens with ${event.to_actor}.`
|
|
342
|
-
: `🌍 The turn passes from ${event.from_actor} to ${event.to_actor}.`;
|
|
343
|
-
case "self_hit": {
|
|
344
|
-
// `attack_kind` is a template id and stays out of the sentence; it
|
|
345
|
-
// is still on the event. Without a producer-resolved name the line
|
|
346
|
-
// names nobody: the raw `attacker_id` is never printed.
|
|
347
|
-
const remaining = event.new_value === undefined ? "." : ` — now at ${event.new_value}.`;
|
|
348
|
-
return event.attacker_name !== undefined && event.attacker_name.length > 0
|
|
349
|
-
? `🌍 ${event.attacker_name} hits you for ${event.amount} ${event.resource_id} damage${remaining}`
|
|
350
|
-
: `🌍 You take ${event.amount} ${event.resource_id} damage${remaining}`;
|
|
351
|
-
}
|
|
352
|
-
case "dealt_hit":
|
|
353
|
-
return `🌍 You hit ${event.target_name} for ${event.amount} damage.`;
|
|
354
|
-
case "self_condition_changed":
|
|
355
|
-
return event.applied
|
|
356
|
-
? `🌍 You are now affected by ${event.condition_id}.`
|
|
357
|
-
: `🌍 You are no longer affected by ${event.condition_id}.`;
|
|
358
|
-
case "dealt_condition":
|
|
359
|
-
return event.applied
|
|
360
|
-
? `🌍 ${event.target_name} is now affected by ${event.condition_id}.`
|
|
361
|
-
: `🌍 ${event.target_name} is no longer affected by ${event.condition_id}.`;
|
|
362
|
-
case "xp_gained": {
|
|
363
|
-
const remaining = event.new_value === undefined ? "" : ` — now at ${event.new_value}.`;
|
|
364
|
-
return `🌍 You gain ${event.amount} experience${remaining === "" ? "." : remaining}`;
|
|
365
|
-
}
|
|
366
|
-
case "self_resource_spent": {
|
|
367
|
-
const remaining = event.new_value === undefined ? "" : ` — now at ${event.new_value}.`;
|
|
368
|
-
return `🌍 You spend ${event.amount} ${event.resource_id} (${event.source})${remaining === "" ? "." : remaining}`;
|
|
369
|
-
}
|
|
370
|
-
case "reaction_window":
|
|
371
|
-
return event.phase === "opened"
|
|
372
|
-
? `🌍 A ${event.window_kind} window opens — ${event.originating_actor}'s ${event.originating_action_id}.`
|
|
373
|
-
: `🌍 The ${event.window_kind} window closes.`;
|
|
374
|
-
case "advancement_available":
|
|
375
|
-
return `🌍 A new advancement is available: ${event.display_name}.`;
|
|
376
|
-
case "speech_heard": {
|
|
377
|
-
// `addressee` is `undefined` for untargeted speech (no "to …" clause
|
|
378
|
-
// at all) — never rendered as if it were a known-but-unperceivable
|
|
379
|
-
// addressee (which reads "to someone").
|
|
380
|
-
const toClause =
|
|
381
|
-
event.addressee === undefined || event.addressee === null
|
|
382
|
-
? ""
|
|
383
|
-
: event.addressee_name !== null && event.addressee_name !== undefined
|
|
384
|
-
? ` to ${event.addressee_name}`
|
|
385
|
-
: " to someone";
|
|
386
|
-
if (event.inscribed_by_name !== null)
|
|
387
|
-
return `🌍 ${event.inscribed_by_name} says${toClause}: "${event.text}"`;
|
|
388
|
-
return event.inscribed_by === null
|
|
389
|
-
? `🌍 Something speaks${toClause}: "${event.text}"`
|
|
390
|
-
: `🌍 An unseen speaker says${toClause}: "${event.text}"`;
|
|
391
|
-
}
|
|
392
|
-
case "trace_departure": {
|
|
393
|
-
// PAYLOAD-BLIND beyond the named keys, the same rule as
|
|
394
|
-
// `trace_addressed`: the line is built from `mover_name` and
|
|
395
|
-
// `exit_label` only. The destination is not in the event and is
|
|
396
|
-
// never guessed at — "this way" is the honest line when the world
|
|
397
|
-
// could derive no direction for the exit.
|
|
398
|
-
const way = event.exit_label === "" ? "this way" : `to the ${event.exit_label}`;
|
|
399
|
-
return event.mover_name === null
|
|
400
|
-
? `🌍 Someone leaves ${way}.`
|
|
401
|
-
: `🌍 ${event.mover_name} leaves ${way}.`;
|
|
402
|
-
}
|
|
403
|
-
case "trace_addressed": {
|
|
404
|
-
// PAYLOAD-BLIND ON PURPOSE, with exactly one authored escape hatch:
|
|
405
|
-
// `label` (module header on `TraceAddressedEvent`). Every other
|
|
406
|
-
// payload key stays unread here — dumping the rest would leak an
|
|
407
|
-
// unbounded, unreviewed shape into the world's voice and make this
|
|
408
|
-
// renderer change whenever an author changed a key. The addressee
|
|
409
|
-
// reads "you" when this actor IS the addressee (`addressed_at_self`,
|
|
410
|
-
// a producer-derived id comparison, never a payload key), else the
|
|
411
|
-
// same way `speech_heard` does — a name only when perceived,
|
|
412
|
-
// "someone" otherwise.
|
|
413
|
-
const to = event.addressed_at_self ? "you" : (event.addressee_name ?? "someone");
|
|
414
|
-
if (event.label !== undefined) {
|
|
415
|
-
return event.inscribed_by_name !== null
|
|
416
|
-
? `🌍 ${event.inscribed_by_name}'s ${event.label} ${to}.`
|
|
417
|
-
: event.inscribed_by === null
|
|
418
|
-
? `🌍 Something's ${event.label} ${to}.`
|
|
419
|
-
: `🌍 An unseen figure's ${event.label} ${to}.`;
|
|
420
|
-
}
|
|
421
|
-
const what = event.trace_kind;
|
|
422
|
-
return event.inscribed_by_name !== null
|
|
423
|
-
? `🌍 ${event.inscribed_by_name} signals ${to} (${what}).`
|
|
424
|
-
: event.inscribed_by === null
|
|
425
|
-
? `🌍 Something signals ${to} (${what}).`
|
|
426
|
-
: `🌍 An unseen figure signals ${to} (${what}).`;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|