angela-sdk 0.3.0 → 0.3.1
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/README.md +161 -7
- package/dist/cjs/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,10 @@ Angela games run as deterministic WebAssembly cartridges in Discord servers. The
|
|
|
15
15
|
3. [Architecture & How It Works](#architecture--how-it-works)
|
|
16
16
|
4. [Application Lifecycle & Event Routing](#application-lifecycle--event-routing)
|
|
17
17
|
5. [The Game Context (`ctx`)](#the-game-context-ctx)
|
|
18
|
+
- [Temporary Channels (`ctx.channel`)](#temporary-channels-ctxchannel)
|
|
19
|
+
- [Permission Overwrites (`ctx.perms`)](#channel-permissions-ctxperms)
|
|
20
|
+
- [Timers & Hibernation (`ctx.timer`)](#timers--hibernation-ctxtimer)
|
|
21
|
+
- [Persistent Player Storage & Stats (`ctx.storage`)](#persistent-player-storage--stats-ctxstorage)
|
|
18
22
|
6. [Economy & Multi-Currency System](#economy--multi-currency-system)
|
|
19
23
|
7. [Inventory & Items](#inventory--items)
|
|
20
24
|
8. [UI Engine](#ui-engine)
|
|
@@ -27,8 +31,14 @@ Angela games run as deterministic WebAssembly cartridges in Discord servers. The
|
|
|
27
31
|
- [Complete Drawing API Reference](#complete-drawing-api-reference)
|
|
28
32
|
10. [Multiplayer & Lobbies](#multiplayer--lobbies)
|
|
29
33
|
11. [AI & Media Gateways](#ai--media-gateways)
|
|
30
|
-
12. [
|
|
31
|
-
|
|
34
|
+
12. [Discord Utilities & Low-Level Primitives](#discord-utilities--low-level-primitives)
|
|
35
|
+
- [Channel Creation & Deletion (`ctx.channel`)](#channel-creation--deletion-ctxchannel)
|
|
36
|
+
- [Permission Overwrites (`ctx.perms`)](#permission-overwrites-ctxperms)
|
|
37
|
+
- [Timer Hibernation & Early Cancellation (`ctx.timer`)](#timer-hibernation--early-cancellation-ctxtimer)
|
|
38
|
+
- [Zero-DM Secret Actions & Ephemerals](#zero-dm-secret-actions--ephemerals)
|
|
39
|
+
13. [Compute Tiers & Flux Metering](#compute-tiers--flux-metering)
|
|
40
|
+
14. [HTTP & Safe Network Access](#http--safe-network-access)
|
|
41
|
+
15. [Cartridge Project Layout & CLI](#cartridge-project-layout--cli)
|
|
32
42
|
|
|
33
43
|
---
|
|
34
44
|
|
|
@@ -264,7 +274,50 @@ const maxTries = Number(ctx.config.max_tries || 3);
|
|
|
264
274
|
|
|
265
275
|
Read-only object containing private slot credentials (such as API keys). Secrets are kept private to the host and never written to game state.
|
|
266
276
|
|
|
267
|
-
###
|
|
277
|
+
### Temporary Channels (`ctx.channel`)
|
|
278
|
+
|
|
279
|
+
Control isolated game channels and private discussion threads:
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
// Create private game thread or temporary channel
|
|
283
|
+
ctx.channel.create("secret-room", {
|
|
284
|
+
type: "private_thread",
|
|
285
|
+
autoDeleteAfter: 300,
|
|
286
|
+
topic: "Secret Strategy Room"
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Delete temporary channel when match ends
|
|
290
|
+
ctx.channel.delete(123456789);
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Channel Permissions (`ctx.perms`)
|
|
294
|
+
|
|
295
|
+
Apply low-level permission overwrites dynamically:
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
// Set channel overwrites for a player
|
|
299
|
+
ctx.perms.set(ctx.user.id, {
|
|
300
|
+
allow: ["view_channel", "send_messages"],
|
|
301
|
+
deny: ["add_reactions"]
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// Freeze chat during critical turn phases
|
|
305
|
+
ctx.perms.lockChannel(30);
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Timers & Hibernation (`ctx.timer`)
|
|
309
|
+
|
|
310
|
+
Schedule asynchronous hibernation wakeups and early cancellations:
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
// Schedule hibernation wake (0 MB RAM & 0 Flux while sleeping)
|
|
314
|
+
ctx.timer.schedule(30, "on_turn_timeout", { round: 1 });
|
|
315
|
+
|
|
316
|
+
// Cancel active session wake early if all participants act
|
|
317
|
+
ctx.timer.cancel();
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Persistent Player Storage & Stats (`ctx.storage`)
|
|
268
321
|
|
|
269
322
|
Store game-scoped persistent player progress and manage cooldowns:
|
|
270
323
|
|
|
@@ -275,6 +328,10 @@ ctx.storage.set("best_score", Math.max(bestScore, currentScore));
|
|
|
275
328
|
|
|
276
329
|
// Enforce a 60-second cooldown on the player
|
|
277
330
|
ctx.storage.setCooldown(ctx.user.id, 60);
|
|
331
|
+
|
|
332
|
+
// Record persistent player gameplay statistics (safeguarded at max 50 keys, 48 chars)
|
|
333
|
+
ctx.storage.recordStat(ctx.user.id, "games_won", 1, "inc");
|
|
334
|
+
ctx.storage.recordStat(ctx.user.id, "top_score", 9990, "set");
|
|
278
335
|
```
|
|
279
336
|
|
|
280
337
|
---
|
|
@@ -701,14 +758,84 @@ To guarantee zero latency spikes, airtight security, and deterministic runs acro
|
|
|
701
758
|
|
|
702
759
|
---
|
|
703
760
|
|
|
704
|
-
## Discord Utilities
|
|
761
|
+
## Discord Utilities & Low-Level Primitives
|
|
762
|
+
|
|
763
|
+
### Channel Creation & Deletion (`ctx.channel`)
|
|
764
|
+
|
|
765
|
+
For games requiring private rooms, team discussion threads, or staged arenas:
|
|
766
|
+
|
|
767
|
+
```typescript
|
|
768
|
+
// Create a private discussion thread or temporary channel
|
|
769
|
+
ctx.channel.create("secret-room", {
|
|
770
|
+
type: "private_thread", // or "text" for temporary guild channel
|
|
771
|
+
autoDeleteAfter: 600, // Auto-cleaned after 10 minutes
|
|
772
|
+
topic: "Secret Game Room"
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
// Tear down when the round or match concludes
|
|
776
|
+
ctx.channel.delete(123456789);
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
> [!NOTE]
|
|
780
|
+
> To prevent channel clutter, servers enforce a hard quota of max 2 concurrent temporary channels per game cartridge.
|
|
781
|
+
|
|
782
|
+
### Permission Overwrites (`ctx.perms`)
|
|
705
783
|
|
|
706
|
-
|
|
784
|
+
Modify player or role channel visibility and permissions dynamically:
|
|
707
785
|
|
|
708
786
|
```typescript
|
|
709
|
-
//
|
|
710
|
-
ctx.
|
|
787
|
+
// Grant a player access to view and chat in the private room
|
|
788
|
+
ctx.perms.set(ctx.user.id, {
|
|
789
|
+
allow: ["view_channel", "send_messages", "read_message_history"],
|
|
790
|
+
deny: ["add_reactions"]
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
// Freeze channel chat during voting or turn calculations
|
|
794
|
+
ctx.perms.lockChannel(30);
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
**Allowed Overwrite Permissions**: `send_messages`, `view_channel`, `read_message_history`, `add_reactions`, `attach_files`.
|
|
798
|
+
|
|
799
|
+
### Timer Hibernation & Early Cancellation (`ctx.timer`)
|
|
800
|
+
|
|
801
|
+
For turn timeouts, phase countdowns, or scheduled events:
|
|
802
|
+
|
|
803
|
+
```typescript
|
|
804
|
+
// Hibernate cartridge for 45 seconds (0 MB RAM & 0 Flux during sleep)
|
|
805
|
+
ctx.timer.schedule(45, "on_night_timeout", {
|
|
806
|
+
phase: "night",
|
|
807
|
+
round: 2
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
// If all players submit actions before the timer expires, cancel it early:
|
|
811
|
+
if (Object.keys(ctx.state.votes || {}).length === ctx.session.participants.length) {
|
|
812
|
+
ctx.timer.cancel();
|
|
813
|
+
// Resume immediately!
|
|
814
|
+
}
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
### Zero-DM Secret Actions & Ephemerals
|
|
818
|
+
|
|
819
|
+
Angela enforces a strict **Zero-DM policy** to protect against Discord anti-spam flags, rate limits (HTTP 429), and user privacy blocks (`Cannot send messages to this user (50007)`).
|
|
820
|
+
|
|
821
|
+
Instead of bot DMs, handle secret gameplay through:
|
|
822
|
+
1. **In-Channel Ephemeral UI**:
|
|
823
|
+
```typescript
|
|
824
|
+
// Only visible to the clicking user inside the channel
|
|
825
|
+
ctx.ui.replyEphemeral({
|
|
826
|
+
text: `🤫 Your secret role is **${myRole}**!`,
|
|
827
|
+
buttons: [
|
|
828
|
+
new Button({ customId: "secret_action_1", label: "Secret Choice A", style: "danger" }),
|
|
829
|
+
new Button({ customId: "secret_action_2", label: "Secret Choice B", style: "secondary" }),
|
|
830
|
+
]
|
|
831
|
+
});
|
|
832
|
+
```
|
|
833
|
+
2. **Private Threads**:
|
|
834
|
+
Use `ctx.channel.create("game-room", { type: "private_thread" })` and invite only specific players with `ctx.perms.set()`.
|
|
711
835
|
|
|
836
|
+
### Channel Management & Chat Listening (`ctx.discord`)
|
|
837
|
+
|
|
838
|
+
```typescript
|
|
712
839
|
// Listen for chat message answers
|
|
713
840
|
ctx.discord.listenMessages({
|
|
714
841
|
exactMatch: "42",
|
|
@@ -719,6 +846,31 @@ ctx.discord.listenMessages({
|
|
|
719
846
|
|
|
720
847
|
---
|
|
721
848
|
|
|
849
|
+
## Compute Tiers & Flux Metering
|
|
850
|
+
|
|
851
|
+
Complex games requiring pathfinding, heavy simulations, or large board states can select appropriate compute tiers in `manifest.json`:
|
|
852
|
+
|
|
853
|
+
| Compute Tier | Wasm Instruction Ceiling (Fuel) | Wall-Clock Timeout | Base Flux Cost |
|
|
854
|
+
|---|---|---|---|
|
|
855
|
+
| `"standard"` (default) | 50,000,000 | 5.0 seconds | 1⚡ |
|
|
856
|
+
| `"high"` | 150,000,000 | 12.0 seconds | 3⚡ |
|
|
857
|
+
| `"ultra"` | 350,000,000 | 25.0 seconds | 6⚡ |
|
|
858
|
+
|
|
859
|
+
Configure your cartridge's tier in `manifest.json`:
|
|
860
|
+
|
|
861
|
+
```json
|
|
862
|
+
{
|
|
863
|
+
"package_id": "grand-strategy",
|
|
864
|
+
"compute_tier": "high",
|
|
865
|
+
"max_flux_per_tick": 5
|
|
866
|
+
}
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
* **Deterministic Fuel Metering**: Billing is calculated based on exact Wasm instructions executed (fuel), ensuring fair costs regardless of server load. Wall-clock timeouts act solely as safety circuit breakers.
|
|
870
|
+
* **Sleeping Sessions Cost Zero**: When a game calls `ctx.timer.schedule()` or `ctx.sleep()`, RAM is released and zero fuel/Flux is charged during hibernation.
|
|
871
|
+
|
|
872
|
+
---
|
|
873
|
+
|
|
722
874
|
## Cartridge Project Layout & CLI
|
|
723
875
|
|
|
724
876
|
Use `angela-cli` to scaffold, test, and publish your cartridge.
|
|
@@ -753,6 +905,7 @@ Angela cartridges require a valid `manifest.json` at project root matching the C
|
|
|
753
905
|
"target_slot_id": 1,
|
|
754
906
|
"default_command": "dice-master-ts",
|
|
755
907
|
"default_ui_theme": "AUTO",
|
|
908
|
+
"compute_tier": "standard",
|
|
756
909
|
"max_flux_per_tick": 5,
|
|
757
910
|
"config_schema": {
|
|
758
911
|
"currency_name": "Coins",
|
|
@@ -777,6 +930,7 @@ Angela cartridges require a valid `manifest.json` at project root matching the C
|
|
|
777
930
|
| `target_slot_id` | `integer` | **Yes** | Target slot ID number on the server (e.g. `1`, `2`). |
|
|
778
931
|
| `default_command` | `string` | No | Slash command trigger for this game (defaults to `package_id`). |
|
|
779
932
|
| `default_ui_theme` | `string` | No | Default rendering mode: `"AUTO"`, `"CV2"`, or `"CLASSIC_EMBED"`. |
|
|
933
|
+
| `compute_tier` | `string` | No | Compute capability tier: `"standard"` (50M fuel / 5s), `"high"` (150M fuel / 12s), or `"ultra"` (350M fuel / 25s). |
|
|
780
934
|
| `max_flux_per_tick` | `integer` | No | Compute Flux ceiling per interaction tick (1 to 100, defaults to 5). |
|
|
781
935
|
| `config_schema` | `object` | No | Default server configuration options merged into `ctx.config`. |
|
|
782
936
|
|
package/dist/cjs/index.js
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/types/index.d.ts
CHANGED