@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,475 @@
|
|
|
1
|
+
// code-size-ceiling: 475 (private-applyset-baselines integration: retain DM condition/payload registrations and add secure read triplets; exact merged line count per ADR-0022 D-3. dm-acts-migration: join occurrence-bound audience trace presentation and declare its visible-trace subscription; prior 465 — role-scoped-world-read: admitted projection triplets, index derivation and paired runtime coverage; exact integrated line count. sk-jay0.1.46.3 shares DialoguePromptPresentation with the prompt row; prior 460 — sk-jay0.1.8.85.1 projects bounded author-published defaults; prior 433 — sk-jay0.2.33.15.9 adds the public advisory cue join; prior 405 — sk-jay0.1.23.36.11 unions target tags with the target's entity_definition_tag facts, same rule readSelfIdentity already applies to the self body; prior 382 — ADR-0142 D-6 adds the ManipulationPrompt.presentation join (readDialoguePromptPresentation); prior 371 — the ManipulationPrompt interface and its read leg; prior 340 — ADR-0139's factored reader joins independent action, target, participant, and template presentation facts.)
|
|
2
|
+
// Reader: ADR-0139's additive factored manipulation context.
|
|
3
|
+
//
|
|
4
|
+
// The personal context row is a lifecycle/readiness fact. Its descriptors are
|
|
5
|
+
// deliberately shared authored metadata from the existing public definition
|
|
6
|
+
// tables, rather than a copied perceiver × action cache. No output row claims
|
|
7
|
+
// that an action against any target is eligible: consumers construct one
|
|
8
|
+
// existing r_manipulate attempt and the reducer remains authoritative.
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
ActionDefinitionRow as DbActionDefinitionRow,
|
|
12
|
+
ActionDefinitionTagRow as DbActionDefinitionTagRow,
|
|
13
|
+
AffordanceTemplateRow as DbAffordanceTemplateRow,
|
|
14
|
+
EntityDefinitionTagRow as DbEntityDefinitionTagRow,
|
|
15
|
+
EntityTagRow as DbEntityTagRow,
|
|
16
|
+
ManipulationAvailableActionRow as DbManipulationAvailableActionRow,
|
|
17
|
+
ManipulationContextRow as DbManipulationContextRow,
|
|
18
|
+
ManipulationObservedTargetRow as DbManipulationObservedTargetRow,
|
|
19
|
+
ManipulationParticipantBindingRow as DbManipulationParticipantBindingRow,
|
|
20
|
+
ManipulationParticipantContextRow as DbManipulationParticipantContextRow,
|
|
21
|
+
ManipulationPromptRow as DbManipulationPromptRow,
|
|
22
|
+
NicheDefinitionRow as DbNicheDefinitionRow,
|
|
23
|
+
NicheProviderDefinitionRow as DbNicheProviderDefinitionRow,
|
|
24
|
+
OutcomeTemplateRow as DbOutcomeTemplateRow,
|
|
25
|
+
} from "../../binding_rows";
|
|
26
|
+
import {
|
|
27
|
+
type RequiredTables,
|
|
28
|
+
registerReaderManifest,
|
|
29
|
+
type SnapshotDb,
|
|
30
|
+
} from "../../reader-manifest";
|
|
31
|
+
import type { EntityRef } from "../ids";
|
|
32
|
+
import { targetRefToString } from "../reducers/transport";
|
|
33
|
+
import { asNumber, asString, buildEntitySummaryMap, resolveEntityId, rows } from "./_helpers";
|
|
34
|
+
import { actionDescriptionFields } from "./action_description";
|
|
35
|
+
import { type AffordanceCue, readAffordanceCues } from "./affordance_cue";
|
|
36
|
+
import { type AffordanceDefaults, readAffordanceDefaults } from "./affordance_defaults";
|
|
37
|
+
import { readAffordanceGroupMembership } from "./affordance_group_membership";
|
|
38
|
+
import { type AffordanceInputSchema, readAffordanceInputSchemas } from "./affordance_input";
|
|
39
|
+
import { readAffordanceDefinitionRefs } from "./affordance_reference";
|
|
40
|
+
import { readAudienceTracePresentation } from "./audience_trace_presentation";
|
|
41
|
+
import {
|
|
42
|
+
type DialoguePromptPresentation,
|
|
43
|
+
readDialoguePromptPresentation,
|
|
44
|
+
} from "./dialogue_prompt_presentation";
|
|
45
|
+
import { responseSlotFields } from "./trace_response";
|
|
46
|
+
|
|
47
|
+
export const requiredTables: RequiredTables<
|
|
48
|
+
[
|
|
49
|
+
"visible_manipulation_context",
|
|
50
|
+
"visible_manipulation_available_action",
|
|
51
|
+
"visible_manipulation_observed_target",
|
|
52
|
+
"visible_manipulation_participant_context",
|
|
53
|
+
"visible_manipulation_participant_binding",
|
|
54
|
+
"visible_manipulation_prompt",
|
|
55
|
+
"visible_trace",
|
|
56
|
+
"action_definition",
|
|
57
|
+
"action_definition_tag",
|
|
58
|
+
"affordance_template",
|
|
59
|
+
"outcome_template",
|
|
60
|
+
"niche_definition",
|
|
61
|
+
"niche_provider_definition",
|
|
62
|
+
"visible_manifest_authored_entity",
|
|
63
|
+
"visible_manifest_authored_entity_coverage",
|
|
64
|
+
"entity",
|
|
65
|
+
"visible_entity_tag",
|
|
66
|
+
"visible_entity_tag_coverage",
|
|
67
|
+
"entity_definition_tag",
|
|
68
|
+
]
|
|
69
|
+
> = [
|
|
70
|
+
"visible_manipulation_context",
|
|
71
|
+
"visible_manipulation_available_action",
|
|
72
|
+
"visible_manipulation_observed_target",
|
|
73
|
+
"visible_manipulation_participant_context",
|
|
74
|
+
"visible_manipulation_participant_binding",
|
|
75
|
+
"visible_manipulation_prompt",
|
|
76
|
+
"visible_trace",
|
|
77
|
+
"action_definition",
|
|
78
|
+
"action_definition_tag",
|
|
79
|
+
"affordance_template",
|
|
80
|
+
"outcome_template",
|
|
81
|
+
"niche_definition",
|
|
82
|
+
"niche_provider_definition",
|
|
83
|
+
"visible_manifest_authored_entity",
|
|
84
|
+
"visible_manifest_authored_entity_coverage",
|
|
85
|
+
"entity",
|
|
86
|
+
"visible_entity_tag",
|
|
87
|
+
"visible_entity_tag_coverage",
|
|
88
|
+
"entity_definition_tag",
|
|
89
|
+
];
|
|
90
|
+
registerReaderManifest({ requiredTables });
|
|
91
|
+
|
|
92
|
+
export interface ManipulationActionDescriptor {
|
|
93
|
+
action_id: string;
|
|
94
|
+
display_name: string;
|
|
95
|
+
/** Public authored response syntax; never target eligibility. */
|
|
96
|
+
response_slot?: number;
|
|
97
|
+
/** When present, this action is dispatched through direct communication,
|
|
98
|
+
* not r_manipulate. The value comes from public authored outcome metadata,
|
|
99
|
+
* not an eager action×target offer. */
|
|
100
|
+
communication_speech_act_id?: string;
|
|
101
|
+
/** Shared author-owned classification facts, not a per-target offer. */
|
|
102
|
+
tags: string[];
|
|
103
|
+
/** Authored action-to-niche links with the open provider's public flags.
|
|
104
|
+
* This is not an action-target result; consumers use it only to rank a
|
|
105
|
+
* direct attempt from separately disclosed target and place facts. */
|
|
106
|
+
niche_requirements: ManipulationNicheRequirement[];
|
|
107
|
+
/** Public authored source templates behind this syntax fact. */
|
|
108
|
+
template_ids: string[];
|
|
109
|
+
/** World-public authored template prose, falling back to the action description. */
|
|
110
|
+
description?: string;
|
|
111
|
+
/** Public `ui.affordance_group` attachments on those templates. */
|
|
112
|
+
groups: string[];
|
|
113
|
+
/** Public `ui.affordance_input` on the first authored source template. */
|
|
114
|
+
input?: AffordanceInputSchema;
|
|
115
|
+
/** Exact `ui.affordance_reference` definition, when a source template authors one. */
|
|
116
|
+
definition_ref?: string;
|
|
117
|
+
/** Public `ui.affordance_cue` on the first authored source template. It is
|
|
118
|
+
* advisory presentation only: never eligibility or response context. */
|
|
119
|
+
cue?: AffordanceCue;
|
|
120
|
+
/** Resolved author-published draft values. They remain advisory: the client
|
|
121
|
+
* dispatches concrete arguments and the reducer revalidates them normally. */
|
|
122
|
+
defaults?: ManipulationActionDefaults;
|
|
123
|
+
self_only: boolean;
|
|
124
|
+
self_eligible: boolean;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface ManipulationActionDefaults {
|
|
128
|
+
target?: { target_ref: string; kind: "actor" | "reference" };
|
|
129
|
+
input_values?: Record<string, string | number>;
|
|
130
|
+
provenance: AffordanceDefaults["provenance"];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface ManipulationNicheRequirement {
|
|
134
|
+
niche_id: string;
|
|
135
|
+
requires_spatial_attachment: boolean;
|
|
136
|
+
admits_targets_without_membership: boolean;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** One disclosed, action-independent target reference. Its presence does not
|
|
140
|
+
* claim that any action is currently legal against it. */
|
|
141
|
+
export interface ManipulationObservedTarget {
|
|
142
|
+
target_fact_id: string;
|
|
143
|
+
target_ref: string;
|
|
144
|
+
/** Public tags only when this disclosed target is an entity: instance
|
|
145
|
+
* `entity_tag` UNION the target's `entity_definition_tag` (species/CR/
|
|
146
|
+
* alignment/…), the same union `readSelfIdentity` already applies to the
|
|
147
|
+
* self body — `entity_definition_tag` is public, so this discloses
|
|
148
|
+
* nothing the DB does not already serve. */
|
|
149
|
+
tags: string[];
|
|
150
|
+
/** Independently meaningful target niche memberships; not action matches. */
|
|
151
|
+
niche_ids: string[];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** A complete, disclosed participant expectation for one action. The token is
|
|
155
|
+
* advisory discovery data; the server freshly resolves and validates it. */
|
|
156
|
+
export interface ManipulationParticipantContext {
|
|
157
|
+
context_id: string;
|
|
158
|
+
action_id: string;
|
|
159
|
+
binding_count: number;
|
|
160
|
+
bindings: Array<{ role_id: string; entity_id: string }>;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** One disclosed dialogue-prompt fact (ADR-0142 D-6): an OPEN occurrence this
|
|
164
|
+
* caller may answer — directed to them by name, or broadcast by a source they
|
|
165
|
+
* currently observe. Not an eligibility claim: `r_manipulate`'s prompt gate
|
|
166
|
+
* (ADR-0142 D-3) re-derives and re-checks the occurrence fresh at dispatch
|
|
167
|
+
* time. `consumed` is scoped to this caller only. */
|
|
168
|
+
export interface ManipulationPrompt {
|
|
169
|
+
occurrence_id: string;
|
|
170
|
+
prompt_def_id: string;
|
|
171
|
+
contract_version: number;
|
|
172
|
+
/** The prompt's speaker, wire-shaped `"entity:<id>"` — the same form
|
|
173
|
+
* `IntentSemanticContext.source_ref` and the server's
|
|
174
|
+
* `ManipulationSemanticContextArg.source_ref` carry. */
|
|
175
|
+
source_ref: string;
|
|
176
|
+
response_action_ids: string[];
|
|
177
|
+
opened_at_tick: number;
|
|
178
|
+
consumed: boolean;
|
|
179
|
+
/** Authored `dialogue.prompt` presentation for this `prompt_def_id`
|
|
180
|
+
* (`metadata_attachment`, public audience) — never eligibility data, see
|
|
181
|
+
* `readDialoguePromptPresentation`. Absent when the world authors none. */
|
|
182
|
+
presentation?: DialoguePromptPresentation;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export type ManipulationContext =
|
|
186
|
+
| { status: "unavailable" }
|
|
187
|
+
| {
|
|
188
|
+
status: "ready";
|
|
189
|
+
schema_version: number;
|
|
190
|
+
revision: number;
|
|
191
|
+
actions: ManipulationActionDescriptor[];
|
|
192
|
+
targets: ManipulationObservedTarget[];
|
|
193
|
+
participants: ManipulationParticipantContext[];
|
|
194
|
+
/** ADR-0142 D-6. Additive migration field, like `manipulationContext?:`
|
|
195
|
+
* on `PlayerOrientationView`: always populated by this reader, but
|
|
196
|
+
* optional on the type so a fixture built before this field existed
|
|
197
|
+
* (elsewhere in the monorepo) stays valid — SDK CLAUDE.md §7 favors
|
|
198
|
+
* "old shape -> new shape in one PR" for OWNED shapes; a required
|
|
199
|
+
* field here would instead force every unrelated consumer package to
|
|
200
|
+
* update in lockstep with this one. */
|
|
201
|
+
prompts?: ManipulationPrompt[];
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Reads one caller-scoped context generation. Missing is unavailable, never an
|
|
206
|
+
* empty palette; a ready context with no action descriptors is distinct and
|
|
207
|
+
* valid. Returned actions are open authored ids and syntax/presentation facts,
|
|
208
|
+
* not an action-target offer list.
|
|
209
|
+
*/
|
|
210
|
+
export function readManipulationContext(
|
|
211
|
+
db: SnapshotDb,
|
|
212
|
+
perceiverEntityId: EntityRef,
|
|
213
|
+
): ManipulationContext {
|
|
214
|
+
const perceiverId = resolveEntityId(db, perceiverEntityId);
|
|
215
|
+
if (perceiverId === undefined) return { status: "unavailable" };
|
|
216
|
+
const context = rows<DbManipulationContextRow>(db, "visible_manipulation_context").find(
|
|
217
|
+
(row) => row.perceiverEntityId === perceiverId,
|
|
218
|
+
);
|
|
219
|
+
if (context === undefined || !context.ready) return { status: "unavailable" };
|
|
220
|
+
const availableActionFacts = new Map<string, { niches: Set<string>; templateIds: Set<string> }>();
|
|
221
|
+
for (const row of rows<DbManipulationAvailableActionRow>(
|
|
222
|
+
db,
|
|
223
|
+
"visible_manipulation_available_action",
|
|
224
|
+
).filter((row) => row.perceiverEntityId === perceiverId)) {
|
|
225
|
+
const actionId = asString(row.actionId);
|
|
226
|
+
availableActionFacts.set(actionId, {
|
|
227
|
+
niches: new Set(row.nicheIds.map(asString)),
|
|
228
|
+
templateIds: new Set((row.templateIds ?? []).map(asString)),
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const actionDescriptors = new Map<string, { communication_speech_act_id?: string }>();
|
|
233
|
+
for (const row of rows<DbOutcomeTemplateRow>(db, "outcome_template")) {
|
|
234
|
+
const actionId = asString(row.manipulationActionId).trim();
|
|
235
|
+
if (!actionId) continue;
|
|
236
|
+
const speechActId = asString(row.communicationSpeechActId).trim();
|
|
237
|
+
// An action can carry both legacy fields. Communication is the more
|
|
238
|
+
// specific transport contract and must survive the factored projection.
|
|
239
|
+
actionDescriptors.set(
|
|
240
|
+
actionId,
|
|
241
|
+
speechActId ? { communication_speech_act_id: speechActId } : {},
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
const tagsByAction = new Map<string, string[]>();
|
|
245
|
+
const templatesById = new Map(
|
|
246
|
+
rows<DbAffordanceTemplateRow>(db, "affordance_template").map((row) => [
|
|
247
|
+
asString(row.templateId),
|
|
248
|
+
row,
|
|
249
|
+
]),
|
|
250
|
+
);
|
|
251
|
+
const groupsByTemplate = readAffordanceGroupMembership(db);
|
|
252
|
+
const inputByTemplate = readAffordanceInputSchemas(db);
|
|
253
|
+
const definitionByTemplate = readAffordanceDefinitionRefs(db);
|
|
254
|
+
const cueByTemplate = readAffordanceCues(db);
|
|
255
|
+
const defaultsByTemplate = readAffordanceDefaults(db, inputByTemplate);
|
|
256
|
+
const visibleTargetRefs = new Set(
|
|
257
|
+
rows<DbManipulationObservedTargetRow>(db, "visible_manipulation_observed_target")
|
|
258
|
+
.filter((row) => row.perceiverEntityId === perceiverId)
|
|
259
|
+
.map((row) => targetRefToString(row.targetRef)),
|
|
260
|
+
);
|
|
261
|
+
const resolveDefaults = (
|
|
262
|
+
defaults: AffordanceDefaults,
|
|
263
|
+
): ManipulationActionDefaults | undefined => {
|
|
264
|
+
const target = defaults.target;
|
|
265
|
+
const resolvedTarget =
|
|
266
|
+
target?.kind === "actor"
|
|
267
|
+
? { target_ref: `entity:${perceiverId}`, kind: "actor" as const }
|
|
268
|
+
: target?.kind === "reference" && visibleTargetRefs.has(target.target_ref)
|
|
269
|
+
? { target_ref: target.target_ref, kind: "reference" as const }
|
|
270
|
+
: undefined;
|
|
271
|
+
// An undisclosed exact reference is omitted, not reconstructed. A safe
|
|
272
|
+
// field default on the same attachment may still be useful on its own.
|
|
273
|
+
if (
|
|
274
|
+
target?.kind === "reference" &&
|
|
275
|
+
resolvedTarget === undefined &&
|
|
276
|
+
defaults.input_values === undefined
|
|
277
|
+
)
|
|
278
|
+
return undefined;
|
|
279
|
+
return {
|
|
280
|
+
...(resolvedTarget === undefined ? {} : { target: resolvedTarget }),
|
|
281
|
+
...(defaults.input_values === undefined ? {} : { input_values: defaults.input_values }),
|
|
282
|
+
provenance: defaults.provenance,
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
for (const row of rows<DbActionDefinitionTagRow>(db, "action_definition_tag")) {
|
|
286
|
+
const actionId = asString(row.actionId);
|
|
287
|
+
const tags = tagsByAction.get(actionId) ?? [];
|
|
288
|
+
tags.push(asString(row.tag));
|
|
289
|
+
tagsByAction.set(actionId, tags);
|
|
290
|
+
}
|
|
291
|
+
const tagsByEntity = new Map<string, string[]>();
|
|
292
|
+
for (const row of rows<DbEntityTagRow>(db, "visible_entity_tag")) {
|
|
293
|
+
const entityId = String(row.entityId);
|
|
294
|
+
const tags = tagsByEntity.get(entityId) ?? [];
|
|
295
|
+
tags.push(asString(row.tag));
|
|
296
|
+
tagsByEntity.set(entityId, tags);
|
|
297
|
+
}
|
|
298
|
+
// Definition tags (species/CR/size/alignment/…) union onto each target's
|
|
299
|
+
// instance tags, resolved via its `entity_def_id` — same rule
|
|
300
|
+
// `readSelfIdentity` already applies to the self body.
|
|
301
|
+
const tagsByDefId = new Map<string, string[]>();
|
|
302
|
+
for (const row of rows<DbEntityDefinitionTagRow>(db, "entity_definition_tag")) {
|
|
303
|
+
const entityDefId = asString(row.entityDefId);
|
|
304
|
+
const tags = tagsByDefId.get(entityDefId) ?? [];
|
|
305
|
+
tags.push(asString(row.tag));
|
|
306
|
+
tagsByDefId.set(entityDefId, tags);
|
|
307
|
+
}
|
|
308
|
+
const entitySummaries = buildEntitySummaryMap(db);
|
|
309
|
+
const providerIdByNiche = new Map<string, string>();
|
|
310
|
+
for (const row of rows<DbNicheDefinitionRow>(db, "niche_definition")) {
|
|
311
|
+
providerIdByNiche.set(asString(row.nicheId), asString(row.provider));
|
|
312
|
+
}
|
|
313
|
+
const providerFlagsById = new Map<
|
|
314
|
+
string,
|
|
315
|
+
Pick<
|
|
316
|
+
ManipulationNicheRequirement,
|
|
317
|
+
"requires_spatial_attachment" | "admits_targets_without_membership"
|
|
318
|
+
>
|
|
319
|
+
>();
|
|
320
|
+
for (const row of rows<DbNicheProviderDefinitionRow>(db, "niche_provider_definition")) {
|
|
321
|
+
providerFlagsById.set(asString(row.providerId), {
|
|
322
|
+
requires_spatial_attachment: Boolean(row.requiresSpatialAttachment),
|
|
323
|
+
admits_targets_without_membership: Boolean(row.admitsTargetsWithoutMembership),
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
const nicheRequirement = (nicheId: string): ManipulationNicheRequirement => {
|
|
327
|
+
const flags = providerFlagsById.get(providerIdByNiche.get(nicheId) ?? "");
|
|
328
|
+
return {
|
|
329
|
+
niche_id: nicheId,
|
|
330
|
+
// Same fail-closed default as server NicheProviderFlags::default().
|
|
331
|
+
requires_spatial_attachment: flags?.requires_spatial_attachment ?? true,
|
|
332
|
+
admits_targets_without_membership: flags?.admits_targets_without_membership ?? false,
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
const actions = rows<DbActionDefinitionRow>(db, "action_definition")
|
|
336
|
+
// The actor-scoped fact is produced from r_manipulate's effective
|
|
337
|
+
// capability fold. It limits syntax discovery without claiming that the
|
|
338
|
+
// action is eligible against any target.
|
|
339
|
+
.filter(
|
|
340
|
+
(row) =>
|
|
341
|
+
actionDescriptors.has(asString(row.actionId)) &&
|
|
342
|
+
availableActionFacts.has(asString(row.actionId)),
|
|
343
|
+
)
|
|
344
|
+
.map((row) => {
|
|
345
|
+
const actionId = asString(row.actionId);
|
|
346
|
+
const actionFacts = availableActionFacts.get(actionId);
|
|
347
|
+
const templateIds = [...(actionFacts?.templateIds ?? [])].sort((left, right) =>
|
|
348
|
+
left.localeCompare(right),
|
|
349
|
+
);
|
|
350
|
+
const groups = [
|
|
351
|
+
...new Set(
|
|
352
|
+
templateIds.flatMap((templateId) => [...(groupsByTemplate.get(templateId) ?? [])]),
|
|
353
|
+
),
|
|
354
|
+
].sort((left, right) => left.localeCompare(right));
|
|
355
|
+
const input = templateIds
|
|
356
|
+
.map((templateId) => inputByTemplate.get(templateId))
|
|
357
|
+
.find((schema) => schema !== undefined);
|
|
358
|
+
const definition_ref = templateIds
|
|
359
|
+
.map((templateId) => definitionByTemplate.get(templateId))
|
|
360
|
+
.find((reference) => reference !== undefined);
|
|
361
|
+
const cue = templateIds
|
|
362
|
+
.map((templateId) => cueByTemplate.get(templateId))
|
|
363
|
+
.find((value) => value !== undefined);
|
|
364
|
+
const authoredDefaults = templateIds
|
|
365
|
+
.map((templateId) => defaultsByTemplate.get(templateId))
|
|
366
|
+
.find((value) => value !== undefined);
|
|
367
|
+
const defaults =
|
|
368
|
+
authoredDefaults === undefined ? undefined : resolveDefaults(authoredDefaults);
|
|
369
|
+
return {
|
|
370
|
+
action_id: actionId,
|
|
371
|
+
...responseSlotFields(tagsByAction.get(actionId) ?? []),
|
|
372
|
+
display_name: asString(row.displayName),
|
|
373
|
+
...actionDescriptors.get(actionId),
|
|
374
|
+
tags: [...new Set(tagsByAction.get(actionId) ?? [])].sort((left, right) =>
|
|
375
|
+
left.localeCompare(right),
|
|
376
|
+
),
|
|
377
|
+
niche_requirements: [...(actionFacts?.niches ?? [])]
|
|
378
|
+
.sort((left, right) => left.localeCompare(right))
|
|
379
|
+
.map(nicheRequirement),
|
|
380
|
+
template_ids: templateIds,
|
|
381
|
+
...actionDescriptionFields(row.description, templateIds, templatesById),
|
|
382
|
+
groups,
|
|
383
|
+
...(input === undefined ? {} : { input }),
|
|
384
|
+
...(definition_ref === undefined ? {} : { definition_ref }),
|
|
385
|
+
...(cue === undefined ? {} : { cue }),
|
|
386
|
+
...(defaults === undefined ? {} : { defaults }),
|
|
387
|
+
self_only: Boolean(row.selfOnly),
|
|
388
|
+
self_eligible: Boolean(row.selfEligible),
|
|
389
|
+
};
|
|
390
|
+
})
|
|
391
|
+
.sort((left, right) => left.action_id.localeCompare(right.action_id));
|
|
392
|
+
const targets = rows<DbManipulationObservedTargetRow>(db, "visible_manipulation_observed_target")
|
|
393
|
+
.filter((row) => row.perceiverEntityId === perceiverId)
|
|
394
|
+
.map((row) => {
|
|
395
|
+
const targetRef = targetRefToString(row.targetRef);
|
|
396
|
+
const entityId = targetRef.startsWith("entity:") ? targetRef.slice("entity:".length) : "";
|
|
397
|
+
const entityDefId = entitySummaries.get(entityId)?.entity_def_id;
|
|
398
|
+
const tags = new Set(tagsByEntity.get(entityId) ?? []);
|
|
399
|
+
if (entityDefId !== undefined) {
|
|
400
|
+
for (const tag of tagsByDefId.get(entityDefId) ?? []) tags.add(tag);
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
target_fact_id: asString(row.targetFactId),
|
|
404
|
+
target_ref: targetRef,
|
|
405
|
+
tags: [...tags].sort((left, right) => left.localeCompare(right)),
|
|
406
|
+
niche_ids: [...new Set(row.nicheIds.map(asString))].sort((left, right) =>
|
|
407
|
+
left.localeCompare(right),
|
|
408
|
+
),
|
|
409
|
+
};
|
|
410
|
+
})
|
|
411
|
+
.sort((left, right) => left.target_fact_id.localeCompare(right.target_fact_id));
|
|
412
|
+
const bindingsByContext = new Map<number, Array<{ role_id: string; entity_id: string }>>();
|
|
413
|
+
for (const row of rows<DbManipulationParticipantBindingRow>(
|
|
414
|
+
db,
|
|
415
|
+
"visible_manipulation_participant_binding",
|
|
416
|
+
)) {
|
|
417
|
+
const contextId = asNumber(row.contextId);
|
|
418
|
+
const bindings = bindingsByContext.get(contextId) ?? [];
|
|
419
|
+
bindings.push({ role_id: asString(row.roleId), entity_id: String(row.entityId) });
|
|
420
|
+
bindingsByContext.set(contextId, bindings);
|
|
421
|
+
}
|
|
422
|
+
const participants = rows<DbManipulationParticipantContextRow>(
|
|
423
|
+
db,
|
|
424
|
+
"visible_manipulation_participant_context",
|
|
425
|
+
)
|
|
426
|
+
.filter((row) => row.perceiverEntityId === perceiverId)
|
|
427
|
+
.map((row) => {
|
|
428
|
+
const contextId = asNumber(row.contextId);
|
|
429
|
+
return {
|
|
430
|
+
context_id: `mpc:${contextId}`,
|
|
431
|
+
action_id: asString(row.actionId),
|
|
432
|
+
binding_count: asNumber(row.bindingCount),
|
|
433
|
+
bindings: (bindingsByContext.get(contextId) ?? []).sort(
|
|
434
|
+
(left, right) =>
|
|
435
|
+
left.role_id.localeCompare(right.role_id) ||
|
|
436
|
+
left.entity_id.localeCompare(right.entity_id),
|
|
437
|
+
),
|
|
438
|
+
};
|
|
439
|
+
})
|
|
440
|
+
.sort((left, right) => left.context_id.localeCompare(right.context_id));
|
|
441
|
+
|
|
442
|
+
const presentationByPromptDefId = readDialoguePromptPresentation(db);
|
|
443
|
+
const prompts = rows<DbManipulationPromptRow>(db, "visible_manipulation_prompt")
|
|
444
|
+
.filter((row) => row.perceiverEntityId === perceiverId)
|
|
445
|
+
.map((row) => {
|
|
446
|
+
const promptDefId = asString(row.promptDefId);
|
|
447
|
+
const presentation = readAudienceTracePresentation(
|
|
448
|
+
db,
|
|
449
|
+
String(row.audienceTraceId),
|
|
450
|
+
row.responseActionIds.map(asString),
|
|
451
|
+
presentationByPromptDefId.get(promptDefId),
|
|
452
|
+
);
|
|
453
|
+
return {
|
|
454
|
+
occurrence_id: String(row.occurrenceId),
|
|
455
|
+
prompt_def_id: promptDefId,
|
|
456
|
+
contract_version: asNumber(row.contractVersion),
|
|
457
|
+
source_ref: asString(row.sourceRef),
|
|
458
|
+
response_action_ids: row.responseActionIds.map(asString),
|
|
459
|
+
opened_at_tick: asNumber(row.openedAtTick),
|
|
460
|
+
consumed: Boolean(row.consumed),
|
|
461
|
+
...(presentation === undefined ? {} : { presentation }),
|
|
462
|
+
};
|
|
463
|
+
})
|
|
464
|
+
.sort((left, right) => left.occurrence_id.localeCompare(right.occurrence_id));
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
status: "ready",
|
|
468
|
+
schema_version: asNumber(context.schemaVersion),
|
|
469
|
+
revision: asNumber(context.revision),
|
|
470
|
+
actions,
|
|
471
|
+
targets,
|
|
472
|
+
participants,
|
|
473
|
+
prompts,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
import type { MapLayerRow } from "../../binding_rows";
|
|
3
|
+
import {
|
|
4
|
+
type RequiredTables,
|
|
5
|
+
registerReaderManifest,
|
|
6
|
+
type SnapshotDb,
|
|
7
|
+
} from "../../reader-manifest";
|
|
8
|
+
import { asString, rows } from "./_helpers";
|
|
9
|
+
|
|
10
|
+
export const requiredTables: RequiredTables<["visible_map_layer"]> = ["visible_map_layer"];
|
|
11
|
+
registerReaderManifest({ requiredTables });
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Read the caller's admitted map_layer catalog — every visible backdrop
|
|
15
|
+
* pointer, in the manifest's own snake_case row shape. Filtering is
|
|
16
|
+
* module-side — see the header note.
|
|
17
|
+
*/
|
|
18
|
+
export function readMapLayers(db: SnapshotDb): Record<string, unknown>[] {
|
|
19
|
+
return projectMapLayers(db, "visible_map_layer");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Shared projection over a named accessor — kept so fixtures can point at
|
|
24
|
+
* an explicit table name while producing the same row shape.
|
|
25
|
+
*/
|
|
26
|
+
export function projectMapLayers(db: SnapshotDb, table: string): Record<string, unknown>[] {
|
|
27
|
+
return rows<MapLayerRow>(db, table).map((row) => ({
|
|
28
|
+
map_layer_id: asString(row.mapLayerId),
|
|
29
|
+
bundle_id: asString(row.bundleId),
|
|
30
|
+
place_graph_id: asString(row.placeGraphId),
|
|
31
|
+
display_name: asString(row.displayName),
|
|
32
|
+
asset_module: asString(row.assetModule),
|
|
33
|
+
asset_path: asString(row.assetPath),
|
|
34
|
+
source_kind: asString(row.sourceKind),
|
|
35
|
+
state: asString(row.state),
|
|
36
|
+
posture: asString(row.posture),
|
|
37
|
+
image_width_px: row.imageWidthPx,
|
|
38
|
+
image_height_px: row.imageHeightPx,
|
|
39
|
+
grid_size_px: row.gridSizePx,
|
|
40
|
+
grid_distance_m: row.gridDistanceM,
|
|
41
|
+
local_width_cells: row.localWidthCells,
|
|
42
|
+
local_height_cells: row.localHeightCells,
|
|
43
|
+
image_origin_x: row.imageOriginX,
|
|
44
|
+
image_origin_y: row.imageOriginY,
|
|
45
|
+
rotation_deg: row.rotationDeg,
|
|
46
|
+
min_zoom: row.minZoom,
|
|
47
|
+
max_zoom: row.maxZoom,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// ADR-0130 D-6: "SDK readers read `public_metadata_attachment` together with
|
|
2
|
+
// `visible_metadata_attachment` through one shared helper." This is that
|
|
3
|
+
// helper. `metadata_attachment` is now a private table (D-1); every reader
|
|
4
|
+
// that used to declare it now declares these two play views instead and
|
|
5
|
+
// reads through `readMetadataAttachmentRows`. Reference consumers
|
|
6
|
+
// (character creation, advancement, authoring tools) declare
|
|
7
|
+
// `public_reference_metadata` and read through `readPublicReferenceMetadataRows`.
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
PublicMetadataAttachmentRow,
|
|
11
|
+
PublicReferenceMetadataRow,
|
|
12
|
+
VisibleMetadataAttachmentRow,
|
|
13
|
+
} from "../../binding_rows";
|
|
14
|
+
import type { SnapshotDb } from "../../reader-manifest";
|
|
15
|
+
import { rows } from "./_helpers";
|
|
16
|
+
|
|
17
|
+
/** The three metadata views share this column shape (D-5). */
|
|
18
|
+
export type MetadataAttachmentRow = PublicMetadataAttachmentRow;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Union of `public_metadata_attachment` and `visible_metadata_attachment`,
|
|
22
|
+
* deduped by `row_id`. The two views are disjoint by construction (a row's
|
|
23
|
+
* `(audience, on_demand, target_kind)` selects exactly one), so the dedupe is
|
|
24
|
+
* defensive rather than load-bearing — it keeps this helper correct even if
|
|
25
|
+
* a future view definition narrows and a row transiently satisfies both.
|
|
26
|
+
*/
|
|
27
|
+
export function readMetadataAttachmentRows(
|
|
28
|
+
db: SnapshotDb,
|
|
29
|
+
): (PublicMetadataAttachmentRow | VisibleMetadataAttachmentRow)[] {
|
|
30
|
+
const seen = new Set<string>();
|
|
31
|
+
const out: (PublicMetadataAttachmentRow | VisibleMetadataAttachmentRow)[] = [];
|
|
32
|
+
for (const row of [
|
|
33
|
+
...rows<PublicMetadataAttachmentRow>(db, "public_metadata_attachment"),
|
|
34
|
+
...rows<VisibleMetadataAttachmentRow>(db, "visible_metadata_attachment"),
|
|
35
|
+
]) {
|
|
36
|
+
// Only a row that actually carries a key takes part in the dedupe. A
|
|
37
|
+
// server row always has one (ADR-0146 storage key); a unit fixture may
|
|
38
|
+
// leave it out, and treating several key-less rows as one would
|
|
39
|
+
// silently drop annotations.
|
|
40
|
+
if (row.key === undefined || row.key === null || row.key === "") {
|
|
41
|
+
out.push(row);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const key = String(row.key);
|
|
45
|
+
if (seen.has(key)) continue;
|
|
46
|
+
seen.add(key);
|
|
47
|
+
out.push(row);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** ADR-0130 D-6: reference consumers declare `public_reference_metadata`
|
|
53
|
+
* directly rather than going through the play-session union above. */
|
|
54
|
+
export function readPublicReferenceMetadataRows(db: SnapshotDb): PublicReferenceMetadataRow[] {
|
|
55
|
+
return rows<PublicReferenceMetadataRow>(db, "public_reference_metadata");
|
|
56
|
+
}
|