@arcforge/types 2.0.218 → 2.0.243
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/package.json +6 -2
- package/src/agent-handle.ts +2 -1
- package/src/blueprint.ts +19 -3
- package/src/body/body.ts +669 -0
- package/src/cognet/blueprint.ts +32 -4
- package/src/cognet/cognet.ts +126 -11
- package/src/cognet/index.ts +2 -2
- package/src/config.ts +21 -3
- package/src/connections.ts +70 -0
- package/src/define.ts +34 -0
- package/src/engine.ts +33 -3
- package/src/error.ts +11 -0
- package/src/handle.ts +67 -0
- package/src/index.ts +8 -0
- package/src/inference.ts +193 -12
- package/src/kernel/abi.ts +132 -10
- package/src/kernel/index.ts +1 -1
- package/src/machine.ts +17 -0
- package/src/provider-usage.ts +63 -0
- package/src/services.ts +79 -0
- package/src/session/channel.ts +15 -0
- package/src/session/envelope.ts +10 -1
- package/src/session/events/activity.ts +13 -1
- package/src/session/events/build.ts +26 -1
- package/src/session/events/cognet.ts +211 -15
- package/src/session/events/kernel.ts +20 -0
- package/src/session/events/runtime.ts +29 -1
- package/src/session/events/stdio/output.ts +6 -0
- package/src/session/events/stdio/shared.ts +35 -0
- package/src/session/events/stdio/stimuli.ts +17 -0
- package/src/session/index.ts +4 -1
- package/src/session/session.ts +2 -2
- package/src/session/text.ts +36 -0
- package/src/supervisor.ts +45 -4
- package/src/tui-contract.ts +1 -1
- package/src/tui.ts +14 -0
- package/src/usage.ts +83 -0
- package/src/world/world.ts +224 -0
package/src/body/body.ts
ADDED
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
3
|
+
* THE BODY CONTRACT — axon.body/1 2026-10-08
|
|
4
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
5
|
+
*
|
|
6
|
+
* How any body — a Minecraft player, a Terraria one, a container's shell, a
|
|
7
|
+
* robot behind ROS — is worn by any mind. Exported from @arcforge/types as
|
|
8
|
+
* the `body` namespace (`body.Manifest`). Checking a manifest, the wire, URDF
|
|
9
|
+
* and examples of real bodies are @arcforge/body's.
|
|
10
|
+
*
|
|
11
|
+
* THE SHAPE
|
|
12
|
+
*
|
|
13
|
+
* lab lease ─► endpoint ─► connect ─► Manifest ─► readings · commands · skills
|
|
14
|
+
* └─► truth (recorded, never to the mind)
|
|
15
|
+
*
|
|
16
|
+
* A body describes itself once, in a Manifest, then streams readings and
|
|
17
|
+
* takes commands on the channels it declared. Everything game- or
|
|
18
|
+
* robot-specific lives on the body's side, so an agent needs ONE generic
|
|
19
|
+
* body module, not one per game.
|
|
20
|
+
*
|
|
21
|
+
* THE RULES
|
|
22
|
+
*
|
|
23
|
+
* 1. The kernel's two verbs already split the way ROS does. `output()` is a
|
|
24
|
+
* topic the mind publishes — unmediated, for control loops — and carries
|
|
25
|
+
* Commands. `run()` is an action — policy-checked, with a result — and
|
|
26
|
+
* carries Skill requests. A control loop never goes through `run()`.
|
|
27
|
+
*
|
|
28
|
+
* 2. Physical quantities are SI (ROS REP 103): metres, seconds, radians. A
|
|
29
|
+
* Minecraft block is one metre, Minecraft's own convention. The body
|
|
30
|
+
* converts once, so no mind ever converts per body.
|
|
31
|
+
*
|
|
32
|
+
* 3. Truth is a different message, not a filtered field. What the body
|
|
33
|
+
* senses is a Reading; what the world knows (true position, velocity) is
|
|
34
|
+
* Truth, recorded beside the session and never delivered. Nothing has to
|
|
35
|
+
* be stripped before the mind sees it.
|
|
36
|
+
*
|
|
37
|
+
* 4. Every reading is stamped on the body's own clock, and every command
|
|
38
|
+
* says which reading it was decided on — so sense-to-act latency is
|
|
39
|
+
* measured for every command, on one clock.
|
|
40
|
+
*
|
|
41
|
+
* 5. Three protections, three places — none of them in a control loop:
|
|
42
|
+
* CONTAINMENT (the OS wall around the mind's process) is paid once, at
|
|
43
|
+
* spawn. MEDIATION (the policy check on `run()`) is per skill. LIMITS
|
|
44
|
+
* (ranges, slew, the lapse) are enforced by the BODY, on whatever
|
|
45
|
+
* arrives: the manifest declares them so the mind knows, and the mind
|
|
46
|
+
* cannot change them. So `output()` needs no check: the body clamps —
|
|
47
|
+
* and says, in `applied`, what it actually did.
|
|
48
|
+
*
|
|
49
|
+
* 6. What is safe when the mind stops is the body's to say. Letting go is
|
|
50
|
+
* safe for legs and fatal for a drone, so every control declares its
|
|
51
|
+
* lapse: let go, keep the target, or a behaviour of the body's own
|
|
52
|
+
* (hover, then land). The mind never has to stay alive to keep a body
|
|
53
|
+
* safe.
|
|
54
|
+
*
|
|
55
|
+
* 7. One mind wears one body, and one agent has one mind. A swarm, a house
|
|
56
|
+
* of devices, two arms: each is one body with many parts, or many
|
|
57
|
+
* agents. Nothing here addresses a second body.
|
|
58
|
+
*
|
|
59
|
+
* HOW IT MAPS TO ROS
|
|
60
|
+
*
|
|
61
|
+
* Clock header stamp Sense sensor_msgs topic
|
|
62
|
+
* Frame link (URDF), tf Control ros2_control command interface
|
|
63
|
+
* Joint joint (URDF) Skill action (goal → progress → result)
|
|
64
|
+
* Place map, odom, earth Lapse a controller's timeout and safe state
|
|
65
|
+
* Lens sensor_msgs/CameraInfo Trajectory trajectory_msgs/JointTrajectory
|
|
66
|
+
* Component message field Truth — (a lab's privilege)
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
70
|
+
// 0. JOINING — how a mind comes to wear a body
|
|
71
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
72
|
+
//
|
|
73
|
+
// The WORLD brings the body; the agent brings only the mind. A body is part
|
|
74
|
+
// of its world — a player in Minecraft, a robot in a simulator — so the lab
|
|
75
|
+
// offers bodies, and the agent's body module asks for one:
|
|
76
|
+
//
|
|
77
|
+
// 1. Lease the body module asks the lab for a body (LeaseRequest);
|
|
78
|
+
// the lab picks or boots one, puts it in the world, and
|
|
79
|
+
// answers where it is (Lease). A lab hands out bodies of
|
|
80
|
+
// its own kind; which lab an agent asks is its choice.
|
|
81
|
+
// 2. Connect to the endpoint, with the token. The body sends its
|
|
82
|
+
// Manifest, then Presence.
|
|
83
|
+
// 3. Mount the manifest is handed to the kernel; senses become
|
|
84
|
+
// stimuli, controls are what `output()` drives, skills are
|
|
85
|
+
// what `run()` may ask, truth goes to the recorder.
|
|
86
|
+
// 4. Live Readings in; Commands and SkillRequests out.
|
|
87
|
+
// 5. Leave release the lease, or drop the connection: every control
|
|
88
|
+
// lapses as it declared, and the lab takes the body back.
|
|
89
|
+
|
|
90
|
+
/** What the agent's body module asks a lab for. */
|
|
91
|
+
export type LeaseRequest = {
|
|
92
|
+
/** The agent, as its package names it. */
|
|
93
|
+
agent: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The lab's answer: a body, where it is, and how to reach it. */
|
|
97
|
+
export type Lease = {
|
|
98
|
+
lease: string
|
|
99
|
+
/** What the lab calls the body, the world it is in, and the name it goes by there — for logs and people. */
|
|
100
|
+
body: string
|
|
101
|
+
world: string
|
|
102
|
+
identity: string
|
|
103
|
+
/** Where the body speaks this contract — a WebSocket URL. */
|
|
104
|
+
endpoint: string
|
|
105
|
+
/** Presented when connecting; good for this lease only. */
|
|
106
|
+
token: string
|
|
107
|
+
/** When the lease runs out unless renewed, ms since the epoch; absent, it is held until released. */
|
|
108
|
+
expires?: number
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
112
|
+
// 1. THE MANIFEST — what a body says about itself
|
|
113
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
114
|
+
|
|
115
|
+
/** Sent when the body connects, and whole again whenever any of it changes. */
|
|
116
|
+
export type Manifest = {
|
|
117
|
+
/** A body speaking a contract the mind does not know is refused by name, never guessed at. */
|
|
118
|
+
contract: "axon.body/1"
|
|
119
|
+
/** `minecraft.player`, `ros2:turtlebot4`. For logs and people — a mind must never branch on it. */
|
|
120
|
+
kind: string
|
|
121
|
+
clock: Clock
|
|
122
|
+
world: World
|
|
123
|
+
frames: Frame[]
|
|
124
|
+
senses: Sense[]
|
|
125
|
+
controls: Control[]
|
|
126
|
+
skills: Skill[]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* What every `sensed` stamp counts: milliseconds since some moment of the
|
|
131
|
+
* body's own. A body that moves in steps (a game at 20 ticks a second, a
|
|
132
|
+
* physics simulation) gives its step.
|
|
133
|
+
*
|
|
134
|
+
* Stamps from one body compare only with each other — never with the mind's
|
|
135
|
+
* clock, never with another body's.
|
|
136
|
+
*/
|
|
137
|
+
export type Clock = {
|
|
138
|
+
unit: "ms"
|
|
139
|
+
step?: number
|
|
140
|
+
pace: Pace
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* How the body's time passes against the wall's — what a mind needs to know
|
|
145
|
+
* before it budgets a deadline in it.
|
|
146
|
+
*
|
|
147
|
+
* real as the wall's: a robot, a game played live
|
|
148
|
+
* scaled `factor` times the wall's: a simulation run fast or slow, 0
|
|
149
|
+
* while paused. A change of pace is a change of manifest.
|
|
150
|
+
* stepped only when told: the body advances `steps` steps on a Step,
|
|
151
|
+
* says everything it sensed, then waits (Waiting). Training,
|
|
152
|
+
* and any simulation that must not run ahead of its mind.
|
|
153
|
+
* Needs `step`.
|
|
154
|
+
*/
|
|
155
|
+
export type Pace = { kind: "real" } | { kind: "scaled"; factor: number } | { kind: "stepped" }
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The world as the body lives in it — what is true of the space, not of the
|
|
159
|
+
* body: how many dimensions it has, how hard it pulls, and the frames fixed
|
|
160
|
+
* to it that some senses read in (REP 105).
|
|
161
|
+
*/
|
|
162
|
+
export type World = {
|
|
163
|
+
space: Space
|
|
164
|
+
/** How hard the world pulls down (its −z), m/s². Absent where nothing pulls: orbit, a top-down world. */
|
|
165
|
+
gravity?: number
|
|
166
|
+
/** The base is fixed to the world and never moves in it: an arm on a bench, a house. */
|
|
167
|
+
anchored?: boolean
|
|
168
|
+
/** Frames fixed to the world rather than the body. A sense may read in one; none is ever a body's frame. */
|
|
169
|
+
places: Place[]
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Three dimensions, or two: a plane the body lives in, named by the two of its
|
|
174
|
+
* base's axes that span it. A side-on world (Terraria) is `xz` — forward and
|
|
175
|
+
* up, nothing to the left. A top-down world is `xy` — no up. Or none: a body
|
|
176
|
+
* with no place in any space — a shell, an account — is its base alone, and
|
|
177
|
+
* nothing in it names a frame.
|
|
178
|
+
*/
|
|
179
|
+
export type Space = { dimensions: 3 } | { dimensions: 2; plane: "xz" | "xy" } | { dimensions: 0 }
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* A frame fixed to the world.
|
|
183
|
+
*
|
|
184
|
+
* local flat and level: z up, x and y level — east and north where the
|
|
185
|
+
* place has a compass. A room's motion capture, a site's map, a
|
|
186
|
+
* game's world.
|
|
187
|
+
* geodetic on a planet: latitude and longitude, rad, and height above
|
|
188
|
+
* its reference surface, m — what a GNSS receiver reads.
|
|
189
|
+
* `datum` names the surface: `WGS84` for Earth,
|
|
190
|
+
* `IAU_2015:49900` for Mars.
|
|
191
|
+
*/
|
|
192
|
+
export type Place = { name: string; kind: "local" } | { name: string; kind: "geodetic"; datum: string }
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A set of axes, placed on its parent. Exactly one frame has no parent: the
|
|
196
|
+
* body's base. Together they form a tree (ROS: tf).
|
|
197
|
+
*
|
|
198
|
+
* flu — x forward, y left, z up for a body and its parts
|
|
199
|
+
* rdf — x right, y down, z forward for a camera's optical axes
|
|
200
|
+
*
|
|
201
|
+
* A frame is a link of the body's skeleton (URDF). `at` and `turn` place it
|
|
202
|
+
* on its parent as it rests. A frame with no `joint` never moves on its parent
|
|
203
|
+
* (a camera bolted to a head); one with a joint moves as the joint does.
|
|
204
|
+
*
|
|
205
|
+
* A skeleton is optional: a body may be one frame and a camera (Terraria), or
|
|
206
|
+
* a dozen jointed links (a quadruped). It is the same shape either way.
|
|
207
|
+
*/
|
|
208
|
+
export type Frame = {
|
|
209
|
+
name: string
|
|
210
|
+
parent: string | null
|
|
211
|
+
axes: "flu" | "rdf"
|
|
212
|
+
/** metres, in the parent's axes, at rest */
|
|
213
|
+
at: Vec3
|
|
214
|
+
/** a unit quaternion, [x, y, z, w], at rest */
|
|
215
|
+
turn: Quat
|
|
216
|
+
joint?: Joint
|
|
217
|
+
/** What the link is, for a mind that models its own body: what it is made of, what it bumps into. */
|
|
218
|
+
shape?: Shape
|
|
219
|
+
/** kg */
|
|
220
|
+
mass?: number
|
|
221
|
+
/** Where the mass is centred, metres in the frame's axes — at its origin when absent. */
|
|
222
|
+
centre?: Vec3
|
|
223
|
+
/** kg·m², about the centre of mass, in the frame's axes: [ixx, ixy, ixz, iyy, iyz, izz] — for a mind, or a simulator, that models its dynamics. */
|
|
224
|
+
inertia?: [number, number, number, number, number, number]
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* How a frame moves on its parent (URDF joint types):
|
|
229
|
+
*
|
|
230
|
+
* revolute turns about `axis`, within limits — a knee
|
|
231
|
+
* continuous turns about `axis`, without end — a wheel
|
|
232
|
+
* prismatic slides along `axis` — a lift
|
|
233
|
+
* planar moves in the plane normal to `axis`
|
|
234
|
+
* floating moves freely — a body's base in its world
|
|
235
|
+
*
|
|
236
|
+
* Where a joint IS arrives on a sense of profile `sensor_msgs/JointState`, its
|
|
237
|
+
* components named after the joints; a joint no sense reports is known only
|
|
238
|
+
* through what the body feels and what was sent.
|
|
239
|
+
*/
|
|
240
|
+
export type Joint = {
|
|
241
|
+
/** The joint's own name, where it has one apart from its frame's (URDF names joints and links separately). */
|
|
242
|
+
name?: string
|
|
243
|
+
type: "revolute" | "continuous" | "prismatic" | "planar" | "floating"
|
|
244
|
+
/** In this frame's own axes, a unit vector. */
|
|
245
|
+
axis: Vec3
|
|
246
|
+
limits?: {
|
|
247
|
+
/** rad or m */
|
|
248
|
+
position?: [number, number]
|
|
249
|
+
/** rad/s or m/s */
|
|
250
|
+
velocity?: number
|
|
251
|
+
/** N·m or N */
|
|
252
|
+
effort?: number
|
|
253
|
+
}
|
|
254
|
+
/** How the joint resists: viscous `damping` (N·m·s/rad or N·s/m) and dry `friction` (N·m or N). */
|
|
255
|
+
dynamics?: { damping?: number; friction?: number }
|
|
256
|
+
/**
|
|
257
|
+
* Moves as another joint does, never on its own: at `multiplier` × the
|
|
258
|
+
* other's position + `offset` — a gripper's second finger. `joint` names
|
|
259
|
+
* the other's frame. Nothing drives a mimicking joint.
|
|
260
|
+
*/
|
|
261
|
+
mimic?: { joint: string; multiplier: number; offset: number }
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* What a link is shaped like, placed on its frame by `place` (at its origin
|
|
266
|
+
* when absent). One shape a link: a cylinder's length runs along its z, as in
|
|
267
|
+
* URDF.
|
|
268
|
+
*/
|
|
269
|
+
export type Shape = (
|
|
270
|
+
| { kind: "box"; size: Vec3 }
|
|
271
|
+
| { kind: "cylinder"; radius: number; length: number }
|
|
272
|
+
| { kind: "sphere"; radius: number }
|
|
273
|
+
/** A mesh too large to carry, scaled by `scale`. */
|
|
274
|
+
| { kind: "mesh"; ref: Ref; scale?: Vec3 }
|
|
275
|
+
) & { place?: { at: Vec3; turn: Quat } }
|
|
276
|
+
|
|
277
|
+
/** One number in a reading or a command: what it is, in what, and its limits. */
|
|
278
|
+
export type Component = {
|
|
279
|
+
name: string
|
|
280
|
+
/**
|
|
281
|
+
* SI when physical — m, m/s, m/s², rad, rad/s, N, K; otherwise bool,
|
|
282
|
+
* count, fraction — or `category`: one of `categories`, by its index (a
|
|
283
|
+
* flight mode, a gear, what the hands hold).
|
|
284
|
+
*/
|
|
285
|
+
unit: string
|
|
286
|
+
range?: [number, number]
|
|
287
|
+
/** How far off one reading is, one standard deviation, in its unit — what an estimator weighs it by (ROS: covariance). */
|
|
288
|
+
noise?: number
|
|
289
|
+
/** What each index means, when the unit is `category`; only then. */
|
|
290
|
+
categories?: string[]
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ── senses ────────────────────────────────────────────────────────────────
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* One instrument, on the channel its readings arrive as stimuli. What every
|
|
297
|
+
* reading would otherwise repeat — its frame, its components, a camera's lens —
|
|
298
|
+
* is said once, here.
|
|
299
|
+
*/
|
|
300
|
+
export type Sense = VectorSense | VisualSense | AudioSense | TextSense
|
|
301
|
+
|
|
302
|
+
type SenseBase = {
|
|
303
|
+
channel: string
|
|
304
|
+
/** Whose axes its numbers or its picture are in — a body frame, or a place (a GNSS fix is the planet's). Absent for what has no direction: hunger, a microphone. */
|
|
305
|
+
frame?: string
|
|
306
|
+
/** Readings a second, nominal; every reading carries its own stamp. */
|
|
307
|
+
rate?: number
|
|
308
|
+
/** The convention it follows — `sensor_msgs/Imu`, `sensor_msgs/JointState`, `axon/contact`. A join key, never validated. */
|
|
309
|
+
profile?: string
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Measured quantities: an IMU, contact, joint angles, hunger, a GNSS fix. */
|
|
313
|
+
export type VectorSense = SenseBase & {
|
|
314
|
+
kind: "vector"
|
|
315
|
+
components: Component[]
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** A picture: its size, how it lies on the world, and what each pixel measures. */
|
|
319
|
+
export type VisualSense = SenseBase & {
|
|
320
|
+
kind: "visual"
|
|
321
|
+
width: number
|
|
322
|
+
height: number
|
|
323
|
+
lens: Lens
|
|
324
|
+
pixel: Pixel
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* How a picture lies on the world, in the sense's frame.
|
|
329
|
+
*
|
|
330
|
+
* perspective a pinhole (ROS CameraInfo): `focal` lengths and the
|
|
331
|
+
* optical `centre`, px, and the lens's distortion when it
|
|
332
|
+
* has any. Its optical frame is `rdf`.
|
|
333
|
+
* orthographic `scale` metres of world a pixel — a side-on game's camera.
|
|
334
|
+
* polar a scanner, or a camera that sees all round: each column a
|
|
335
|
+
* direction about the frame's z, `from` to `to` rad; each
|
|
336
|
+
* row an elevation, rad, top row first — evenly `from` `to`,
|
|
337
|
+
* or each row's own (a 3D lidar's beams are uneven). A 2D
|
|
338
|
+
* lidar is one row at elevation 0.
|
|
339
|
+
*/
|
|
340
|
+
export type Lens =
|
|
341
|
+
| { kind: "perspective"; focal: [number, number]; centre: [number, number]; distortion?: Distortion }
|
|
342
|
+
| { kind: "orthographic"; scale: number }
|
|
343
|
+
| { kind: "polar"; from: number; to: number; elevation: { from: number; to: number } | number[] }
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* A lens's distortion, as ROS's camera models give it: `plumb_bob` (k1 k2 p1
|
|
347
|
+
* p2 k3), `rational_polynomial` (k1 k2 p1 p2 k3 k4 k5 k6), `equidistant` — a
|
|
348
|
+
* fisheye — (k1 k2 k3 k4).
|
|
349
|
+
*/
|
|
350
|
+
export type Distortion = { model: "plumb_bob" | "rational_polynomial" | "equidistant"; coefficients: number[] }
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* What one pixel measures.
|
|
354
|
+
*
|
|
355
|
+
* colour light, as seen
|
|
356
|
+
* depth how far what it sees is — along the camera's z for a
|
|
357
|
+
* perspective lens (ROS depth images), along the ray for a polar
|
|
358
|
+
* one — m, up to `range`; 0 where nothing was met
|
|
359
|
+
* measure one quantity in `unit`: a thermal camera's K, a lidar's return
|
|
360
|
+
* intensity
|
|
361
|
+
*/
|
|
362
|
+
export type Pixel = { kind: "colour" } | { kind: "depth"; range: number } | { kind: "measure"; unit: string; range?: [number, number] }
|
|
363
|
+
|
|
364
|
+
export type AudioSense = SenseBase & {
|
|
365
|
+
kind: "audio"
|
|
366
|
+
/** samples a second */
|
|
367
|
+
sampleRate: number
|
|
368
|
+
channels: number
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Words the body hears or reads — a terminal's output — or, with `format`
|
|
373
|
+
* `json`, a reading of a shape the body declares in `schema`: things of no
|
|
374
|
+
* fixed number (what is detected, who is near, what the hands hold), and
|
|
375
|
+
* chat with who said it. Either way it reaches the mind as text, which is
|
|
376
|
+
* what symbols are.
|
|
377
|
+
*/
|
|
378
|
+
export type TextSense = SenseBase & {
|
|
379
|
+
kind: "text"
|
|
380
|
+
format?: "json"
|
|
381
|
+
/** JSON Schema of every reading's text, parsed; only with `format` `json`. */
|
|
382
|
+
schema?: object
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// ── controls ──────────────────────────────────────────────────────────────
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* One stream of acts, on the channel the mind outputs on. The mirror of a
|
|
389
|
+
* Sense: a vector control moves something, a text control says something (a
|
|
390
|
+
* chat line), an audio control sounds something.
|
|
391
|
+
*/
|
|
392
|
+
export type Control = VectorControl | TextControl | AudioControl
|
|
393
|
+
|
|
394
|
+
type ControlBase = {
|
|
395
|
+
channel: string
|
|
396
|
+
profile?: string
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Something driven: a command sets every component at once, in declared order
|
|
401
|
+
* — one act, not several.
|
|
402
|
+
*/
|
|
403
|
+
export type VectorControl = ControlBase & {
|
|
404
|
+
kind: "vector"
|
|
405
|
+
/** Whose axes it is given in: a body frame, or a place — a drone told a velocity over the ground. */
|
|
406
|
+
frame?: string
|
|
407
|
+
components: ControlComponent[]
|
|
408
|
+
lapse: Lapse
|
|
409
|
+
/** How often the body reads it: commands sent faster are superseded unseen. */
|
|
410
|
+
rate?: number
|
|
411
|
+
/**
|
|
412
|
+
* It takes commands planned ahead — up to `points` timed points, each
|
|
413
|
+
* applied at its time on the body's clock, `step` held until the next or
|
|
414
|
+
* `linear` moved towards it. A rover's drive sequence, an arm's
|
|
415
|
+
* trajectory. The lapse counts from the last point.
|
|
416
|
+
*/
|
|
417
|
+
trajectory?: { points: number; interpolation: "step" | "linear" }
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* What the body does when the mind stops saying — a command's time runs out,
|
|
422
|
+
* the connection drops, the lease ends.
|
|
423
|
+
*
|
|
424
|
+
* release `after` ms without a command, every component is let go: a
|
|
425
|
+
* switch off; an axis, velocity or effort zero; a position no
|
|
426
|
+
* longer held, so the joint goes limp. Legs, wheels.
|
|
427
|
+
* keep the last command stays applied until the next. Only for
|
|
428
|
+
* targets — a position, a choice — never a velocity or effort,
|
|
429
|
+
* which run away left applied.
|
|
430
|
+
* behaviour `after` ms without a command, the body takes over with a
|
|
431
|
+
* behaviour of its own until commanded again: a drone hovers
|
|
432
|
+
* then lands, a car brakes to a stop.
|
|
433
|
+
*/
|
|
434
|
+
export type Lapse =
|
|
435
|
+
| { kind: "release"; after: number }
|
|
436
|
+
| { kind: "keep" }
|
|
437
|
+
| { kind: "behaviour"; after: number; name: string; describe: string }
|
|
438
|
+
|
|
439
|
+
/** Words the body says or types: a chat line, keystrokes into a terminal. */
|
|
440
|
+
export type TextControl = ControlBase & {
|
|
441
|
+
kind: "text"
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** Sound the body makes. */
|
|
445
|
+
export type AudioControl = ControlBase & {
|
|
446
|
+
kind: "audio"
|
|
447
|
+
sampleRate: number
|
|
448
|
+
channels: number
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export type ControlComponent = Component & {
|
|
452
|
+
interface: Interface
|
|
453
|
+
/** The joint it drives, when it drives one — by the name of the FRAME it moves (as a mimic names its leader), so nothing depends on order. */
|
|
454
|
+
joint?: string
|
|
455
|
+
/** The most it may change in a second, in its unit per second — an acceleration limit on a velocity. The body clamps it. */
|
|
456
|
+
slew?: number
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* How a component is driven (ros2_control's command interfaces):
|
|
461
|
+
*
|
|
462
|
+
* switch on or off — a key
|
|
463
|
+
* axis −1..1 — a stick
|
|
464
|
+
* choice one of the component's `categories`, by index — a gear
|
|
465
|
+
* position driven to a target, in its unit
|
|
466
|
+
* velocity driven at a speed, in its unit
|
|
467
|
+
* effort driven with a force or torque, in its unit
|
|
468
|
+
*/
|
|
469
|
+
export type Interface = "switch" | "axis" | "choice" | "position" | "velocity" | "effort"
|
|
470
|
+
|
|
471
|
+
// ── skills ────────────────────────────────────────────────────────────────
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Something the body can be asked to do, that answers (ROS: an action) —
|
|
475
|
+
* `craft`, `navigate_to`, `exec`. Asked through `run()`, so it passes the
|
|
476
|
+
* policy check like every other request.
|
|
477
|
+
*
|
|
478
|
+
* Seen this way, the TypeScript and bash a coding agent runs today are the
|
|
479
|
+
* Linux machine's skills: the agent already wears the machine as a body.
|
|
480
|
+
*/
|
|
481
|
+
export type Skill = {
|
|
482
|
+
name: string
|
|
483
|
+
/** What it does — for a person, or a model choosing a skill. */
|
|
484
|
+
describe: string
|
|
485
|
+
/** JSON Schema of what it is asked with. */
|
|
486
|
+
args: object
|
|
487
|
+
/** JSON Schema of what it answers. */
|
|
488
|
+
result: object
|
|
489
|
+
cancellable: boolean
|
|
490
|
+
/** The longest it takes before the body itself gives up, ms. */
|
|
491
|
+
within: number
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
495
|
+
// 2. FROM THE BODY — what a body says while worn
|
|
496
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
497
|
+
|
|
498
|
+
export type FromBody = ManifestMessage | Reading | Truth | Applied | SkillUpdate | Presence | Waiting
|
|
499
|
+
|
|
500
|
+
export type ManifestMessage = {
|
|
501
|
+
type: "manifest"
|
|
502
|
+
manifest: Manifest
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* One reading of one sense: it becomes the stimulus its Sense declared. A
|
|
507
|
+
* vector sense sends `values`, in its components' order; a camera or
|
|
508
|
+
* microphone sends a `ref` to the bytes; a text sense sends `text` — JSON of
|
|
509
|
+
* its schema, when its format is `json`.
|
|
510
|
+
*/
|
|
511
|
+
export type Reading = {
|
|
512
|
+
type: "reading"
|
|
513
|
+
channel: string
|
|
514
|
+
/** Counts this channel's readings, so a gap is visible. */
|
|
515
|
+
seq: number
|
|
516
|
+
/** When it was sensed, on the body's clock. */
|
|
517
|
+
sensed: number
|
|
518
|
+
values?: number[]
|
|
519
|
+
ref?: Ref
|
|
520
|
+
text?: string
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** Bytes too large to carry — a picture, a stretch of sound — and where they are. */
|
|
524
|
+
export type Ref = {
|
|
525
|
+
uri: string
|
|
526
|
+
mime: string
|
|
527
|
+
bytes?: number
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* The world's answer key: what is true, that the body does not sense — true
|
|
532
|
+
* position, true velocity, health. Recorded beside the session for scoring,
|
|
533
|
+
* NEVER delivered to the mind.
|
|
534
|
+
*/
|
|
535
|
+
export type Truth = {
|
|
536
|
+
type: "truth"
|
|
537
|
+
sensed: number
|
|
538
|
+
values: number[]
|
|
539
|
+
components: Component[]
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* A command took effect — the other end of a command's `basis` — and what
|
|
544
|
+
* took effect: after the body's limits, a vector control's `values` are what
|
|
545
|
+
* the body actually did, so a mind whose command was clamped learns it.
|
|
546
|
+
*/
|
|
547
|
+
export type Applied = {
|
|
548
|
+
type: "applied"
|
|
549
|
+
channel: string
|
|
550
|
+
/** The command's own seq. */
|
|
551
|
+
seq: number
|
|
552
|
+
/** Which of a trajectory's points; absent for a command of one. */
|
|
553
|
+
point?: number
|
|
554
|
+
/** When it took effect, on the body's clock. */
|
|
555
|
+
sensed: number
|
|
556
|
+
/** A vector control's components as applied, in declared order. */
|
|
557
|
+
values?: number[]
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export type SkillUpdate = {
|
|
561
|
+
type: "skill"
|
|
562
|
+
/** The id the mind asked with. */
|
|
563
|
+
id: string
|
|
564
|
+
state: "running" | "succeeded" | "failed" | "cancelled"
|
|
565
|
+
progress?: unknown
|
|
566
|
+
result?: unknown
|
|
567
|
+
error?: string
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Whether the body is the mind's to move.
|
|
572
|
+
*
|
|
573
|
+
* embodied in the world: it senses, and commands act
|
|
574
|
+
* held it senses, but holds itself and acts on nothing — an
|
|
575
|
+
* emergency stop, a safe mode, a rover asleep through the night
|
|
576
|
+
* overridden it senses, but someone else drives it — a safety driver, a
|
|
577
|
+
* person with the controller. Commands are not applied.
|
|
578
|
+
* detached not in any world: it neither senses nor acts
|
|
579
|
+
*
|
|
580
|
+
* `why` is said for every state but embodied.
|
|
581
|
+
*/
|
|
582
|
+
export type Presence =
|
|
583
|
+
| { type: "presence"; state: "embodied" }
|
|
584
|
+
| { type: "presence"; state: "held" | "overridden"; why: string }
|
|
585
|
+
| { type: "presence"; state: "detached"; why: string }
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* A stepped body has said everything it sensed up to `sensed`, and waits for
|
|
589
|
+
* a Step. Only from a body whose pace is `stepped`.
|
|
590
|
+
*/
|
|
591
|
+
export type Waiting = {
|
|
592
|
+
type: "waiting"
|
|
593
|
+
sensed: number
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
597
|
+
// 3. TO THE BODY — what a mind says
|
|
598
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
599
|
+
|
|
600
|
+
export type ToBody = Command | SkillRequest | SkillCancel | Step
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* One act on one Control — sent by `output()`. A vector control takes
|
|
604
|
+
* `values`, every component at once, or — when it takes trajectories — a
|
|
605
|
+
* `trajectory` of timed points; text, `text`; audio, a `ref`.
|
|
606
|
+
*/
|
|
607
|
+
export type Command = {
|
|
608
|
+
type: "command"
|
|
609
|
+
channel: string
|
|
610
|
+
seq: number
|
|
611
|
+
values?: number[]
|
|
612
|
+
/** Points in order of `at`, on the body's clock; it replaces whatever plan the control was following. */
|
|
613
|
+
trajectory?: { at: number; values: number[] }[]
|
|
614
|
+
text?: string
|
|
615
|
+
ref?: Ref
|
|
616
|
+
/**
|
|
617
|
+
* The `sensed` stamp of the newest reading this was decided on. With the
|
|
618
|
+
* body's `applied`, it closes the loop: sensed → decided → applied, the
|
|
619
|
+
* latency of acting on what was sensed.
|
|
620
|
+
*/
|
|
621
|
+
basis?: number
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** Asked by `run()`, after the policy check. */
|
|
625
|
+
export type SkillRequest = {
|
|
626
|
+
type: "skill"
|
|
627
|
+
id: string
|
|
628
|
+
name: string
|
|
629
|
+
args: unknown
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export type SkillCancel = {
|
|
633
|
+
type: "cancel"
|
|
634
|
+
id: string
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** Advance a stepped body `steps` steps. Only to a body whose pace is `stepped`. */
|
|
638
|
+
export type Step = {
|
|
639
|
+
type: "step"
|
|
640
|
+
steps: number
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
644
|
+
// 4. OPEN — to settle before /1 is final
|
|
645
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
646
|
+
//
|
|
647
|
+
// · How the Manifest reaches a cognet. Stimulus kinds are closed and a
|
|
648
|
+
// manifest is not a sense — it is self-knowledge. A kernel fact a cognet
|
|
649
|
+
// reads, like its scope, rather than a stimulus?
|
|
650
|
+
// · Minecraft's neck: declared as joints; whether a JointState sense reports
|
|
651
|
+
// them (proprioception, as a robot's encoders do) or they stay truth (as
|
|
652
|
+
// today, known only through the gyro and what was sent) is the lab's call.
|
|
653
|
+
// · What `run()` carries for a skill: today it carries TypeScript source; a
|
|
654
|
+
// skill is `{ skill, args }`, and the policy check would need both.
|
|
655
|
+
// · Skills against controls: whether a skill may run while the mind drives
|
|
656
|
+
// the same parts (navigate_to and /cmd_vel), and which wins. And whether a
|
|
657
|
+
// skill can be unavailable for now (crafting with no table near).
|
|
658
|
+
// · Media transport: refs today point at shared memory and files the daemon
|
|
659
|
+
// sets up. A remote robot shares no memory with the mind; a link to Mars
|
|
660
|
+
// is minutes long and narrow, and stores what it cannot send.
|
|
661
|
+
// · Noise that changes reading by reading (a GNSS fix's accuracy), and
|
|
662
|
+
// where each of a microphone array's channels sits.
|
|
663
|
+
// · Rates: may a mind ask a body for a different rate, or is declared final?
|
|
664
|
+
// · Truth's frame: true position is in some world frame; truth should name
|
|
665
|
+
// which of the body's places.
|
|
666
|
+
// · Bodies that are not rigid links — a tentacle, cloth — are not described.
|
|
667
|
+
|
|
668
|
+
type Vec3 = [number, number, number]
|
|
669
|
+
type Quat = [number, number, number, number]
|