@spellkave/sdk 0.0.0-stage → 0.1.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/LICENSE +89 -0
- package/README.md +155 -2
- package/package.json +63 -4
- package/src/binding_rows.ts +186 -0
- package/src/connection.ts +964 -0
- package/src/core/actor.ts +62 -0
- package/src/core/actor_control.ts +193 -0
- package/src/core/actor_control_query_methods.ts +101 -0
- package/src/core/actor_control_reaction_methods.ts +79 -0
- package/src/core/actor_control_sense_methods.ts +81 -0
- package/src/core/actor_control_source.ts +57 -0
- package/src/core/actor_session_methods.ts +226 -0
- package/src/core/binding_drift.ts +301 -0
- package/src/core/credential.ts +259 -0
- package/src/core/driver_control.ts +54 -0
- package/src/core/effective_environment_state.ts +71 -0
- package/src/core/factored_manipulation_attempt.ts +158 -0
- package/src/core/ids.ts +60 -0
- package/src/core/interaction/canonical.ts +15 -0
- package/src/core/interaction/fingerprint.ts +118 -0
- package/src/core/interaction/index.ts +31 -0
- package/src/core/interaction/intent.ts +284 -0
- package/src/core/interaction/outcome.ts +67 -0
- package/src/core/interaction/rejection_ledger.ts +108 -0
- package/src/core/kernel_contract.generated.ts +10 -0
- package/src/core/log.ts +23 -0
- package/src/core/movement.ts +111 -0
- package/src/core/node-io.ts +208 -0
- package/src/core/paths.ts +220 -0
- package/src/core/profile.ts +270 -0
- package/src/core/profiles.ts +9 -0
- package/src/core/provenance_buffer.ts +102 -0
- package/src/core/readers/_helpers.ts +273 -0
- package/src/core/readers/action_description.ts +17 -0
- package/src/core/readers/action_economy_events.ts +149 -0
- package/src/core/readers/actor_body_swaps.ts +62 -0
- package/src/core/readers/actor_snapshot.ts +197 -0
- package/src/core/readers/actor_states.ts +163 -0
- package/src/core/readers/actors_and_bodies.ts +179 -0
- package/src/core/readers/affordance_cue.ts +59 -0
- package/src/core/readers/affordance_defaults.ts +158 -0
- package/src/core/readers/affordance_group_membership.ts +67 -0
- package/src/core/readers/affordance_input.ts +129 -0
- package/src/core/readers/affordance_reference.ts +41 -0
- package/src/core/readers/apply_consequences.ts +54 -0
- package/src/core/readers/audience_trace_presentation.ts +62 -0
- package/src/core/readers/bounded_collection.ts +29 -0
- package/src/core/readers/bundle_definitions.ts +74 -0
- package/src/core/readers/bundle_entities.ts +62 -0
- package/src/core/readers/co_location.ts +71 -0
- package/src/core/readers/combat_session.ts +124 -0
- package/src/core/readers/combat_session_active.ts +44 -0
- package/src/core/readers/combat_session_feedback.ts +37 -0
- package/src/core/readers/combat_session_grid.ts +117 -0
- package/src/core/readers/combat_session_roster.ts +98 -0
- package/src/core/readers/combat_session_types.ts +51 -0
- package/src/core/readers/condition_deltas.ts +53 -0
- package/src/core/readers/container_contents.ts +92 -0
- package/src/core/readers/dialogue_guide.ts +99 -0
- package/src/core/readers/dialogue_prompt_presentation.ts +90 -0
- package/src/core/readers/driver_control.ts +64 -0
- package/src/core/readers/entity_art.ts +219 -0
- package/src/core/readers/entity_containment.ts +119 -0
- package/src/core/readers/equipment.ts +99 -0
- package/src/core/readers/intervention_windows.ts +136 -0
- package/src/core/readers/inventory_query.ts +145 -0
- package/src/core/readers/item_detail.ts +198 -0
- package/src/core/readers/location_snapshot.ts +216 -0
- package/src/core/readers/manifest_apply_provenance.ts +32 -0
- package/src/core/readers/manifest_export.ts +81 -0
- package/src/core/readers/manipulation_context.ts +475 -0
- package/src/core/readers/map_layers.ts +49 -0
- package/src/core/readers/metadata_rows.ts +56 -0
- package/src/core/readers/object_state.ts +124 -0
- package/src/core/readers/observer_knowledge.ts +41 -0
- package/src/core/readers/observer_place_knowledge.ts +37 -0
- package/src/core/readers/observer_trace_knowledge.ts +45 -0
- package/src/core/readers/outcome_template.ts +41 -0
- package/src/core/readers/place_topology.ts +109 -0
- package/src/core/readers/reaction_options.ts +156 -0
- package/src/core/readers/resource_deltas.ts +47 -0
- package/src/core/readers/scene.ts +275 -0
- package/src/core/readers/seats.ts +33 -0
- package/src/core/readers/self.ts +245 -0
- package/src/core/readers/self_capabilities.ts +159 -0
- package/src/core/readers/self_economy.ts +101 -0
- package/src/core/readers/self_economy_budget.ts +93 -0
- package/src/core/readers/self_evaluations.ts +128 -0
- package/src/core/readers/self_identity.ts +104 -0
- package/src/core/readers/sense_context.ts +112 -0
- package/src/core/readers/session.ts +207 -0
- package/src/core/readers/session_detail.ts +211 -0
- package/src/core/readers/session_status.ts +68 -0
- package/src/core/readers/spatial_environment_state.ts +74 -0
- package/src/core/readers/spatial_niche_attachments.ts +28 -0
- package/src/core/readers/substrate_definitions.ts +27 -0
- package/src/core/readers/suggest_next_action.ts +72 -0
- package/src/core/readers/surface_membership.ts +78 -0
- package/src/core/readers/tag_reads.ts +54 -0
- package/src/core/readers/trace_query.ts +120 -0
- package/src/core/readers/trace_response.ts +80 -0
- package/src/core/readers/traces.ts +124 -0
- package/src/core/readers/travel_session.ts +88 -0
- package/src/core/readers/turn_state.ts +34 -0
- package/src/core/readers/world_events.ts +43 -0
- package/src/core/readers/world_status.ts +63 -0
- package/src/core/reducers/manipulation_args.ts +239 -0
- package/src/core/reducers/manipulation_receipt.ts +66 -0
- package/src/core/reducers/r_actor_wake_up.ts +32 -0
- package/src/core/reducers/r_inscribe_trace.ts +109 -0
- package/src/core/reducers/r_manipulate.ts +163 -0
- package/src/core/reducers/r_move.ts +155 -0
- package/src/core/reducers/r_react.ts +143 -0
- package/src/core/reducers/r_release_claim.ts +81 -0
- package/src/core/reducers/r_sense.ts +84 -0
- package/src/core/reducers/r_session_close.ts +130 -0
- package/src/core/reducers/r_session_move.ts +116 -0
- package/src/core/reducers/r_session_open.ts +91 -0
- package/src/core/reducers/session_lookup.ts +64 -0
- package/src/core/reducers/tick.ts +65 -0
- package/src/core/reducers/trace_lookup.ts +29 -0
- package/src/core/reducers/transport.ts +84 -0
- package/src/core/resolve.ts +228 -0
- package/src/core/shape_telemetry.ts +146 -0
- package/src/core/snapshot_rows.ts +109 -0
- package/src/core/tick_cadence.ts +61 -0
- package/src/core/types.ts +501 -0
- package/src/core/watch_provenance.ts +113 -0
- package/src/core/world-contract/classify.ts +38 -0
- package/src/core/world-contract/index.ts +12 -0
- package/src/core/world-contract/normalise.ts +574 -0
- package/src/core/world-contract/runtime.ts +144 -0
- package/src/core/world-contract/served.ts +173 -0
- package/src/core/world-contract/strict-reducers.ts +14 -0
- package/src/core/world-contract/typetext.ts +94 -0
- package/src/core/world_time.ts +22 -0
- package/src/index.ts +262 -0
- package/src/manifest-apply.ts +497 -0
- package/src/provenance.ts +568 -0
- package/src/reader-manifest.ts +338 -0
- package/src/readers.ts +392 -0
- package/src/replay.ts +515 -0
- package/src/watch-buffer.ts +438 -0
- package/src/world-events/builder.ts +1042 -0
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
// Shared result types for actor-control verbs.
|
|
2
|
+
//
|
|
3
|
+
// Extracted from actor_control.ts as part of the D4 mechanical split.
|
|
4
|
+
// These discriminated unions are shared across per-reducer wrapper files;
|
|
5
|
+
// keeping them here avoids re-exporting via multiple files and prevents drift.
|
|
6
|
+
// NOT subject to per-file LOC ceiling (D4, design.md:112).
|
|
7
|
+
|
|
8
|
+
import type { SnapshotDb } from "../connection";
|
|
9
|
+
import type { ProvenanceRow, ReducerAttemptTelemetry } from "../provenance";
|
|
10
|
+
import type {
|
|
11
|
+
RActorWakeUpFn,
|
|
12
|
+
RAdvanceTurnFn,
|
|
13
|
+
RManipulateFn,
|
|
14
|
+
RMoveFn,
|
|
15
|
+
RReactFn,
|
|
16
|
+
RReleaseClaimFn,
|
|
17
|
+
RSenseFn,
|
|
18
|
+
RSessionCloseFn,
|
|
19
|
+
RSessionMoveFn,
|
|
20
|
+
RSessionOpenFn,
|
|
21
|
+
} from "./actor_control_source";
|
|
22
|
+
import type { EntityRef } from "./ids";
|
|
23
|
+
import type { ActorSnapshot } from "./readers/actor_snapshot";
|
|
24
|
+
import type { LocationSnapshot } from "./readers/location_snapshot";
|
|
25
|
+
import type { SuggestedNextAction } from "./readers/suggest_next_action";
|
|
26
|
+
import type { ActorWakeUpResult } from "./reducers/r_actor_wake_up";
|
|
27
|
+
import type { InscribeTraceResult, VisibilityClass } from "./reducers/r_inscribe_trace";
|
|
28
|
+
import type { ActorReleaseClaimResult } from "./reducers/r_release_claim";
|
|
29
|
+
import type { SessionCloseResult } from "./reducers/r_session_close";
|
|
30
|
+
import type { SessionMoveResult } from "./reducers/r_session_move";
|
|
31
|
+
import type { SessionOpenResult } from "./reducers/r_session_open";
|
|
32
|
+
import type { TickIntervalEstimator } from "./tick_cadence";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Outcome status shared by all actor-control verbs.
|
|
36
|
+
*
|
|
37
|
+
* - `success` — reducer accepted and the verb's success predicate observed in subscribed state.
|
|
38
|
+
* - `rejected` — reducer threw or the server emitted a failure `evaluation_provenance` row.
|
|
39
|
+
* - `unobserved_timeout` — observation window expired before success state was observed.
|
|
40
|
+
* - `unobserved_no_provenance` — reducer returned but no success state or provenance row was observed.
|
|
41
|
+
* - `unobservable` — reducer returned but no provenance row was visible to this identity.
|
|
42
|
+
*/
|
|
43
|
+
export type ActorAttemptStatus =
|
|
44
|
+
| "success"
|
|
45
|
+
| "rejected"
|
|
46
|
+
| "unobserved_timeout"
|
|
47
|
+
| "unobserved_no_provenance"
|
|
48
|
+
| "unobservable";
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Move result types
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
export interface ActorMoveCall {
|
|
55
|
+
actor_id: EntityRef;
|
|
56
|
+
from_node: string;
|
|
57
|
+
to_node: string;
|
|
58
|
+
edge_id: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface ActorMoveSuccess {
|
|
62
|
+
status: "success";
|
|
63
|
+
actor_id: EntityRef;
|
|
64
|
+
edge_id: string;
|
|
65
|
+
from_node: string;
|
|
66
|
+
to_node: string;
|
|
67
|
+
actor_snapshot: ActorSnapshot;
|
|
68
|
+
provenance?: ProvenanceRow;
|
|
69
|
+
lagWarning: boolean;
|
|
70
|
+
observedAtTick: bigint;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ActorMoveRejected {
|
|
74
|
+
status: "rejected";
|
|
75
|
+
actor_id: EntityRef;
|
|
76
|
+
edge_id: string;
|
|
77
|
+
from_node?: string;
|
|
78
|
+
to_node?: string;
|
|
79
|
+
actor_snapshot: ActorSnapshot | null;
|
|
80
|
+
reason: string;
|
|
81
|
+
provenance?: ProvenanceRow;
|
|
82
|
+
lagWarning: boolean;
|
|
83
|
+
observedAtTick: bigint;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface ActorMoveUnobservedTimeout {
|
|
87
|
+
status: "unobserved_timeout";
|
|
88
|
+
actor_id: EntityRef;
|
|
89
|
+
edge_id: string;
|
|
90
|
+
from_node: string;
|
|
91
|
+
to_node: string;
|
|
92
|
+
actor_snapshot: ActorSnapshot | null;
|
|
93
|
+
reason: string;
|
|
94
|
+
provenance?: ProvenanceRow;
|
|
95
|
+
lagWarning: boolean;
|
|
96
|
+
observedAtTick: bigint;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface ActorMoveUnobservedNoProvenance {
|
|
100
|
+
status: "unobserved_no_provenance";
|
|
101
|
+
actor_id: EntityRef;
|
|
102
|
+
edge_id: string;
|
|
103
|
+
from_node: string;
|
|
104
|
+
to_node: string;
|
|
105
|
+
actor_snapshot: ActorSnapshot | null;
|
|
106
|
+
reason: string;
|
|
107
|
+
provenance?: ProvenanceRow;
|
|
108
|
+
lagWarning: boolean;
|
|
109
|
+
observedAtTick: bigint;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface ActorMoveUnobservable extends Omit<ActorMoveUnobservedNoProvenance, "status"> {
|
|
113
|
+
status: "unobservable";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface ActorMoveTravelling
|
|
117
|
+
extends Omit<ActorMoveUnobservedNoProvenance, "status" | "reason"> {
|
|
118
|
+
status: "travelling";
|
|
119
|
+
/** Ticks still to go when this result was built. */
|
|
120
|
+
arrives_in_ticks: number;
|
|
121
|
+
/** Absolute world tick the actor is put down at `to_node`. */
|
|
122
|
+
arrives_at_tick: number;
|
|
123
|
+
/** The long-running-move session doing the walking. */
|
|
124
|
+
session_id: string;
|
|
125
|
+
/** Human-readable, e.g. "travelling to 'inn/stairs' — arrives in 4 ticks". */
|
|
126
|
+
reason: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type ActorMoveResult =
|
|
130
|
+
| ActorMoveSuccess
|
|
131
|
+
| ActorMoveRejected
|
|
132
|
+
| ActorMoveTravelling
|
|
133
|
+
| ActorMoveUnobservedTimeout
|
|
134
|
+
| ActorMoveUnobservedNoProvenance
|
|
135
|
+
| ActorMoveUnobservable;
|
|
136
|
+
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
// Manipulate result types
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
|
|
141
|
+
export interface ActorManipulateSuccess<T> {
|
|
142
|
+
status: "success";
|
|
143
|
+
actor_id: EntityRef;
|
|
144
|
+
target_id: string;
|
|
145
|
+
action_id: string;
|
|
146
|
+
snapshot: T;
|
|
147
|
+
/**
|
|
148
|
+
* #1968 B-9: the `evaluation_provenance` row `r_manipulate` recorded for
|
|
149
|
+
* THIS dispatch — previously dropped on the success branch (every other
|
|
150
|
+
* `ActorManipulateResult`/`ActorSenseResult` variant already carries it).
|
|
151
|
+
* `provenance.selected_template_ids[1]` is the fired `outcome_template_id`,
|
|
152
|
+
* the join key `describeOutcomeTemplate` (shared tool runtime `observation.ts`)
|
|
153
|
+
* resolves the authored observation narrative from.
|
|
154
|
+
*/
|
|
155
|
+
provenance?: ProvenanceRow;
|
|
156
|
+
lagWarning: boolean;
|
|
157
|
+
observedAtTick: bigint;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface ActorManipulateRejected<T> {
|
|
161
|
+
status: "rejected";
|
|
162
|
+
actor_id: EntityRef;
|
|
163
|
+
target_id: string;
|
|
164
|
+
action_id: string;
|
|
165
|
+
snapshot: T | null;
|
|
166
|
+
reason: string;
|
|
167
|
+
provenance?: ProvenanceRow;
|
|
168
|
+
lagWarning: boolean;
|
|
169
|
+
observedAtTick: bigint;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface ActorManipulateUnobservedTimeout<T> {
|
|
173
|
+
status: "unobserved_timeout";
|
|
174
|
+
actor_id: EntityRef;
|
|
175
|
+
target_id: string;
|
|
176
|
+
action_id: string;
|
|
177
|
+
snapshot: T | null;
|
|
178
|
+
reason: string;
|
|
179
|
+
provenance?: ProvenanceRow;
|
|
180
|
+
lagWarning: boolean;
|
|
181
|
+
observedAtTick: bigint;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface ActorManipulateUnobservedNoProvenance<T> {
|
|
185
|
+
status: "unobserved_no_provenance";
|
|
186
|
+
actor_id: EntityRef;
|
|
187
|
+
target_id: string;
|
|
188
|
+
action_id: string;
|
|
189
|
+
snapshot: T | null;
|
|
190
|
+
reason: string;
|
|
191
|
+
provenance?: ProvenanceRow;
|
|
192
|
+
lagWarning: boolean;
|
|
193
|
+
observedAtTick: bigint;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface ActorManipulateUnobservable<T>
|
|
197
|
+
extends Omit<ActorManipulateUnobservedNoProvenance<T>, "status"> {
|
|
198
|
+
status: "unobservable";
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type ActorManipulateResult<T> =
|
|
202
|
+
| ActorManipulateSuccess<T>
|
|
203
|
+
| ActorManipulateRejected<T>
|
|
204
|
+
| ActorManipulateUnobservedTimeout<T>
|
|
205
|
+
| ActorManipulateUnobservedNoProvenance<T>
|
|
206
|
+
| ActorManipulateUnobservable<T>;
|
|
207
|
+
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
// Session result types (re-export from per-reducer wrappers)
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
|
|
212
|
+
export type { InscribeTraceResult, VisibilityClass } from "./reducers/r_inscribe_trace";
|
|
213
|
+
export type { ActorReleaseClaimResult } from "./reducers/r_release_claim";
|
|
214
|
+
export type { SessionCloseResult } from "./reducers/r_session_close";
|
|
215
|
+
export type { SessionMoveResult } from "./reducers/r_session_move";
|
|
216
|
+
export type { SessionOpenResult } from "./reducers/r_session_open";
|
|
217
|
+
|
|
218
|
+
/** Result of r_advance_turn: fire-and-await (no state-observed snapshot). */
|
|
219
|
+
export type AdvanceTurnResult =
|
|
220
|
+
| { status: "success"; sessionId: bigint }
|
|
221
|
+
| { status: "rejected"; sessionId: bigint; reason: string };
|
|
222
|
+
export type { ActorWakeUpResult } from "./reducers/r_actor_wake_up";
|
|
223
|
+
|
|
224
|
+
export interface ActorSenseSuccess {
|
|
225
|
+
status: "success";
|
|
226
|
+
actor_id: EntityRef;
|
|
227
|
+
query_kind: string;
|
|
228
|
+
visibility_class: string;
|
|
229
|
+
provenance?: ProvenanceRow;
|
|
230
|
+
lagWarning: boolean;
|
|
231
|
+
observedAtTick: bigint;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface ActorSenseRejected {
|
|
235
|
+
status: "rejected";
|
|
236
|
+
actor_id: EntityRef;
|
|
237
|
+
query_kind: string;
|
|
238
|
+
visibility_class: string;
|
|
239
|
+
reason: string;
|
|
240
|
+
provenance?: ProvenanceRow;
|
|
241
|
+
lagWarning: boolean;
|
|
242
|
+
observedAtTick: bigint;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface ActorSenseUnobservedTimeout {
|
|
246
|
+
status: "unobserved_timeout";
|
|
247
|
+
actor_id: EntityRef;
|
|
248
|
+
query_kind: string;
|
|
249
|
+
visibility_class: string;
|
|
250
|
+
reason: string;
|
|
251
|
+
provenance?: ProvenanceRow;
|
|
252
|
+
lagWarning: boolean;
|
|
253
|
+
observedAtTick: bigint;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface ActorSenseUnobservedNoProvenance {
|
|
257
|
+
status: "unobserved_no_provenance";
|
|
258
|
+
actor_id: EntityRef;
|
|
259
|
+
query_kind: string;
|
|
260
|
+
visibility_class: string;
|
|
261
|
+
reason: string;
|
|
262
|
+
provenance?: ProvenanceRow;
|
|
263
|
+
lagWarning: boolean;
|
|
264
|
+
observedAtTick: bigint;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface ActorSenseUnobservable extends Omit<ActorSenseUnobservedNoProvenance, "status"> {
|
|
268
|
+
status: "unobservable";
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export type ActorSenseResult =
|
|
272
|
+
| ActorSenseSuccess
|
|
273
|
+
| ActorSenseRejected
|
|
274
|
+
| ActorSenseUnobservedTimeout
|
|
275
|
+
| ActorSenseUnobservedNoProvenance
|
|
276
|
+
| ActorSenseUnobservable;
|
|
277
|
+
|
|
278
|
+
// ── r_react (#509) — provenance-observed (reacted-state lives on the
|
|
279
|
+
// unsubscribed pending_resolution_reactor table; see reducers/r_react.ts). ──
|
|
280
|
+
|
|
281
|
+
export interface ActorReactSuccess {
|
|
282
|
+
status: "success";
|
|
283
|
+
actor_id: EntityRef;
|
|
284
|
+
pending_id: bigint;
|
|
285
|
+
response_intent: string;
|
|
286
|
+
/** The frozen-draw index this react replaced, when the caller selected one
|
|
287
|
+
* (post-roll intervention windows, #2058). Absent for a plain decline or a
|
|
288
|
+
* non-stochastic reaction seat. */
|
|
289
|
+
selected_draw_index?: number;
|
|
290
|
+
provenance?: ProvenanceRow;
|
|
291
|
+
lagWarning: boolean;
|
|
292
|
+
observedAtTick: bigint;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export interface ActorReactRejected {
|
|
296
|
+
status: "rejected";
|
|
297
|
+
actor_id: EntityRef;
|
|
298
|
+
pending_id: bigint;
|
|
299
|
+
response_intent: string;
|
|
300
|
+
selected_draw_index?: number;
|
|
301
|
+
reason: string;
|
|
302
|
+
provenance?: ProvenanceRow;
|
|
303
|
+
lagWarning: boolean;
|
|
304
|
+
observedAtTick: bigint;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface ActorReactUnobservedTimeout {
|
|
308
|
+
status: "unobserved_timeout";
|
|
309
|
+
actor_id: EntityRef;
|
|
310
|
+
pending_id: bigint;
|
|
311
|
+
response_intent: string;
|
|
312
|
+
selected_draw_index?: number;
|
|
313
|
+
reason: string;
|
|
314
|
+
provenance?: ProvenanceRow;
|
|
315
|
+
lagWarning: boolean;
|
|
316
|
+
observedAtTick: bigint;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface ActorReactUnobservedNoProvenance {
|
|
320
|
+
status: "unobserved_no_provenance";
|
|
321
|
+
actor_id: EntityRef;
|
|
322
|
+
pending_id: bigint;
|
|
323
|
+
response_intent: string;
|
|
324
|
+
selected_draw_index?: number;
|
|
325
|
+
reason: string;
|
|
326
|
+
provenance?: ProvenanceRow;
|
|
327
|
+
lagWarning: boolean;
|
|
328
|
+
observedAtTick: bigint;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface ActorReactUnobservable extends Omit<ActorReactUnobservedNoProvenance, "status"> {
|
|
332
|
+
status: "unobservable";
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export type ActorReactResult =
|
|
336
|
+
| ActorReactSuccess
|
|
337
|
+
| ActorReactRejected
|
|
338
|
+
| ActorReactUnobservedTimeout
|
|
339
|
+
| ActorReactUnobservedNoProvenance
|
|
340
|
+
| ActorReactUnobservable;
|
|
341
|
+
|
|
342
|
+
// ---------------------------------------------------------------------------
|
|
343
|
+
// Shared verb helpers
|
|
344
|
+
// ---------------------------------------------------------------------------
|
|
345
|
+
|
|
346
|
+
export interface AdjacentMove {
|
|
347
|
+
edge_id: string;
|
|
348
|
+
to_node: string;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export interface ActorClientOptions {
|
|
352
|
+
/** Original control generation captured with the perception used to decide.
|
|
353
|
+
* Never refreshed by dispatch; a stale refusal requires a new perception and decision. */
|
|
354
|
+
driverToken?: import("./driver_control").DriverToken;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Milliseconds to wait for observed destination.
|
|
358
|
+
* Default: 2 × a measured estimator cadence (or 2 × config.tick_interval_secs when the snapshot has it); a cold estimator is treated as unknown and falls back to 2000ms. Overrides estimator when supplied.
|
|
359
|
+
*/
|
|
360
|
+
observationTimeoutMs?: number;
|
|
361
|
+
/** Fallback poll interval for snapshot hosts without cache callbacks. Default: 40 ms. */
|
|
362
|
+
observationPollMs?: number;
|
|
363
|
+
/** Tick-interval estimator for dynamic timeout default computation. */
|
|
364
|
+
tickEstimator?: TickIntervalEstimator;
|
|
365
|
+
/** Optional override for where move actually invokes `r_move`. */
|
|
366
|
+
rMove?: RMoveFn;
|
|
367
|
+
/** Optional override for where manipulate actually invokes `r_manipulate`. */
|
|
368
|
+
rManipulate?: RManipulateFn;
|
|
369
|
+
/** Optional host-provided tracer for reducer observation attempts. */
|
|
370
|
+
reducerAttemptTelemetry?: ReducerAttemptTelemetry;
|
|
371
|
+
/** Optional override for where sessionOpen actually invokes `r_session_open`. */
|
|
372
|
+
rSessionOpen?: RSessionOpenFn;
|
|
373
|
+
/** Optional override for where sessionClose actually invokes `r_session_close`. */
|
|
374
|
+
rSessionClose?: RSessionCloseFn;
|
|
375
|
+
/** Optional override for where sessionMove actually invokes `r_session_move`. */
|
|
376
|
+
rSessionMove?: RSessionMoveFn;
|
|
377
|
+
/** Optional override for where sense actually invokes `r_sense`. */
|
|
378
|
+
rSense?: RSenseFn;
|
|
379
|
+
/**
|
|
380
|
+
* When true, `manipulate` treats its invocation-attributed success receipt as success
|
|
381
|
+
* even if `successPredicate` never fires. For callers (e.g. generic agent
|
|
382
|
+
* tool hosts) that cannot express a world-state predicate and want to rely on
|
|
383
|
+
* the server's own verdict. Default: false (also requires the state predicate). Both modes await the
|
|
384
|
+
* own reducer result and require an attributable terminal receipt. Snapshot-only
|
|
385
|
+
* hosts without reducer delivery context return unobservable. A settled call
|
|
386
|
+
* without a unique terminal receipt returns uncertainty immediately; only a
|
|
387
|
+
* still-pending reducer or state observation retains the deadline.
|
|
388
|
+
*/
|
|
389
|
+
successOnProvenance?: boolean;
|
|
390
|
+
/** Optional override for where inscribeTrace actually invokes `r_inscribe_trace`. */
|
|
391
|
+
rInscribeTrace?: (args: {
|
|
392
|
+
kind: string;
|
|
393
|
+
locationKind: string;
|
|
394
|
+
locationRef: string;
|
|
395
|
+
payloadJson: string;
|
|
396
|
+
expiresAtTick?: bigint;
|
|
397
|
+
inscribedBy: string;
|
|
398
|
+
visibility: VisibilityClass;
|
|
399
|
+
bundleId: string;
|
|
400
|
+
}) => Promise<void>;
|
|
401
|
+
/** Optional override for where react actually invokes `r_react`. */
|
|
402
|
+
rReact?: RReactFn;
|
|
403
|
+
/** Optional override for where releaseClaim actually invokes `r_release_claim`. */
|
|
404
|
+
rReleaseClaim?: RReleaseClaimFn;
|
|
405
|
+
/** Optional override for where wakeUp actually invokes `r_actor_wake_up`. */
|
|
406
|
+
rActorWakeUp?: RActorWakeUpFn;
|
|
407
|
+
/** Optional override for where advanceTurn actually invokes `r_advance_turn`. */
|
|
408
|
+
rAdvanceTurn?: RAdvanceTurnFn;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export interface ActorClient {
|
|
412
|
+
/** Rebind a decision to its original observed generation without reading live state. */
|
|
413
|
+
withDriverToken?(token: import("./driver_control").DriverToken): ActorClient;
|
|
414
|
+
/** Canonical actor id bound at construction time. */
|
|
415
|
+
readonly actorId: string;
|
|
416
|
+
/** Current actor snapshot from live subscription state. */
|
|
417
|
+
actorSnapshot(): ActorSnapshot;
|
|
418
|
+
/** Live location snapshot for the actor's current place node. */
|
|
419
|
+
locationSnapshot(): LocationSnapshot | null;
|
|
420
|
+
/** Adjacent edges from the actor's current live node. */
|
|
421
|
+
adjacentMoves(): AdjacentMove[];
|
|
422
|
+
/** Deterministic suggestion from live snapshot state. */
|
|
423
|
+
suggestNextAction(): SuggestedNextAction | null;
|
|
424
|
+
/**
|
|
425
|
+
* Attempt movement over one adjacent edge id from live state.
|
|
426
|
+
* Reducer callback success alone is insufficient; destination must be
|
|
427
|
+
* observed in subscribed state before success is reported.
|
|
428
|
+
*/
|
|
429
|
+
move(edgeId: string): Promise<ActorMoveResult>;
|
|
430
|
+
/**
|
|
431
|
+
* Attempt a generic manipulation action against a target entity.
|
|
432
|
+
* SDK does NO argument validation — all args pass 1:1 to r_manipulate.
|
|
433
|
+
* The server is authoritative; outcome is observed via successPredicate.
|
|
434
|
+
*/
|
|
435
|
+
manipulate<T>(
|
|
436
|
+
targetId: string,
|
|
437
|
+
actionId: string,
|
|
438
|
+
argsJson: string,
|
|
439
|
+
successPredicate: (db: SnapshotDb) => boolean,
|
|
440
|
+
collectSnapshot: (db: SnapshotDb) => T | null,
|
|
441
|
+
): Promise<ActorManipulateResult<T>>;
|
|
442
|
+
/** Attempt to open a session for this actor. Dispatches through r_session_open wrapper. */
|
|
443
|
+
sessionOpen(sessionDefId: string, participantsCsv?: string): Promise<SessionOpenResult>;
|
|
444
|
+
/** Attempt to close a session. Dispatches through r_session_close wrapper. */
|
|
445
|
+
sessionClose(
|
|
446
|
+
sessionId: bigint,
|
|
447
|
+
outcome: string,
|
|
448
|
+
driverTokens?: readonly import("./driver_control").DriverToken[],
|
|
449
|
+
): Promise<SessionCloseResult>;
|
|
450
|
+
/** Attempt a move within a session. Dispatches through r_session_move wrapper. */
|
|
451
|
+
sessionMove(sessionId: bigint, moveTemplateId: string): Promise<SessionMoveResult>;
|
|
452
|
+
/** Advance the turn in an active session. Dispatches r_advance_turn (fire-and-await). */
|
|
453
|
+
advanceTurn(sessionId: bigint): Promise<AdvanceTurnResult>;
|
|
454
|
+
/** Resolve this actor's active participant session and end its current turn. */
|
|
455
|
+
endTurn(): Promise<AdvanceTurnResult>;
|
|
456
|
+
/** Attempt passive/active sensing. Success is provenance-observed because r_sense writes no state. */
|
|
457
|
+
sense(queryKind: string, visibilityClass: string): Promise<ActorSenseResult>;
|
|
458
|
+
/**
|
|
459
|
+
* Inscribe a trace (leave-a-mark, #510). The acting actor is the trace's
|
|
460
|
+
* `inscribed_by`. State-observed: success when the trace row appears in the
|
|
461
|
+
* subscribed `visible_trace` view. `expiresAtTick` is optional (None = permanent).
|
|
462
|
+
* SDK does NO argument validation — all args pass 1:1 to r_inscribe_trace.
|
|
463
|
+
*/
|
|
464
|
+
inscribeTrace(
|
|
465
|
+
kind: string,
|
|
466
|
+
locationKind: string,
|
|
467
|
+
locationRef: string,
|
|
468
|
+
payloadJson: string,
|
|
469
|
+
visibility: VisibilityClass,
|
|
470
|
+
bundleId: string,
|
|
471
|
+
expiresAtTick?: bigint,
|
|
472
|
+
): Promise<InscribeTraceResult>;
|
|
473
|
+
/**
|
|
474
|
+
* React to a pending_resolution (#509). The acting actor is the reactor.
|
|
475
|
+
* Success is observed one of two ways depending on shape: a multi-actor
|
|
476
|
+
* reaction seat (unsubscribed pending_resolution_reactor table) flipping
|
|
477
|
+
* or disappearing, or — when this reactor holds no seat row at all, the
|
|
478
|
+
* shape a post-roll intervention window takes (#2058: the eligible
|
|
479
|
+
* responder is `target_actor` on `pending_resolution` itself, not a seat)
|
|
480
|
+
* — the matching `visible_pending_resolution` row disappearing. SDK does
|
|
481
|
+
* NO argument validation — all args pass 1:1 to r_react. `selectedDrawIndex`
|
|
482
|
+
* is the intervention-window accept case: which already-drawn face to
|
|
483
|
+
* replace; omit it to decline (keep the original result, spend nothing).
|
|
484
|
+
*/
|
|
485
|
+
react(
|
|
486
|
+
pendingId: bigint,
|
|
487
|
+
responseIntent: string,
|
|
488
|
+
selectedDrawIndex?: number,
|
|
489
|
+
): Promise<ActorReactResult>;
|
|
490
|
+
/**
|
|
491
|
+
* Release a claim/lock this actor holds on a target (multiplayer contention).
|
|
492
|
+
* Provenance-observed (the claim module emits evaluation_provenance).
|
|
493
|
+
*/
|
|
494
|
+
releaseClaim(targetId: string): Promise<ActorReleaseClaimResult>;
|
|
495
|
+
/**
|
|
496
|
+
* Seed wake-up perception for the actor's current node (connect-path, design
|
|
497
|
+
* D-3). Idempotent and fire-and-confirm: reports "submitted" once invoked, as
|
|
498
|
+
* the reducer emits no terminal signal. Read observer_knowledge to confirm.
|
|
499
|
+
*/
|
|
500
|
+
wakeUp(): Promise<ActorWakeUpResult>;
|
|
501
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Isolated filtered provenance subscription for a specific actor.
|
|
2
|
+
//
|
|
3
|
+
// Issues a second filtered subscription on the SAME DbConnection as the session.
|
|
4
|
+
// Uses a dedicated ProvenanceRingBuffer so it is fully isolated from the default
|
|
5
|
+
// session buffer — including when actorId === connectedActorId (past-eviction recovery).
|
|
6
|
+
|
|
7
|
+
import type { DbConnection } from "@spellkave/bindings";
|
|
8
|
+
import type { ProvenanceRow } from "../provenance";
|
|
9
|
+
import { ProvenanceRingBuffer } from "./provenance_buffer";
|
|
10
|
+
|
|
11
|
+
export interface WatchProvenanceHandle {
|
|
12
|
+
/** All rows accumulated since subscription applied, filtered by actorId and sinceTick. */
|
|
13
|
+
rows: ProvenanceRow[];
|
|
14
|
+
/** Unsubscribes the watch subscription and releases resources. */
|
|
15
|
+
close(): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Open a second filtered subscription for `actorId` with rows newer than `sinceTick`.
|
|
20
|
+
* Returns a handle with a snapshot of accumulated rows and a `close()` teardown.
|
|
21
|
+
*
|
|
22
|
+
* Isolated from the default session ring buffer regardless of which actorId is requested.
|
|
23
|
+
* Use for non-default subjects and for connected-actor past-eviction recovery.
|
|
24
|
+
*/
|
|
25
|
+
export function watchProvenanceFor(
|
|
26
|
+
conn: DbConnection,
|
|
27
|
+
actorId: string,
|
|
28
|
+
sinceTick: bigint,
|
|
29
|
+
): WatchProvenanceHandle {
|
|
30
|
+
const isolatedBuffer = new ProvenanceRingBuffer(actorId);
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
// biome-ignore lint/suspicious/noExplicitAny: pre-existing debt from #1368 biome onboarding, tracked in #1455
|
|
34
|
+
const handle = conn.subscriptionBuilder().subscribe((tables: any) =>
|
|
35
|
+
tables.visible_evaluation_provenance.where(
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
// biome-ignore lint/suspicious/noExplicitAny: pre-existing debt from #1368 biome onboarding, tracked in #1455
|
|
38
|
+
(p: any) => p.subjectId.eq(actorId),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Per-row onInsert callback: receives the single new row directly.
|
|
43
|
+
// Storing the reference so removeOnInsert() can deregister it in close().
|
|
44
|
+
const db = conn.db as unknown as Record<string, TableHandle | undefined>;
|
|
45
|
+
const tableHandle = db.visible_evaluation_provenance ?? db.evaluation_provenance;
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
// biome-ignore lint/suspicious/noExplicitAny: pre-existing debt from #1368 biome onboarding, tracked in #1455
|
|
49
|
+
const insertCb = (_ctx: any, raw: unknown) => {
|
|
50
|
+
const r = raw as RawProvenanceRow;
|
|
51
|
+
const tick =
|
|
52
|
+
typeof r.createdAtTick === "bigint" ? r.createdAtTick : BigInt(String(r.createdAtTick ?? 0));
|
|
53
|
+
if (tick <= sinceTick) return;
|
|
54
|
+
isolatedBuffer.insert({
|
|
55
|
+
id: r.provenanceId,
|
|
56
|
+
kind: tagString(r.kind),
|
|
57
|
+
status: tagString(r.status),
|
|
58
|
+
subject_id: r.subjectId,
|
|
59
|
+
failure_kind: r.failureKind,
|
|
60
|
+
failure_detail: r.failureDetail,
|
|
61
|
+
selected_template_ids: Array.isArray(r.selectedTemplateIds)
|
|
62
|
+
? r.selectedTemplateIds.map(String)
|
|
63
|
+
: [],
|
|
64
|
+
created_at_tick: tick,
|
|
65
|
+
bundle_id: r.bundleId,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (tableHandle?.onInsert) {
|
|
70
|
+
tableHandle.onInsert(insertCb);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
get rows(): ProvenanceRow[] {
|
|
75
|
+
return isolatedBuffer.forSubject(actorId);
|
|
76
|
+
},
|
|
77
|
+
close(): void {
|
|
78
|
+
// Deregister the insert callback BEFORE unsubscribing so no further
|
|
79
|
+
// rows are routed to isolatedBuffer after close() returns.
|
|
80
|
+
if (tableHandle?.removeOnInsert) {
|
|
81
|
+
tableHandle.removeOnInsert(insertCb);
|
|
82
|
+
}
|
|
83
|
+
handle.unsubscribe();
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface TableHandle {
|
|
89
|
+
iter(): Iterable<Record<string, unknown>>;
|
|
90
|
+
onInsert?: (cb: (ctx: unknown, row: unknown) => void) => void;
|
|
91
|
+
removeOnInsert?: (cb: (ctx: unknown, row: unknown) => void) => void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface RawProvenanceRow {
|
|
95
|
+
provenanceId: string;
|
|
96
|
+
kind: unknown;
|
|
97
|
+
status: unknown;
|
|
98
|
+
subjectId: string;
|
|
99
|
+
failureKind: string;
|
|
100
|
+
failureDetail: string;
|
|
101
|
+
selectedTemplateIds: unknown;
|
|
102
|
+
createdAtTick: unknown;
|
|
103
|
+
bundleId: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function tagString(v: unknown): string {
|
|
107
|
+
if (typeof v === "string") return v;
|
|
108
|
+
if (v && typeof v === "object") {
|
|
109
|
+
const tag = (v as { tag?: unknown }).tag;
|
|
110
|
+
if (typeof tag === "string") return tag;
|
|
111
|
+
}
|
|
112
|
+
return String(v ?? "");
|
|
113
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface SchemaTable {
|
|
2
|
+
readonly access: string;
|
|
3
|
+
readonly kind: string;
|
|
4
|
+
readonly event: boolean;
|
|
5
|
+
readonly columns: readonly string[];
|
|
6
|
+
readonly primaryKey: readonly string[];
|
|
7
|
+
readonly unique: readonly string[];
|
|
8
|
+
readonly indexes: Readonly<Record<string, string>>;
|
|
9
|
+
readonly autoInc: readonly string[];
|
|
10
|
+
readonly schedule?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SchemaView {
|
|
13
|
+
readonly public: boolean;
|
|
14
|
+
readonly anonymous: boolean;
|
|
15
|
+
readonly params: readonly string[];
|
|
16
|
+
readonly returns: string;
|
|
17
|
+
readonly columns?: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export interface SchemaReducer {
|
|
20
|
+
readonly visibility: string;
|
|
21
|
+
readonly params: readonly string[];
|
|
22
|
+
readonly ok: string;
|
|
23
|
+
readonly err: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SchemaProcedure {
|
|
26
|
+
readonly visibility: string;
|
|
27
|
+
readonly params: readonly string[];
|
|
28
|
+
readonly returns: string;
|
|
29
|
+
}
|
|
30
|
+
export interface SchemaSnapshot {
|
|
31
|
+
readonly tables: Readonly<Record<string, SchemaTable>>;
|
|
32
|
+
readonly views: Readonly<Record<string, SchemaView>>;
|
|
33
|
+
readonly reducers: Readonly<Record<string, SchemaReducer>>;
|
|
34
|
+
readonly procedures: Readonly<Record<string, SchemaProcedure>>;
|
|
35
|
+
readonly lifecycle: Readonly<Record<string, string>>;
|
|
36
|
+
readonly types: Readonly<Record<string, unknown>>;
|
|
37
|
+
readonly explicitNames?: unknown;
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { SchemaSnapshot, SchemaTable } from "./classify.ts";
|
|
2
|
+
export {
|
|
3
|
+
foldCollisions,
|
|
4
|
+
foldNames,
|
|
5
|
+
normaliseItems,
|
|
6
|
+
type UncheckedItem,
|
|
7
|
+
normaliseModuleDef,
|
|
8
|
+
restrictSnapshot,
|
|
9
|
+
} from "./normalise.ts";
|
|
10
|
+
export { classifyRuntimeChange, type RuntimeChange } from "./runtime.ts";
|
|
11
|
+
export { servedSchemaFromSnapshot } from "./served.ts";
|
|
12
|
+
export { typeNames } from "./typetext.ts";
|