@driftengine/script 3.61.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 +202 -0
- package/NOTICE +9 -0
- package/README.md +81 -0
- package/dist/bindings/ai.d.ts +66 -0
- package/dist/bindings/ai.js +173 -0
- package/dist/bindings/animation.d.ts +13 -0
- package/dist/bindings/animation.js +177 -0
- package/dist/bindings/audio.d.ts +56 -0
- package/dist/bindings/audio.js +126 -0
- package/dist/bindings/behavior.d.ts +36 -0
- package/dist/bindings/behavior.js +101 -0
- package/dist/bindings/chemistry.d.ts +72 -0
- package/dist/bindings/chemistry.js +253 -0
- package/dist/bindings/core.d.ts +172 -0
- package/dist/bindings/core.js +814 -0
- package/dist/bindings/editor.d.ts +53 -0
- package/dist/bindings/editor.js +248 -0
- package/dist/bindings/entities.d.ts +73 -0
- package/dist/bindings/entities.js +339 -0
- package/dist/bindings/interface.d.ts +55 -0
- package/dist/bindings/interface.js +200 -0
- package/dist/bindings/navigation.d.ts +36 -0
- package/dist/bindings/navigation.js +255 -0
- package/dist/bindings/network.d.ts +51 -0
- package/dist/bindings/network.js +96 -0
- package/dist/bindings/render.d.ts +71 -0
- package/dist/bindings/render.js +143 -0
- package/dist/bindings/rollback.d.ts +41 -0
- package/dist/bindings/rollback.js +74 -0
- package/dist/bindings/sprites.d.ts +53 -0
- package/dist/bindings/sprites.js +186 -0
- package/dist/bindings/terrain.d.ts +54 -0
- package/dist/bindings/terrain.js +138 -0
- package/dist/bindings/xr.d.ts +56 -0
- package/dist/bindings/xr.js +155 -0
- package/dist/entityHost.d.ts +80 -0
- package/dist/entityHost.js +159 -0
- package/dist/host.d.ts +153 -0
- package/dist/host.js +233 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +18 -0
- package/package.json +68 -0
- package/src/bindings/ai.ts +306 -0
- package/src/bindings/animation.ts +346 -0
- package/src/bindings/audio.ts +185 -0
- package/src/bindings/behavior.ts +181 -0
- package/src/bindings/chemistry.ts +548 -0
- package/src/bindings/core.ts +1604 -0
- package/src/bindings/editor.ts +393 -0
- package/src/bindings/entities.ts +550 -0
- package/src/bindings/interface.ts +300 -0
- package/src/bindings/navigation.ts +367 -0
- package/src/bindings/network.ts +178 -0
- package/src/bindings/render.ts +191 -0
- package/src/bindings/rollback.ts +110 -0
- package/src/bindings/sprites.ts +310 -0
- package/src/bindings/terrain.ts +180 -0
- package/src/bindings/xr.ts +272 -0
- package/src/entityHost.ts +219 -0
- package/src/host.ts +465 -0
- package/src/index.ts +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Drift Technologies
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
DriftEngine
|
|
2
|
+
Copyright 2026 Drift Technologies
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Drift Technologies
|
|
5
|
+
(https://github.com/drftrun/driftengine).
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0. Section 4(d) of that licence
|
|
8
|
+
requires this NOTICE to be reproduced in any derivative work you distribute,
|
|
9
|
+
in the source, the documentation, or a display generated by the work.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @driftengine/script
|
|
2
|
+
|
|
3
|
+
The `drift/*` capability bindings: what this engine provides to DriftScript, and **the only place the
|
|
4
|
+
two are coupled**.
|
|
5
|
+
|
|
6
|
+
**Cost: 36.7 KB gzipped on top of core.** Measured by `scripts/size-gate.test.mjs`, which fails if it
|
|
7
|
+
drifts more than 3% — the number is derived from the same floors that gate asserts, so a README
|
|
8
|
+
quoting a stale one is a red suite rather than a thing somebody notices.
|
|
9
|
+
|
|
10
|
+
## What it is
|
|
11
|
+
|
|
12
|
+
[`driftscript`](https://www.npmjs.com/package/driftscript) is a language and knows nothing about this engine: no
|
|
13
|
+
scene, no mesh, no mix bus. This package is the other half — it describes each engine subsystem as
|
|
14
|
+
capabilities a script may call, and supplies the implementations at link time.
|
|
15
|
+
|
|
16
|
+
Twelve modules are bound: `drift/animation`, `audio`, `camera`, `ecs`, `events`, `input`,
|
|
17
|
+
`persistence`, `physics`, `prefab`, `random`, `scene` and `time`. **`drift/core` is deliberately
|
|
18
|
+
unbound**, because its provider is `startLoop`, which drives a script rather than being called by
|
|
19
|
+
one.
|
|
20
|
+
|
|
21
|
+
**Four of `drift/ecs`'s capabilities are ones nobody writes by hand.** `query`, `next`, `view` and
|
|
22
|
+
`without` are what a `for … in query<…>()` loop compiles to, so their documentation describes the
|
|
23
|
+
shape of generated code rather than how to call them. They are capabilities rather than a second
|
|
24
|
+
bind hook, so generated code reaches them exactly as it reaches everything else.
|
|
25
|
+
|
|
26
|
+
`registerEntityModule` turns a compiled module's declarations into the engine's own objects — a
|
|
27
|
+
`ComponentType` per component, a `Prefab` per prefab, a `SystemDefinition` per system — and
|
|
28
|
+
`assertHostShapes` checks every `component X from host` against what this host registered.
|
|
29
|
+
|
|
30
|
+
## Reaching this package from a bundler config — you cannot, and do not need to
|
|
31
|
+
|
|
32
|
+
**`import { engineRegistry } from '@driftengine/script'` fails inside a `vite.config.ts`**, with
|
|
33
|
+
`ERR_MODULE_NOT_FOUND` on a path like `@driftengine/audio/src/registry`. A bundler config is loaded
|
|
34
|
+
by Node; engine packages use extensionless relative imports that only a bundler resolves. That is
|
|
35
|
+
this engine's module layout and not a bug in the config.
|
|
36
|
+
|
|
37
|
+
Pass the **data** instead. This package ships it:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { fileURLToPath } from 'node:url';
|
|
41
|
+
import { driftScript } from 'driftscript/vite';
|
|
42
|
+
|
|
43
|
+
driftScript({
|
|
44
|
+
capabilities: fileURLToPath(import.meta.resolve('@driftengine/script/capabilities.json')),
|
|
45
|
+
manifest: { name: 'my-game', provides: ['drift/ecs', 'drift/audio'] },
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`capabilities.json` is regenerated by `npm run capabilities` and gated by `npm run
|
|
50
|
+
capabilities:check`, so it cannot drift from the bindings above it. The DriftScript language server
|
|
51
|
+
reads the same file for the same reason — see the next section for why a registry can cross a
|
|
52
|
+
process boundary at all.
|
|
53
|
+
|
|
54
|
+
## The registry describes and never invokes
|
|
55
|
+
|
|
56
|
+
A definition names its implementation as a **string**. The host supplies the functions when a module
|
|
57
|
+
links. That is what keeps the language package host-neutral, and it is also what lets the language
|
|
58
|
+
server read `capabilities.json` in a process that cannot import this engine at all.
|
|
59
|
+
|
|
60
|
+
## Adding a binding
|
|
61
|
+
|
|
62
|
+
The five steps are at the top of [`src/host.ts`](src/host.ts), beside the code that does them. Two of
|
|
63
|
+
them are the ones that get missed:
|
|
64
|
+
|
|
65
|
+
**A capability that lands unbound is one DriftScript cannot reach, and nothing fails to say so.** The
|
|
66
|
+
linker refuses an unbound module by naming the track it waits on — so a script author hits a refusal
|
|
67
|
+
that reads exactly like a track that has not shipped, and concludes it has not. The capability
|
|
68
|
+
exists, is finished, is tested, and is unreachable.
|
|
69
|
+
|
|
70
|
+
**Check whether an optional parameter must become required at the language boundary.** A TypeScript
|
|
71
|
+
signature may make one optional because its caller has the context to know when to pass it. A script
|
|
72
|
+
author is further from the subsystem, meets the trap first, and gets a wrong _result_ rather than an
|
|
73
|
+
error. `src/bindings/animation.ts` is the worked example.
|
|
74
|
+
|
|
75
|
+
**Write a binding from the source, never from a description of it.** Two were written from a
|
|
76
|
+
paraphrase and both were wrong — one named two methods the class does not have, reached through an
|
|
77
|
+
optional-call cast, so a script calling it compiled, linked, ran and did nothing. `src/host.test.ts`
|
|
78
|
+
now refuses `?.(` and `as unknown as` anywhere under `bindings/`.
|
|
79
|
+
|
|
80
|
+
Part of [DriftEngine](../../README.md). See [`docs/ARCHITECTURE.md`](../../docs/ARCHITECTURE.md)
|
|
81
|
+
for how the packages divide, and why some features are compiled into core on demand instead.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `drift/ai` — what this engine lets a script ask of an agent.
|
|
3
|
+
*
|
|
4
|
+
* **Deliberately small, and deliberately not a way to call a model.** A script wakes an
|
|
5
|
+
* agent, asks it to consider, and reads what it is doing. It never awaits a provider,
|
|
6
|
+
* because a script that could would be a script that can stall a fixed step for five
|
|
7
|
+
* seconds — and the whole of Track O is the argument that nothing should.
|
|
8
|
+
*
|
|
9
|
+
* Three constraints this surface inherits:
|
|
10
|
+
*
|
|
11
|
+
* - **`ai` is outside the determinism boundary.** A `@deterministic` function may not
|
|
12
|
+
* call any of it. The floor is deterministic and runs inside the simulation; asking a
|
|
13
|
+
* provider is not, and the compiler is making a line that already exists visible.
|
|
14
|
+
* - **Nothing here returns a model's answer.** `wake` and `consider` are requests that
|
|
15
|
+
* an agent think, and they return immediately. What the agent decided arrives as the
|
|
16
|
+
* intent its session hands the consumer on a later tick.
|
|
17
|
+
* - **Reading is cheap and stays inside the boundary.** `intentId` and `degraded` are
|
|
18
|
+
* `@deterministic`-safe: the current intent is state the simulation already owns,
|
|
19
|
+
* because a deterministic floor put it there and a replay recomputes it.
|
|
20
|
+
*/
|
|
21
|
+
import { type CapabilityDefinition, type OpaqueType } from 'driftscript';
|
|
22
|
+
import type { AgentSession, NavigateArgs, NavigateResult, ToolDefinition } from '@driftengine/ai';
|
|
23
|
+
import type { NavPath } from '@driftengine/core';
|
|
24
|
+
export declare const AI_MODULE = "drift/ai";
|
|
25
|
+
/**
|
|
26
|
+
* A live agent session, held by a script and passed back to the engine.
|
|
27
|
+
*
|
|
28
|
+
* Opaque, for the reason `Sound` is: a script that could read its fields would be a
|
|
29
|
+
* script depending on a representation this package cannot then change.
|
|
30
|
+
*/
|
|
31
|
+
export declare const AI_TYPES: readonly OpaqueType[];
|
|
32
|
+
export declare const AI_CAPABILITIES: readonly CapabilityDefinition[];
|
|
33
|
+
/**
|
|
34
|
+
* A consumer's agents, by the id a script may name them with.
|
|
35
|
+
*
|
|
36
|
+
* The registry is the consumer's, exactly as `SoundRegistry` is: this package owns the
|
|
37
|
+
* loop and the floor, and which agents exist in a scene is not something an engine can
|
|
38
|
+
* know.
|
|
39
|
+
*/
|
|
40
|
+
export interface AgentRegistry {
|
|
41
|
+
get(id: string): AgentSession | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* What the navigation bridge needs from the host to answer for an agent.
|
|
45
|
+
*
|
|
46
|
+
* The world and the tools are the consumer's: `navigationBridge` is a factory over their adapter,
|
|
47
|
+
* and this is where the result of that factory meets a script.
|
|
48
|
+
*/
|
|
49
|
+
export interface AgentNavigation<W = unknown> {
|
|
50
|
+
readonly world: W;
|
|
51
|
+
readonly tools: readonly ToolDefinition<NavigateArgs, NavigateResult, W>[];
|
|
52
|
+
pathOf(agentId: string): NavPath | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** Which agents this peer decides for. One method, because that is the whole script-visible fact. */
|
|
55
|
+
export interface AgentAuthority {
|
|
56
|
+
deciding(agentId: string): boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface AiServices<W = unknown> {
|
|
59
|
+
readonly agents: AgentRegistry;
|
|
60
|
+
/** Absent means `reachable`, `navigate` and `path` fail at the call saying what to provide. */
|
|
61
|
+
readonly navigation?: AgentNavigation<W>;
|
|
62
|
+
/** Absent means `deciding` fails at the call. */
|
|
63
|
+
readonly authority?: AgentAuthority;
|
|
64
|
+
}
|
|
65
|
+
/** The implementations the host supplies at link time, keyed by capability name. */
|
|
66
|
+
export declare function aiImplementation(services: AiServices): Readonly<Record<string, unknown>>;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `drift/ai` — what this engine lets a script ask of an agent.
|
|
3
|
+
*
|
|
4
|
+
* **Deliberately small, and deliberately not a way to call a model.** A script wakes an
|
|
5
|
+
* agent, asks it to consider, and reads what it is doing. It never awaits a provider,
|
|
6
|
+
* because a script that could would be a script that can stall a fixed step for five
|
|
7
|
+
* seconds — and the whole of Track O is the argument that nothing should.
|
|
8
|
+
*
|
|
9
|
+
* Three constraints this surface inherits:
|
|
10
|
+
*
|
|
11
|
+
* - **`ai` is outside the determinism boundary.** A `@deterministic` function may not
|
|
12
|
+
* call any of it. The floor is deterministic and runs inside the simulation; asking a
|
|
13
|
+
* provider is not, and the compiler is making a line that already exists visible.
|
|
14
|
+
* - **Nothing here returns a model's answer.** `wake` and `consider` are requests that
|
|
15
|
+
* an agent think, and they return immediately. What the agent decided arrives as the
|
|
16
|
+
* intent its session hands the consumer on a later tick.
|
|
17
|
+
* - **Reading is cheap and stays inside the boundary.** `intentId` and `degraded` are
|
|
18
|
+
* `@deterministic`-safe: the current intent is state the simulation already owns,
|
|
19
|
+
* because a deterministic floor put it there and a replay recomputes it.
|
|
20
|
+
*/
|
|
21
|
+
import { defineCapability } from 'driftscript';
|
|
22
|
+
export const AI_MODULE = 'drift/ai';
|
|
23
|
+
/**
|
|
24
|
+
* A live agent session, held by a script and passed back to the engine.
|
|
25
|
+
*
|
|
26
|
+
* Opaque, for the reason `Sound` is: a script that could read its fields would be a
|
|
27
|
+
* script depending on a representation this package cannot then change.
|
|
28
|
+
*/
|
|
29
|
+
export const AI_TYPES = [
|
|
30
|
+
{
|
|
31
|
+
module: AI_MODULE,
|
|
32
|
+
name: 'Agent',
|
|
33
|
+
doc: 'A live agent session. Held and passed back; never read into.',
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
const define = (name, params, returns, effects, deterministic, doc, implementation) => defineCapability({
|
|
37
|
+
module: AI_MODULE,
|
|
38
|
+
name,
|
|
39
|
+
signature: `fn(${params.map((p) => `${p.name}: ${p.type}`).join(', ')}) -> ${returns}`,
|
|
40
|
+
params: [...params],
|
|
41
|
+
returns,
|
|
42
|
+
effects,
|
|
43
|
+
deterministic,
|
|
44
|
+
doc,
|
|
45
|
+
implementation,
|
|
46
|
+
});
|
|
47
|
+
export const AI_CAPABILITIES = [
|
|
48
|
+
define('agent', [{ name: 'id', type: 'String' }],
|
|
49
|
+
/*
|
|
50
|
+
* `Agent?`, and the `?` is the point, exactly as it is for `audio.sound`.
|
|
51
|
+
*
|
|
52
|
+
* A consumer registers the agents a script may talk to, and a script naming one
|
|
53
|
+
* that was not registered is ordinary rather than exceptional — a scene loaded
|
|
54
|
+
* without its agents, a name that moved. Returning a bare `Agent` would make every
|
|
55
|
+
* script that forgot to check talk to nothing and report success.
|
|
56
|
+
*/
|
|
57
|
+
'Agent?', ['pure'], true, 'Resolve an agent by the id the consumer registered it under. Absent when there is none.', 'AgentRegistry.get'),
|
|
58
|
+
define('wake', [
|
|
59
|
+
{ name: 'agent', type: 'Agent' },
|
|
60
|
+
{ name: 'reason', type: 'String' },
|
|
61
|
+
{ name: 'priority', type: 'i32' },
|
|
62
|
+
], 'void', ['ai'], false, 'Tell an agent something happened. Returns immediately; the agent acts at its next tick.', 'AgentSession.observe'),
|
|
63
|
+
define('consider', [{ name: 'agent', type: 'Agent' }], 'void', ['ai'], false, 'Ask an agent to think, at ordinary priority. Returns immediately.', 'AgentSession.consider'),
|
|
64
|
+
define('intentId', [{ name: 'agent', type: 'Agent' }], 'String', ['pure'],
|
|
65
|
+
/*
|
|
66
|
+
* Readable from a `@deterministic` function, unlike everything else here.
|
|
67
|
+
*
|
|
68
|
+
* The current intent is state the simulation already owns — the floor put it there
|
|
69
|
+
* and a replay recomputes it — so reading it is reading the simulation rather than
|
|
70
|
+
* reaching outside it. Asking a provider is the part that is nondeterministic, and
|
|
71
|
+
* that is what `wake` and `consider` carry `ai` for.
|
|
72
|
+
*/
|
|
73
|
+
true, 'What the agent is doing now. Empty before its first tick.', 'AgentSession.intentId'),
|
|
74
|
+
define('degraded', [{ name: 'agent', type: 'Agent' }], 'bool', ['pure'], true, 'Whether the agent is over budget and running on its policy floor alone.', 'AgentSession.degraded'),
|
|
75
|
+
/*
|
|
76
|
+
* The two bridges, and every effect below is inherited rather than invented.
|
|
77
|
+
*
|
|
78
|
+
* **None of these duplicates `drift/navigation`.** That module binds twelve capabilities and
|
|
79
|
+
* every one takes a `NavPath` or a `NavGraph`; what a script could not do is aim any of them at
|
|
80
|
+
* an `Agent`, which is a session keyed by an id the consumer registered. `path` is the join, so
|
|
81
|
+
* one capability makes all twelve work on an agent instead of any being bound a second time.
|
|
82
|
+
*/
|
|
83
|
+
define('reachable', [
|
|
84
|
+
{ name: 'agent', type: 'Agent' },
|
|
85
|
+
{ name: 'x', type: 'float' },
|
|
86
|
+
{ name: 'y', type: 'float' },
|
|
87
|
+
{ name: 'z', type: 'float' },
|
|
88
|
+
], 'bool', ['navigation.read'],
|
|
89
|
+
/*
|
|
90
|
+
* Deterministic, and it is the admission guard as a question. `navigation.route` computes *and
|
|
91
|
+
* writes*, so a script wanting to score a destination before committing to it had to route and
|
|
92
|
+
* then undo — which is a write a `@deterministic` system would have had to make and take back.
|
|
93
|
+
*/
|
|
94
|
+
true, 'Whether a route exists from where this agent is to a point, without writing one.', 'navigationBridge.admits'),
|
|
95
|
+
define('navigate', [
|
|
96
|
+
{ name: 'agent', type: 'Agent' },
|
|
97
|
+
{ name: 'x', type: 'float' },
|
|
98
|
+
{ name: 'y', type: 'float' },
|
|
99
|
+
{ name: 'z', type: 'float' },
|
|
100
|
+
], 'bool', ['navigation.write'],
|
|
101
|
+
/*
|
|
102
|
+
* **Deterministic, and safe on every peer, which only looks like it contradicts `deciding`.**
|
|
103
|
+
* The authority rule is about *model*-authored intents: a provider is nondeterministic, slow
|
|
104
|
+
* and metered, so two peers running one diverge. A script's own command is a function of the
|
|
105
|
+
* simulation — DriftScript 1.12.0 admitted `navigation.write` to `DETERMINISTIC_EFFECTS` on
|
|
106
|
+
* exactly that argument, since a route is a function of the graph and two endpoints and
|
|
107
|
+
* `navSearch` breaks ties on the node index — so every peer computes the same route and it
|
|
108
|
+
* replicates itself by being re-run.
|
|
109
|
+
*/
|
|
110
|
+
true, 'Route this agent to a point. False when no route exists, and then it clears the old one.', 'navigationBridge.execute'),
|
|
111
|
+
define('path', [{ name: 'agent', type: 'Agent' }],
|
|
112
|
+
/*
|
|
113
|
+
* `NavPath?`, from `drift/navigation`. Cross-module opaque types are ordinary here:
|
|
114
|
+
* `drift/editor.rebuildTree` takes a `drift/scene.Node` and `drift/ui.draw` takes a
|
|
115
|
+
* `drift/2d.SpriteBatch`.
|
|
116
|
+
*
|
|
117
|
+
* Optional because an agent the consumer never gave a route object to is ordinary rather than
|
|
118
|
+
* exceptional, and a bare `NavPath` would hand every script that forgot to check a handle to
|
|
119
|
+
* nothing.
|
|
120
|
+
*/
|
|
121
|
+
'NavPath?', ['navigation.read'], true, 'The route object this agent follows, for `drift/navigation` to read or steer along.', 'AgentNavigation.pathOf'),
|
|
122
|
+
define('deciding', [{ name: 'agent', type: 'Agent' }], 'bool',
|
|
123
|
+
/*
|
|
124
|
+
* `network.read`, and inside `DETERMINISTIC_EFFECTS`, on the same narrowing
|
|
125
|
+
* `drift/network.authority` already uses: which participant this is, and whether it is the
|
|
126
|
+
* authority, are facts that cannot vary with packet timing. This is that fact per agent.
|
|
127
|
+
*/
|
|
128
|
+
['network.read'], true, 'Whether this peer decides this agent’s model intents. Elsewhere they arrive already taken.', 'AuthoritativeAgent.deciding'),
|
|
129
|
+
];
|
|
130
|
+
/**
|
|
131
|
+
* Missing wiring fails at the call, naming what is absent.
|
|
132
|
+
*
|
|
133
|
+
* **Not a falsy default**, for the reason `HostServices` already gives about `drift/behavior`: a
|
|
134
|
+
* stub makes an agent whose routine never runs look exactly like one standing about with nothing to
|
|
135
|
+
* do. `navigate` returning `false` because nobody wired a bridge is indistinguishable from `false`
|
|
136
|
+
* because there is no route, and the second is a thing a script is meant to handle.
|
|
137
|
+
*/
|
|
138
|
+
function required(value, what) {
|
|
139
|
+
if (value === undefined) {
|
|
140
|
+
throw new Error(`drift/ai: this host provides no ${what}, so that capability cannot answer. Pass it in ` +
|
|
141
|
+
`\`services.ai\` — see \`navigationBridge\` in @driftengine/ai.`);
|
|
142
|
+
}
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
/** The implementations the host supplies at link time, keyed by capability name. */
|
|
146
|
+
export function aiImplementation(services) {
|
|
147
|
+
const { agents } = services;
|
|
148
|
+
const navigate = (agent, x, y, z, act) => {
|
|
149
|
+
const nav = required(services.navigation, 'navigation bridge');
|
|
150
|
+
const tool = nav.tools.find((candidate) => candidate.id === 'navigate@1');
|
|
151
|
+
if (tool === undefined)
|
|
152
|
+
return false;
|
|
153
|
+
const args = { agentId: agent.agentId, x, y, z };
|
|
154
|
+
/* `admits` is the guard and `execute` is the act, and `reachable` is deliberately the first
|
|
155
|
+
without the second — the whole point of exposing it is not having to route and undo. */
|
|
156
|
+
return act ? tool.execute(args, nav.world).found : tool.admits(args, nav.world);
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
agent: (id) => agents.get(id),
|
|
160
|
+
wake: (agent, reason, priority) => {
|
|
161
|
+
agent.observe({ id: reason, priority, text: reason });
|
|
162
|
+
},
|
|
163
|
+
consider: (agent) => {
|
|
164
|
+
agent.observe({ id: 'consider', priority: 0, text: 'consider' });
|
|
165
|
+
},
|
|
166
|
+
intentId: (agent) => agent.current?.id ?? '',
|
|
167
|
+
degraded: (agent) => agent.degraded,
|
|
168
|
+
reachable: (agent, x, y, z) => navigate(agent, x, y, z, false),
|
|
169
|
+
navigate: (agent, x, y, z) => navigate(agent, x, y, z, true),
|
|
170
|
+
path: (agent) => required(services.navigation, 'navigation bridge').pathOf(agent.agentId),
|
|
171
|
+
deciding: (agent) => required(services.authority, 'authority bridge').deciding(agent.agentId),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type CapabilityDefinition, type OpaqueType } from 'driftscript';
|
|
2
|
+
export declare const ANIMATION_MODULE = "drift/animation";
|
|
3
|
+
export declare const ANIMATION_TYPES: readonly OpaqueType[];
|
|
4
|
+
export declare const ANIMATION_CAPABILITIES: readonly CapabilityDefinition[];
|
|
5
|
+
/**
|
|
6
|
+
* The implementations.
|
|
7
|
+
*
|
|
8
|
+
* `blendTree` passes the bind pose straight through to the engine's optional parameter — the
|
|
9
|
+
* requirement lives entirely in the *description*, which is exactly where a capability boundary
|
|
10
|
+
* should hold a rule. The engine's own callers keep their option; script authors get the safe
|
|
11
|
+
* behaviour without the engine changing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function animationImplementation(): Record<string, unknown>;
|