@spellkave/sdk 0.0.0-bootstrap
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 +156 -0
- package/package.json +65 -0
- 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,145 @@
|
|
|
1
|
+
import type { EntityContainmentRow as DbEntityContainmentRow } from "../../binding_rows";
|
|
2
|
+
import {
|
|
3
|
+
type RequiredTables,
|
|
4
|
+
registerReaderManifest,
|
|
5
|
+
type SnapshotDb,
|
|
6
|
+
} from "../../reader-manifest";
|
|
7
|
+
import type { EntityRef } from "../ids";
|
|
8
|
+
import {
|
|
9
|
+
asNumber,
|
|
10
|
+
asString,
|
|
11
|
+
buildEntitySummaryMap,
|
|
12
|
+
optString,
|
|
13
|
+
resolveEntityId,
|
|
14
|
+
rows,
|
|
15
|
+
} from "./_helpers";
|
|
16
|
+
|
|
17
|
+
export const requiredTables: RequiredTables<
|
|
18
|
+
[
|
|
19
|
+
"visible_entity_containment",
|
|
20
|
+
"visible_manifest_authored_entity",
|
|
21
|
+
"visible_manifest_authored_entity_coverage",
|
|
22
|
+
"entity",
|
|
23
|
+
]
|
|
24
|
+
> = [
|
|
25
|
+
"visible_entity_containment",
|
|
26
|
+
"visible_manifest_authored_entity",
|
|
27
|
+
"visible_manifest_authored_entity_coverage",
|
|
28
|
+
"entity",
|
|
29
|
+
];
|
|
30
|
+
registerReaderManifest({ requiredTables });
|
|
31
|
+
|
|
32
|
+
export interface InventoryQueryItem {
|
|
33
|
+
entity_id: string;
|
|
34
|
+
container_id: string;
|
|
35
|
+
depth: number;
|
|
36
|
+
container_path: string[];
|
|
37
|
+
slot_id: string;
|
|
38
|
+
/** Authored attach direction, e.g. for a mounted/anchored container slot.
|
|
39
|
+
* Omitted (not "") when unauthored. */
|
|
40
|
+
direction?: string;
|
|
41
|
+
inserted_at_tick: number;
|
|
42
|
+
name: string;
|
|
43
|
+
entity_def_id: string;
|
|
44
|
+
kind: string;
|
|
45
|
+
quantity: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface InventoryProjection {
|
|
49
|
+
root_entity_id: string;
|
|
50
|
+
items: InventoryQueryItem[];
|
|
51
|
+
truncated: boolean;
|
|
52
|
+
max_depth: number;
|
|
53
|
+
max_items: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ReadInventoryProjectionOptions {
|
|
57
|
+
maxDepth?: number;
|
|
58
|
+
maxItems?: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const DEFAULT_MAX_DEPTH = 8;
|
|
62
|
+
const DEFAULT_MAX_ITEMS = 200;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Traverse the server-authorized containment projection from one implicit body.
|
|
66
|
+
* Rows are deterministic by depth then entity id. Cycles are ignored and
|
|
67
|
+
* traversal fails bounded rather than exposing unrelated roots.
|
|
68
|
+
*/
|
|
69
|
+
export function readInventoryProjection(
|
|
70
|
+
db: SnapshotDb,
|
|
71
|
+
actorId: EntityRef,
|
|
72
|
+
options: ReadInventoryProjectionOptions = {},
|
|
73
|
+
): InventoryProjection | null {
|
|
74
|
+
const root = resolveEntityId(db, actorId);
|
|
75
|
+
if (root === undefined) return null;
|
|
76
|
+
const maxDepth = Math.max(0, Math.min(32, Math.trunc(options.maxDepth ?? DEFAULT_MAX_DEPTH)));
|
|
77
|
+
const maxItems = Math.max(1, Math.min(1_000, Math.trunc(options.maxItems ?? DEFAULT_MAX_ITEMS)));
|
|
78
|
+
const summaries = buildEntitySummaryMap(db);
|
|
79
|
+
const byContainer = new Map<string, DbEntityContainmentRow[]>();
|
|
80
|
+
for (const row of rows<DbEntityContainmentRow>(db, "visible_entity_containment")) {
|
|
81
|
+
const key = String(row.containerId);
|
|
82
|
+
const bucket = byContainer.get(key) ?? [];
|
|
83
|
+
bucket.push(row);
|
|
84
|
+
byContainer.set(key, bucket);
|
|
85
|
+
}
|
|
86
|
+
for (const bucket of byContainer.values()) {
|
|
87
|
+
bucket.sort((a, b) =>
|
|
88
|
+
String(a.entityId).localeCompare(String(b.entityId), undefined, { numeric: true }),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const items: InventoryQueryItem[] = [];
|
|
93
|
+
const visited = new Set<string>([String(root)]);
|
|
94
|
+
const queue: { containerId: string; depth: number; path: string[] }[] = [
|
|
95
|
+
{ containerId: String(root), depth: 0, path: [String(root)] },
|
|
96
|
+
];
|
|
97
|
+
let truncated = false;
|
|
98
|
+
while (queue.length > 0) {
|
|
99
|
+
const current = queue.shift();
|
|
100
|
+
if (current === undefined) break;
|
|
101
|
+
const children = byContainer.get(current.containerId) ?? [];
|
|
102
|
+
for (const row of children) {
|
|
103
|
+
const entityId = String(row.entityId);
|
|
104
|
+
if (visited.has(entityId)) continue;
|
|
105
|
+
if (current.depth > maxDepth || items.length >= maxItems) {
|
|
106
|
+
truncated = true;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
visited.add(entityId);
|
|
110
|
+
const summary = summaries.get(entityId);
|
|
111
|
+
const path = [...current.path, entityId];
|
|
112
|
+
const direction = optString(row.direction);
|
|
113
|
+
items.push({
|
|
114
|
+
entity_id: entityId,
|
|
115
|
+
container_id: String(row.containerId),
|
|
116
|
+
depth: current.depth,
|
|
117
|
+
container_path: path,
|
|
118
|
+
slot_id: asString(row.slotId),
|
|
119
|
+
...(direction === undefined ? {} : { direction }),
|
|
120
|
+
inserted_at_tick: asNumber(row.insertedAtTick),
|
|
121
|
+
name: summary?.name ?? "",
|
|
122
|
+
entity_def_id: summary?.entity_def_id ?? "",
|
|
123
|
+
kind: summary?.kind ?? "",
|
|
124
|
+
quantity: summary?.quantity ?? 0,
|
|
125
|
+
});
|
|
126
|
+
if (current.depth < maxDepth) {
|
|
127
|
+
queue.push({ containerId: entityId, depth: current.depth + 1, path });
|
|
128
|
+
} else if ((byContainer.get(entityId)?.length ?? 0) > 0) {
|
|
129
|
+
truncated = true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
items.sort(
|
|
135
|
+
(a, b) =>
|
|
136
|
+
a.depth - b.depth || a.entity_id.localeCompare(b.entity_id, undefined, { numeric: true }),
|
|
137
|
+
);
|
|
138
|
+
return {
|
|
139
|
+
root_entity_id: String(root),
|
|
140
|
+
items,
|
|
141
|
+
truncated,
|
|
142
|
+
max_depth: maxDepth,
|
|
143
|
+
max_items: maxItems,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EntityDefinitionRow,
|
|
3
|
+
EntityDescriptionRow,
|
|
4
|
+
EntityEquipmentSlotRow,
|
|
5
|
+
EquipmentSlotDefinitionRow,
|
|
6
|
+
ObjectStateDefinitionRow,
|
|
7
|
+
ObjectStateRow,
|
|
8
|
+
ResourceDefinitionRow,
|
|
9
|
+
} from "../../binding_rows";
|
|
10
|
+
import {
|
|
11
|
+
type RequiredTables,
|
|
12
|
+
registerReaderManifest,
|
|
13
|
+
type SnapshotDb,
|
|
14
|
+
} from "../../reader-manifest";
|
|
15
|
+
import type { EntityRef } from "../ids";
|
|
16
|
+
import { asNumber, asString, rows } from "./_helpers";
|
|
17
|
+
import { type EntityArt, readPublicEntityArt } from "./entity_art";
|
|
18
|
+
import { readInventoryProjection } from "./inventory_query";
|
|
19
|
+
|
|
20
|
+
export const requiredTables: RequiredTables<
|
|
21
|
+
[
|
|
22
|
+
"visible_entity_containment",
|
|
23
|
+
"visible_manifest_authored_entity",
|
|
24
|
+
"visible_manifest_authored_entity_coverage",
|
|
25
|
+
"entity",
|
|
26
|
+
"visible_entity_equipment_slot",
|
|
27
|
+
"equipment_slot_definition",
|
|
28
|
+
"owned_object_state",
|
|
29
|
+
"entity_definition",
|
|
30
|
+
"entity_description",
|
|
31
|
+
"object_state_definition",
|
|
32
|
+
"resource_definition",
|
|
33
|
+
"public_metadata_attachment",
|
|
34
|
+
"visible_metadata_attachment",
|
|
35
|
+
]
|
|
36
|
+
> = [
|
|
37
|
+
"visible_entity_containment",
|
|
38
|
+
"visible_manifest_authored_entity",
|
|
39
|
+
"visible_manifest_authored_entity_coverage",
|
|
40
|
+
"entity",
|
|
41
|
+
"visible_entity_equipment_slot",
|
|
42
|
+
"equipment_slot_definition",
|
|
43
|
+
"owned_object_state",
|
|
44
|
+
"entity_definition",
|
|
45
|
+
"entity_description",
|
|
46
|
+
"object_state_definition",
|
|
47
|
+
"resource_definition",
|
|
48
|
+
"public_metadata_attachment",
|
|
49
|
+
"visible_metadata_attachment",
|
|
50
|
+
];
|
|
51
|
+
registerReaderManifest({ requiredTables });
|
|
52
|
+
|
|
53
|
+
export interface ItemStateSlice {
|
|
54
|
+
state_id: string;
|
|
55
|
+
display_name?: string;
|
|
56
|
+
/** Authored resource prose for this owned state; absent when unavailable. */
|
|
57
|
+
description?: string;
|
|
58
|
+
value: string;
|
|
59
|
+
source_template_id: string;
|
|
60
|
+
set_at_tick: number;
|
|
61
|
+
expires_at_tick: number;
|
|
62
|
+
bundle_id: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ItemEquipmentRole {
|
|
66
|
+
owner_entity_id: string;
|
|
67
|
+
slot_id: string;
|
|
68
|
+
slot_label: string;
|
|
69
|
+
equipped_at_tick: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ItemDetailProjection {
|
|
73
|
+
entity_id: string;
|
|
74
|
+
art?: EntityArt;
|
|
75
|
+
/** Authored instance prose, falling back to its definition; absent when unauthored. */
|
|
76
|
+
description?: string;
|
|
77
|
+
name: string;
|
|
78
|
+
entity_def_id: string;
|
|
79
|
+
kind: string;
|
|
80
|
+
quantity: number;
|
|
81
|
+
containment: {
|
|
82
|
+
container_id: string;
|
|
83
|
+
depth: number;
|
|
84
|
+
container_path: string[];
|
|
85
|
+
slot_id: string;
|
|
86
|
+
/** Authored attach direction. Omitted (not "") when unauthored. */
|
|
87
|
+
direction?: string;
|
|
88
|
+
};
|
|
89
|
+
equipment: ItemEquipmentRole | null;
|
|
90
|
+
states: ItemStateSlice[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Resolve one item only after it appears in the actor's authorized recursive
|
|
95
|
+
* containment projection. Static entity rows never grant item-detail access.
|
|
96
|
+
*/
|
|
97
|
+
export function readAuthorizedItemDetail(
|
|
98
|
+
db: SnapshotDb,
|
|
99
|
+
actorId: EntityRef,
|
|
100
|
+
itemEntityId: string,
|
|
101
|
+
): ItemDetailProjection | null {
|
|
102
|
+
const inventory = readInventoryProjection(db, actorId);
|
|
103
|
+
const item = inventory?.items.find((candidate) => candidate.entity_id === itemEntityId);
|
|
104
|
+
if (item === undefined) return null;
|
|
105
|
+
const description =
|
|
106
|
+
asString(
|
|
107
|
+
rows<EntityDescriptionRow>(db, "entity_description").find(
|
|
108
|
+
(row) => String(row.entityId) === item.entity_id,
|
|
109
|
+
)?.description,
|
|
110
|
+
) ||
|
|
111
|
+
asString(
|
|
112
|
+
rows<EntityDefinitionRow>(db, "entity_definition").find(
|
|
113
|
+
(row) => row.entityDefId === item.entity_def_id,
|
|
114
|
+
)?.description,
|
|
115
|
+
);
|
|
116
|
+
const labels = new Map(
|
|
117
|
+
rows<ObjectStateDefinitionRow>(db, "object_state_definition").map((row) => [
|
|
118
|
+
row.stateId,
|
|
119
|
+
row.displayName,
|
|
120
|
+
]),
|
|
121
|
+
);
|
|
122
|
+
const descriptions = new Map<string, string>();
|
|
123
|
+
for (const row of rows<ResourceDefinitionRow>(db, "resource_definition")) {
|
|
124
|
+
if (row.displayName) labels.set(row.resourceDefinitionId, row.displayName);
|
|
125
|
+
const prose = asString(row.description);
|
|
126
|
+
if (prose.trim()) descriptions.set(row.resourceDefinitionId, prose);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// #915 PR-6: entity_equipment_slot is private; the caller's own root body
|
|
130
|
+
// is always within its own visible_entity_equipment_slot subset (a caller
|
|
131
|
+
// is always in its own directly-controlled-bodies scope), so this lookup
|
|
132
|
+
// is unaffected in shape — only the source table changed.
|
|
133
|
+
const equipmentRow = rows<EntityEquipmentSlotRow>(db, "visible_entity_equipment_slot").find(
|
|
134
|
+
(row) =>
|
|
135
|
+
String(row.entityId) === inventory?.root_entity_id &&
|
|
136
|
+
String(row.equippedEntityId) === item.entity_id,
|
|
137
|
+
);
|
|
138
|
+
const slotDefinition = equipmentRow
|
|
139
|
+
? rows<EquipmentSlotDefinitionRow>(db, "equipment_slot_definition").find(
|
|
140
|
+
(row) => asString(row.slotId) === asString(equipmentRow.slotId),
|
|
141
|
+
)
|
|
142
|
+
: undefined;
|
|
143
|
+
|
|
144
|
+
const states = rows<ObjectStateRow>(db, "owned_object_state")
|
|
145
|
+
.filter(
|
|
146
|
+
(row) => asString(row.targetKind) === "entity" && asString(row.targetId) === item.entity_id,
|
|
147
|
+
)
|
|
148
|
+
.map((row) => ({
|
|
149
|
+
state_id: asString(row.stateId),
|
|
150
|
+
...(labels.get(asString(row.stateId))
|
|
151
|
+
? { display_name: labels.get(asString(row.stateId)) }
|
|
152
|
+
: {}),
|
|
153
|
+
...(descriptions.has(asString(row.stateId))
|
|
154
|
+
? { description: descriptions.get(asString(row.stateId)) }
|
|
155
|
+
: {}),
|
|
156
|
+
value: stringifyValue(row.value),
|
|
157
|
+
source_template_id: asString(row.sourceTemplateId),
|
|
158
|
+
set_at_tick: asNumber(row.setAtTick),
|
|
159
|
+
expires_at_tick: asNumber(row.expiresAtTick),
|
|
160
|
+
bundle_id: asString(row.bundleId),
|
|
161
|
+
}))
|
|
162
|
+
.sort((a, b) => a.state_id.localeCompare(b.state_id));
|
|
163
|
+
|
|
164
|
+
const art = readPublicEntityArt(db, item.entity_id, item.entity_def_id);
|
|
165
|
+
return {
|
|
166
|
+
entity_id: item.entity_id,
|
|
167
|
+
...(art ? { art } : {}),
|
|
168
|
+
...(description ? { description } : {}),
|
|
169
|
+
name: item.name,
|
|
170
|
+
entity_def_id: item.entity_def_id,
|
|
171
|
+
kind: item.kind,
|
|
172
|
+
quantity: item.quantity,
|
|
173
|
+
containment: {
|
|
174
|
+
container_id: item.container_id,
|
|
175
|
+
depth: item.depth,
|
|
176
|
+
container_path: item.container_path,
|
|
177
|
+
slot_id: item.slot_id,
|
|
178
|
+
...(item.direction === undefined ? {} : { direction: item.direction }),
|
|
179
|
+
},
|
|
180
|
+
equipment: equipmentRow
|
|
181
|
+
? {
|
|
182
|
+
owner_entity_id: String(equipmentRow.entityId),
|
|
183
|
+
slot_id: asString(equipmentRow.slotId),
|
|
184
|
+
slot_label: slotDefinition ? asString(slotDefinition.label) : "",
|
|
185
|
+
equipped_at_tick: asNumber(equipmentRow.equippedAtTick),
|
|
186
|
+
}
|
|
187
|
+
: null,
|
|
188
|
+
states,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function stringifyValue(value: unknown): string {
|
|
193
|
+
if (value === undefined || value === null) return "";
|
|
194
|
+
if (typeof value !== "object") return String(value);
|
|
195
|
+
return JSON.stringify(value, (_key, part: unknown) =>
|
|
196
|
+
typeof part === "bigint" ? part.toString() : part,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// Reader: location snapshot (place_node + place_edge + actor_spatial_location).
|
|
2
|
+
// Mechanical split from readers.ts; no new functionality.
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
ActorSpatialLocationRow,
|
|
6
|
+
PlaceEdgeAffordanceRow,
|
|
7
|
+
PlaceEdgeRow,
|
|
8
|
+
PlaceGraphDefinitionRow,
|
|
9
|
+
PlaceNodeRow,
|
|
10
|
+
} from "../../binding_rows";
|
|
11
|
+
import {
|
|
12
|
+
type RequiredTables,
|
|
13
|
+
registerReaderManifest,
|
|
14
|
+
type SnapshotDb,
|
|
15
|
+
} from "../../reader-manifest";
|
|
16
|
+
import { asString, buildEntityFactionMap, buildEntityNameMap, rows } from "./_helpers";
|
|
17
|
+
|
|
18
|
+
export const requiredTables: RequiredTables<
|
|
19
|
+
[
|
|
20
|
+
"visible_place_node",
|
|
21
|
+
"visible_place_edge",
|
|
22
|
+
"place_edge_affordance",
|
|
23
|
+
"visible_actor_spatial_location",
|
|
24
|
+
"visible_place_graph_definition",
|
|
25
|
+
"entity",
|
|
26
|
+
"visible_entity_tag",
|
|
27
|
+
"visible_entity_tag_coverage",
|
|
28
|
+
]
|
|
29
|
+
> = [
|
|
30
|
+
"visible_place_node",
|
|
31
|
+
"visible_place_edge",
|
|
32
|
+
"place_edge_affordance",
|
|
33
|
+
"visible_actor_spatial_location",
|
|
34
|
+
"visible_place_graph_definition",
|
|
35
|
+
"entity",
|
|
36
|
+
"visible_entity_tag",
|
|
37
|
+
"visible_entity_tag_coverage",
|
|
38
|
+
];
|
|
39
|
+
registerReaderManifest({ requiredTables });
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* One `place_edge_affordance` row paired with an edge — ADR-0101 D-1 added
|
|
43
|
+
* `mode_id` (open author-chosen traversal-mode id; `""` = the implicit
|
|
44
|
+
* default mode) alongside the template it names.
|
|
45
|
+
*/
|
|
46
|
+
export interface EdgeAffordanceBinding {
|
|
47
|
+
template_id: string;
|
|
48
|
+
mode_id: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface LocationOutgoingEdge {
|
|
52
|
+
edge_id: string;
|
|
53
|
+
to_node_id: string;
|
|
54
|
+
direction: string | null;
|
|
55
|
+
/**
|
|
56
|
+
* Affordance templates paired with this edge (`place_edge_affordance`),
|
|
57
|
+
* i.e. what an actor would have to satisfy to traverse it (#1987), each
|
|
58
|
+
* with its `mode_id` (ADR-0101 D-1) — rows sharing one `mode_id` AND-join;
|
|
59
|
+
* distinct `mode_id`s on the same edge are alternatives (OR, the kernel
|
|
60
|
+
* picks the cheapest passing one). NOTE: this reads ONLY authored
|
|
61
|
+
* `place_edge_affordance` rows on the edge itself — a `movement_default`
|
|
62
|
+
* resolved via edge > graph > bundle inheritance (ADR-0101 D-2) is NOT
|
|
63
|
+
* projected here yet, so a zero-per-edge-row edge (A-1's own idiom) shows
|
|
64
|
+
* an empty array even though it may still be traversable.
|
|
65
|
+
*
|
|
66
|
+
* TOPOLOGY, not permission: this says which gate stands here, never whether
|
|
67
|
+
* a given actor passes it — that answer lives in the actor's affordance
|
|
68
|
+
* palette, which is deliberately a different question and a different
|
|
69
|
+
* layer. A caller joins the two to tell "there is a way, currently shut"
|
|
70
|
+
* apart from "there is no way", which was previously indistinguishable.
|
|
71
|
+
*
|
|
72
|
+
* Empty for an edge with no paired template.
|
|
73
|
+
*/
|
|
74
|
+
affordance_bindings: EdgeAffordanceBinding[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* An actor present at this node, enriched with authored identity (#1849).
|
|
79
|
+
* Sibling of the bare `actors_here` id list (kept for existing identity/
|
|
80
|
+
* co-location callers — SDK CLAUDE.md §2 host-neutral row types stay stable);
|
|
81
|
+
* this is the display-oriented view for a perceiver that needs to know WHO is
|
|
82
|
+
* here, not just that someone is.
|
|
83
|
+
*/
|
|
84
|
+
export interface LocationActorEntry {
|
|
85
|
+
entity_id: string;
|
|
86
|
+
/** Authored instance name from the `entity` table. */
|
|
87
|
+
name: string;
|
|
88
|
+
/** First `faction:<name>` tag suffix on this entity, or `null` if untagged. */
|
|
89
|
+
faction: string | null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface LocationSnapshot {
|
|
93
|
+
node_id: string;
|
|
94
|
+
/**
|
|
95
|
+
* Authored display name for this place node (`place_node.display_name`) —
|
|
96
|
+
* e.g. for `{place_name}` interpolation in authored observation prose
|
|
97
|
+
* (#1968 B-9). Distinct from `node_description`: a name, not atmospheric
|
|
98
|
+
* prose.
|
|
99
|
+
*/
|
|
100
|
+
node_display_name: string;
|
|
101
|
+
/**
|
|
102
|
+
* Authored atmospheric prose for this place node. Graph-static authored
|
|
103
|
+
* content; empty string when no description has been authored.
|
|
104
|
+
* NOT a hidden-state channel — conditional reveals use affordance +
|
|
105
|
+
* observer_knowledge, never gated description text (ADR-0021 perception
|
|
106
|
+
* residual).
|
|
107
|
+
*/
|
|
108
|
+
node_description: string;
|
|
109
|
+
/**
|
|
110
|
+
* Authored atmospheric prose for the graph containing this node. Empty
|
|
111
|
+
* string when no description has been authored on the graph.
|
|
112
|
+
* Same static-prose guarantee as node_description.
|
|
113
|
+
*/
|
|
114
|
+
graph_description: string;
|
|
115
|
+
/**
|
|
116
|
+
* Authored Z-axis elevation of the node in world units (positive = above
|
|
117
|
+
* ground, negative = underground). `null` when `pose_elevation_present=false`
|
|
118
|
+
* (elevation not authored for this node).
|
|
119
|
+
*/
|
|
120
|
+
pose_elevation: number | null;
|
|
121
|
+
outgoing_edges: LocationOutgoingEdge[];
|
|
122
|
+
/** Bare entity ids of actors present — the identity/co-location list existing
|
|
123
|
+
* callers filter/compare against. */
|
|
124
|
+
actors_here: string[];
|
|
125
|
+
/** Same actors as `actors_here`, enriched with name + faction (#1849) — the
|
|
126
|
+
* display list for surfaces that must not leave a target anonymous. */
|
|
127
|
+
actor_details: LocationActorEntry[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const COMPASS = [
|
|
131
|
+
"east",
|
|
132
|
+
"northeast",
|
|
133
|
+
"north",
|
|
134
|
+
"northwest",
|
|
135
|
+
"west",
|
|
136
|
+
"southwest",
|
|
137
|
+
"south",
|
|
138
|
+
"southeast",
|
|
139
|
+
] as const;
|
|
140
|
+
|
|
141
|
+
function metricDirection(fromX: number, fromY: number, toX: number, toY: number): string {
|
|
142
|
+
const dx = toX - fromX;
|
|
143
|
+
const dy = toY - fromY;
|
|
144
|
+
const deg = Math.atan2(dy, dx) * (180 / Math.PI);
|
|
145
|
+
const normalised = deg < 0 ? deg + 360 : deg;
|
|
146
|
+
const sector = Math.floor((normalised + 22.5) / 45) % 8;
|
|
147
|
+
// biome-ignore lint/style/noNonNullAssertion: pre-existing debt from #1368 biome onboarding, tracked in #1455
|
|
148
|
+
return COMPASS[sector]!; // sector is always 0–7 via % 8
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Read per-location snapshot. Returns `null` if `visible_place_node` does not contain `nodeId`.
|
|
153
|
+
*/
|
|
154
|
+
export function readLocationSnapshot(db: SnapshotDb, nodeId: string): LocationSnapshot | null {
|
|
155
|
+
const allNodes = rows<PlaceNodeRow>(db, "visible_place_node");
|
|
156
|
+
const nodeMap = new Map(allNodes.map((n) => [n.nodeId, n]));
|
|
157
|
+
const node = nodeMap.get(nodeId);
|
|
158
|
+
if (!node) return null;
|
|
159
|
+
|
|
160
|
+
const graphRow = rows<PlaceGraphDefinitionRow>(db, "visible_place_graph_definition").find(
|
|
161
|
+
(g) => g.placeGraphId === node.placeGraphId,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// `place_edge_affordance` keys by the AUTHORED `edge_key`, not the runtime
|
|
165
|
+
// `edge_id`, so the join goes through `place_edge`'s own `edge_key` column.
|
|
166
|
+
const bindingsByEdgeKey = new Map<string, EdgeAffordanceBinding[]>();
|
|
167
|
+
for (const row of rows<PlaceEdgeAffordanceRow>(db, "place_edge_affordance")) {
|
|
168
|
+
const key = asString(row.edgeKey);
|
|
169
|
+
const binding: EdgeAffordanceBinding = {
|
|
170
|
+
template_id: asString(row.affordanceTemplateId),
|
|
171
|
+
mode_id: asString(row.modeId),
|
|
172
|
+
};
|
|
173
|
+
const list = bindingsByEdgeKey.get(key);
|
|
174
|
+
if (list === undefined) bindingsByEdgeKey.set(key, [binding]);
|
|
175
|
+
else list.push(binding);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const outgoing_edges = rows<PlaceEdgeRow>(db, "visible_place_edge")
|
|
179
|
+
.filter((r) => r.fromNodeId === nodeId)
|
|
180
|
+
.map((r): LocationOutgoingEdge => {
|
|
181
|
+
const toNode = nodeMap.get(r.toNodeId);
|
|
182
|
+
const direction =
|
|
183
|
+
node.posPresent && toNode?.posPresent
|
|
184
|
+
? metricDirection(node.posX, node.posY, toNode.posX, toNode.posY)
|
|
185
|
+
: null;
|
|
186
|
+
return {
|
|
187
|
+
edge_id: asString(r.edgeId),
|
|
188
|
+
to_node_id: r.toNodeId,
|
|
189
|
+
direction,
|
|
190
|
+
affordance_bindings: bindingsByEdgeKey.get(asString(r.edgeKey)) ?? [],
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const entityNames = buildEntityNameMap(db);
|
|
195
|
+
const entityFactions = buildEntityFactionMap(db);
|
|
196
|
+
const actors_here = rows<ActorSpatialLocationRow>(db, "visible_actor_spatial_location")
|
|
197
|
+
.filter((r) => r.placeNodeId === nodeId)
|
|
198
|
+
.map((r) => String(r.entityId))
|
|
199
|
+
.filter((s) => s.length > 0);
|
|
200
|
+
const actor_details: LocationActorEntry[] = actors_here.map((entityId) => ({
|
|
201
|
+
entity_id: entityId,
|
|
202
|
+
name: entityNames.get(entityId) ?? "",
|
|
203
|
+
faction: entityFactions.get(entityId) ?? null,
|
|
204
|
+
}));
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
node_id: nodeId,
|
|
208
|
+
node_display_name: node.displayName ?? "",
|
|
209
|
+
node_description: node.description ?? "",
|
|
210
|
+
graph_description: graphRow?.description ?? "",
|
|
211
|
+
pose_elevation: node.poseElevationPresent ? node.poseElevation : null,
|
|
212
|
+
outgoing_edges,
|
|
213
|
+
actors_here,
|
|
214
|
+
actor_details,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Authenticated audit view: the server exposes only the applier's rows or all rows to its publisher.
|
|
2
|
+
import {
|
|
3
|
+
type RequiredTables,
|
|
4
|
+
registerReaderManifest,
|
|
5
|
+
type SnapshotDb,
|
|
6
|
+
} from "../../reader-manifest";
|
|
7
|
+
import { asNumber, asString, rows } from "./_helpers";
|
|
8
|
+
export const requiredTables: RequiredTables<["visible_manifest_apply_provenance"]> = [
|
|
9
|
+
"visible_manifest_apply_provenance",
|
|
10
|
+
];
|
|
11
|
+
registerReaderManifest({ requiredTables });
|
|
12
|
+
export interface ManifestApplyProvenanceRow {
|
|
13
|
+
key: string;
|
|
14
|
+
digest: string;
|
|
15
|
+
appliedBy: string;
|
|
16
|
+
appliedVia: string[];
|
|
17
|
+
appliedAtTick: number;
|
|
18
|
+
}
|
|
19
|
+
/** Missing rows mean unavailable audit metadata; they never imply the caller was the publisher. */
|
|
20
|
+
export function readManifestApplyProvenance(db: SnapshotDb): ManifestApplyProvenanceRow[] {
|
|
21
|
+
return rows<Record<string, unknown>>(
|
|
22
|
+
db,
|
|
23
|
+
"visibleManifestApplyProvenance",
|
|
24
|
+
"visible_manifest_apply_provenance",
|
|
25
|
+
).map((row) => ({
|
|
26
|
+
key: asString(row.key),
|
|
27
|
+
digest: asString(row.digest),
|
|
28
|
+
appliedBy: asString(row.appliedBy ?? row.applied_by),
|
|
29
|
+
appliedVia: ((row.appliedVia ?? row.applied_via) as string[] | undefined) ?? [],
|
|
30
|
+
appliedAtTick: asNumber(row.appliedAtTick ?? row.applied_at_tick),
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Reader: ADR-0149 export result, read through the view over the caller's
|
|
2
|
+
// own rows. The retired `manifest_export` buffer is private and no longer written.
|
|
3
|
+
//
|
|
4
|
+
// The view is subscribed only when the module lists it
|
|
5
|
+
// (`OPTIONAL_SATELLITE_TABLES` in connection.ts). A module without the view
|
|
6
|
+
// has no export on this client.
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type RequiredTables,
|
|
10
|
+
registerReaderManifest,
|
|
11
|
+
type SnapshotDb,
|
|
12
|
+
} from "../../reader-manifest";
|
|
13
|
+
import { asNumber, asString, rows } from "./_helpers";
|
|
14
|
+
|
|
15
|
+
export const MANIFEST_EXPORT_VIEW = "visible_manifest_export_result";
|
|
16
|
+
|
|
17
|
+
// Declares the view. `buildSubscribeSet` drops it; `subscribeSetForSurface`
|
|
18
|
+
// adds it back only when the published module lists it.
|
|
19
|
+
export const requiredTables: RequiredTables<[typeof MANIFEST_EXPORT_VIEW]> = [MANIFEST_EXPORT_VIEW];
|
|
20
|
+
registerReaderManifest({ requiredTables });
|
|
21
|
+
|
|
22
|
+
export interface ManifestExportRow {
|
|
23
|
+
bundleId: string;
|
|
24
|
+
requestedAtTick: number;
|
|
25
|
+
manifestJson: string;
|
|
26
|
+
status: string;
|
|
27
|
+
rowCount: number;
|
|
28
|
+
diagnostics: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class ManifestExportUnavailableError extends Error {
|
|
32
|
+
constructor() {
|
|
33
|
+
super("manifest export is not available");
|
|
34
|
+
this.name = "ManifestExportUnavailableError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** True when the published module lists the export view. */
|
|
39
|
+
export function manifestExportAvailable(tables: readonly string[]): boolean {
|
|
40
|
+
return tables.includes(MANIFEST_EXPORT_VIEW);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Refuse an export against a module that does not list the view. Callers
|
|
45
|
+
* that already know the surface use this before `r_export_manifest`.
|
|
46
|
+
*/
|
|
47
|
+
export function assertManifestExportAvailable(tables: readonly string[]): void {
|
|
48
|
+
if (!manifestExportAvailable(tables)) {
|
|
49
|
+
throw new ManifestExportUnavailableError();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Read the caller's export result for `bundleId` from the view, or `undefined`. */
|
|
54
|
+
export function readManifestExport(
|
|
55
|
+
db: SnapshotDb,
|
|
56
|
+
bundleId: string,
|
|
57
|
+
): ManifestExportRow | undefined {
|
|
58
|
+
const row = rows<{
|
|
59
|
+
bundleId?: unknown;
|
|
60
|
+
bundle_id?: unknown;
|
|
61
|
+
requestedAtTick?: unknown;
|
|
62
|
+
requested_at_tick?: unknown;
|
|
63
|
+
manifestJson?: unknown;
|
|
64
|
+
manifest_json?: unknown;
|
|
65
|
+
status?: unknown;
|
|
66
|
+
rowCount?: unknown;
|
|
67
|
+
row_count?: unknown;
|
|
68
|
+
diagnostics?: unknown;
|
|
69
|
+
}>(db, "visibleManifestExportResult", "visible_manifest_export_result").find(
|
|
70
|
+
(candidate) => asString(candidate.bundleId ?? candidate.bundle_id) === bundleId,
|
|
71
|
+
);
|
|
72
|
+
if (row === undefined) return undefined;
|
|
73
|
+
return {
|
|
74
|
+
bundleId: asString(row.bundleId ?? row.bundle_id),
|
|
75
|
+
requestedAtTick: asNumber(row.requestedAtTick ?? row.requested_at_tick),
|
|
76
|
+
manifestJson: asString(row.manifestJson ?? row.manifest_json),
|
|
77
|
+
status: asString(row.status),
|
|
78
|
+
rowCount: asNumber(row.rowCount ?? row.row_count),
|
|
79
|
+
diagnostics: asString(row.diagnostics),
|
|
80
|
+
};
|
|
81
|
+
}
|