@minecraftbot-com/plugin 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/AGENTS.md +177 -0
  2. package/README.md +45 -2
  3. package/dist/api.d.ts +351 -0
  4. package/dist/api.js +2 -0
  5. package/dist/cli/api.d.ts +26 -0
  6. package/dist/cli/api.js +61 -0
  7. package/dist/cli/build.d.ts +23 -0
  8. package/dist/cli/build.js +65 -0
  9. package/dist/cli/check.d.ts +10 -0
  10. package/dist/cli/check.js +98 -0
  11. package/dist/cli/config.d.ts +11 -0
  12. package/dist/cli/config.js +38 -0
  13. package/dist/cli/create.d.ts +2 -0
  14. package/dist/cli/create.js +39 -0
  15. package/dist/cli/dev-mcp.d.ts +36 -0
  16. package/dist/cli/dev-mcp.js +101 -0
  17. package/dist/cli/dev.d.ts +15 -0
  18. package/dist/cli/dev.js +261 -0
  19. package/dist/cli/fetch-guard.d.ts +7 -0
  20. package/dist/cli/fetch-guard.js +66 -0
  21. package/dist/cli/main.d.ts +2 -0
  22. package/dist/cli/main.js +112 -0
  23. package/dist/cli/mcp.d.ts +24 -0
  24. package/dist/cli/mcp.js +136 -0
  25. package/dist/cli/output.d.ts +11 -0
  26. package/dist/cli/output.js +25 -0
  27. package/dist/cli/test.d.ts +2 -0
  28. package/dist/cli/test.js +39 -0
  29. package/dist/errors.d.ts +22 -0
  30. package/dist/errors.js +35 -0
  31. package/dist/generated/block-states.d.ts +4087 -0
  32. package/dist/generated/block-states.js +2 -0
  33. package/dist/generated/blocks.d.ts +1289 -0
  34. package/dist/generated/blocks.js +1291 -0
  35. package/dist/generated/contracts.d.ts +304 -0
  36. package/dist/generated/contracts.js +327 -0
  37. package/dist/generated/effects.d.ts +43 -0
  38. package/dist/generated/effects.js +45 -0
  39. package/dist/generated/entities.d.ts +164 -0
  40. package/dist/generated/entities.js +166 -0
  41. package/dist/generated/items.d.ts +1661 -0
  42. package/dist/generated/items.js +1663 -0
  43. package/dist/generated/operations.d.ts +7 -0
  44. package/dist/generated/operations.js +65 -0
  45. package/dist/generated/permission-labels.d.ts +3 -0
  46. package/dist/generated/permission-labels.js +17 -0
  47. package/dist/generated/version.d.ts +2 -0
  48. package/dist/generated/version.js +3 -0
  49. package/dist/host/index.d.ts +7 -0
  50. package/dist/host/index.js +5 -0
  51. package/dist/index.d.ts +19 -0
  52. package/dist/index.js +13 -0
  53. package/dist/permissions.d.ts +11 -0
  54. package/dist/permissions.js +18 -0
  55. package/dist/plugin.d.ts +86 -0
  56. package/dist/plugin.js +26 -0
  57. package/dist/protocol.d.ts +167 -0
  58. package/dist/protocol.js +4 -0
  59. package/dist/runtime/connection.d.ts +52 -0
  60. package/dist/runtime/connection.js +132 -0
  61. package/dist/runtime/handles.d.ts +95 -0
  62. package/dist/runtime/handles.js +289 -0
  63. package/dist/runtime/memory-transport.d.ts +6 -0
  64. package/dist/runtime/memory-transport.js +39 -0
  65. package/dist/runtime/runtime.d.ts +57 -0
  66. package/dist/runtime/runtime.js +265 -0
  67. package/dist/runtime/scope.d.ts +25 -0
  68. package/dist/runtime/scope.js +94 -0
  69. package/dist/runtime/storage-runtime.d.ts +10 -0
  70. package/dist/runtime/storage-runtime.js +131 -0
  71. package/dist/settings.d.ts +111 -0
  72. package/dist/settings.js +78 -0
  73. package/dist/storage.d.ts +78 -0
  74. package/dist/storage.js +24 -0
  75. package/dist/testing/fake-container.d.ts +175 -0
  76. package/dist/testing/fake-container.js +483 -0
  77. package/dist/testing/index.d.ts +37 -0
  78. package/dist/testing/index.js +54 -0
  79. package/dist/types.d.ts +65 -0
  80. package/dist/types.js +54 -0
  81. package/llms.txt +11 -0
  82. package/package.json +55 -4
  83. package/src/api.ts +334 -0
  84. package/src/cli/api.ts +79 -0
  85. package/src/cli/build.ts +76 -0
  86. package/src/cli/check.ts +103 -0
  87. package/src/cli/config.ts +48 -0
  88. package/src/cli/create.ts +38 -0
  89. package/src/cli/dev-mcp.ts +131 -0
  90. package/src/cli/dev.ts +272 -0
  91. package/src/cli/fetch-guard.ts +61 -0
  92. package/src/cli/main.ts +113 -0
  93. package/src/cli/mcp.ts +168 -0
  94. package/src/cli/output.ts +30 -0
  95. package/src/cli/test.ts +38 -0
  96. package/src/errors.ts +34 -0
  97. package/src/generated/block-states.ts +892 -0
  98. package/src/generated/blocks.ts +1291 -0
  99. package/src/generated/contracts.ts +329 -0
  100. package/src/generated/effects.ts +45 -0
  101. package/src/generated/entities.ts +166 -0
  102. package/src/generated/items.ts +1663 -0
  103. package/src/generated/operations.ts +69 -0
  104. package/src/generated/permission-labels.ts +19 -0
  105. package/src/generated/version.ts +3 -0
  106. package/src/host/index.ts +9 -0
  107. package/src/index.ts +34 -0
  108. package/src/permissions.ts +23 -0
  109. package/src/plugin.ts +105 -0
  110. package/src/protocol.ts +107 -0
  111. package/src/runtime/connection.ts +167 -0
  112. package/src/runtime/handles.ts +337 -0
  113. package/src/runtime/memory-transport.ts +41 -0
  114. package/src/runtime/runtime.ts +281 -0
  115. package/src/runtime/scope.ts +101 -0
  116. package/src/runtime/storage-runtime.ts +138 -0
  117. package/src/settings.ts +118 -0
  118. package/src/storage.ts +82 -0
  119. package/src/testing/fake-container.ts +571 -0
  120. package/src/testing/index.ts +70 -0
  121. package/src/types.ts +88 -0
  122. package/templates/basic/AGENTS.md +31 -0
  123. package/templates/basic/README.md +13 -0
  124. package/templates/basic/gitignore +3 -0
  125. package/templates/basic/package.json +18 -0
  126. package/templates/basic/src/index.ts +20 -0
  127. package/templates/basic/test/plugin.test.ts +14 -0
  128. package/templates/basic/tsconfig.json +14 -0
@@ -0,0 +1,78 @@
1
+ function define(schema) {
2
+ return { schema };
3
+ }
4
+ function clean(schema) {
5
+ for (const key of Object.keys(schema))
6
+ if (schema[key] === undefined)
7
+ delete schema[key];
8
+ return schema;
9
+ }
10
+ /**
11
+ * Settings the user configures on the dashboard, per bot.
12
+ *
13
+ * @example
14
+ * settings: {
15
+ * crop: Setting.block({ label: "Crop", options: [Block.Wheat, Block.Carrots], default: Block.Wheat }),
16
+ * radius: Setting.radius({ label: "Search radius", default: 16, max: 48 }),
17
+ * greeting: Setting.text({ label: "Greeting", default: "Hello!" }),
18
+ * }
19
+ */
20
+ export const Setting = {
21
+ /** Free text. `max` limits the length (default 256). */
22
+ text(o) {
23
+ return define(clean({ type: "text", label: o.label, description: o.description, default: o.default, optional: o.optional, max: o.max ?? 256 }));
24
+ },
25
+ /** A number between `min` and `max`. */
26
+ number(o) {
27
+ return define(clean({ type: "number", label: o.label, description: o.description, default: o.default, optional: o.optional, min: o.min, max: o.max }));
28
+ },
29
+ /** A distance in blocks, 1 to `max` (at most 64). */
30
+ radius(o) {
31
+ return define(clean({ type: "radius", label: o.label, description: o.description, default: o.default ?? 16, min: 1, max: Math.min(o.max ?? 32, 64) }));
32
+ },
33
+ /** On or off. */
34
+ boolean(o) {
35
+ return define(clean({ type: "boolean", label: o.label, description: o.description, default: o.default ?? false }));
36
+ },
37
+ /** One of a fixed list of values, e.g. an enum's members. */
38
+ select(o) {
39
+ return define(clean({ type: "select", label: o.label, description: o.description, default: o.default, optional: o.optional, options: [...o.options] }));
40
+ },
41
+ /** A block type. `options` limits the choice; without it any block can be picked. */
42
+ block(o) {
43
+ return define(clean({ type: "block", label: o.label, description: o.description, default: o.default, optional: o.optional, options: o.options ? [...o.options] : undefined }));
44
+ },
45
+ /** An item type. */
46
+ item(o) {
47
+ return define(clean({ type: "item", label: o.label, description: o.description, default: o.default, optional: o.optional, options: o.options ? [...o.options] : undefined }));
48
+ },
49
+ /** An entity type (mob, animal, player...). */
50
+ entity(o) {
51
+ return define(clean({ type: "entity", label: o.label, description: o.description, default: o.default, optional: o.optional, options: o.options ? [...o.options] : undefined }));
52
+ },
53
+ /** A position in the world (x, y, z). */
54
+ position(o) {
55
+ return define(clean({ type: "position", label: o.label, description: o.description, default: o.default, optional: o.optional }));
56
+ },
57
+ /**
58
+ * An HTTPS address the user enters, such as a webhook. Your plugin may `fetch` exactly this origin
59
+ * without declaring a network permission. `hosts` limits which hosts are accepted.
60
+ *
61
+ * @example
62
+ * webhook: Setting.url({ label: "Discord webhook", hosts: ["discord.com"], secret: true, optional: true })
63
+ */
64
+ url(o) {
65
+ return define(clean({ type: "url", label: o.label, description: o.description, default: o.secret ? undefined : o.default, optional: o.optional, hosts: o.hosts ? [...o.hosts] : undefined, secret: o.secret || undefined }));
66
+ },
67
+ /**
68
+ * A secret such as an API key: stored encrypted, never shown again on the dashboard, sent only to the
69
+ * running plugin and never to its author.
70
+ */
71
+ secret(o) {
72
+ return define(clean({ type: "secret", label: o.label, description: o.description, optional: o.optional, secret: true }));
73
+ },
74
+ /** A list of values of one kind, e.g. `Setting.list({ label: "Owners", of: Setting.text({ label: "Name" }) })`. */
75
+ list(o) {
76
+ return define(clean({ type: "list", label: o.label, description: o.description, of: o.of.schema, max: o.max ?? 32, default: o.default ?? [] }));
77
+ },
78
+ };
@@ -0,0 +1,78 @@
1
+ import type { StorageSchema } from "./protocol.js";
2
+ import { StorageScope } from "./generated/contracts.js";
3
+ import type { JsonValue } from "./types.js";
4
+ /** Declares one stored value. Build it with `Storage.value` or `Storage.map`. */
5
+ export interface StorageDefinition<T, K extends "value" | "map", S extends StorageScope> {
6
+ readonly schema: StorageSchema;
7
+ readonly __value?: T;
8
+ readonly __kind?: K;
9
+ readonly __scope?: S;
10
+ }
11
+ /**
12
+ * Data your plugin keeps between runs. It belongs to the user who installed the plugin, is limited to
13
+ * 1 MB per scope and 64 KB per value, and holds JSON values only.
14
+ *
15
+ * Scopes: `StorageScope.Profile` (default, shared by every bot of the profile), `StorageScope.Bot` (one per
16
+ * account, survives renames), `StorageScope.User` (shared by all of the user's profiles).
17
+ *
18
+ * @example
19
+ * storage: {
20
+ * harvested: Storage.value({ scope: StorageScope.Bot, default: 0 }),
21
+ * homes: Storage.map<Vec3>(),
22
+ * }
23
+ */
24
+ export declare const Storage: {
25
+ /** A single value. `get()` returns `default` until something is set. */
26
+ value<T, S extends StorageScope = StorageScope.Profile>(o: {
27
+ scope?: S;
28
+ default: T & JsonValue;
29
+ }): StorageDefinition<T, "value", NoInfer<S>>;
30
+ /** Keys (strings, up to 128 characters) to values. */
31
+ map<T extends JsonValue, S extends StorageScope = StorageScope.Profile>(o?: {
32
+ scope?: S;
33
+ }): StorageDefinition<T, "map", NoInfer<S>>;
34
+ };
35
+ /** A stored value. */
36
+ export interface StoredValue<T> {
37
+ /** The current value, or the declared default. */
38
+ get(): Promise<T>;
39
+ set(value: T): Promise<void>;
40
+ /** Back to the default. */
41
+ delete(): Promise<void>;
42
+ /**
43
+ * Read, change and write in one step. If another bot wrote in between, `fn` runs again on the newer
44
+ * value, so concurrent updates are never lost.
45
+ *
46
+ * @example await storage.harvested.update(n => n + 1);
47
+ */
48
+ update(fn: (current: T) => T): Promise<T>;
49
+ }
50
+ /** A stored map from string keys to values. */
51
+ export interface StoredMap<T> {
52
+ get(key: string): Promise<T | undefined>;
53
+ set(key: string, value: T): Promise<void>;
54
+ delete(key: string): Promise<void>;
55
+ /** Change one entry in one step; `fn` gets `undefined` for a missing key. */
56
+ update(key: string, fn: (current: T | undefined) => T): Promise<T>;
57
+ /** Every key, in order. */
58
+ keys(): Promise<string[]>;
59
+ /** Every entry, in key order. */
60
+ entries(): Promise<[string, T][]>;
61
+ }
62
+ /** A bot-scoped value seen from `runProfile`: pick the bot first. */
63
+ export interface PerBot<S> {
64
+ for(bot: {
65
+ readonly uuid: string;
66
+ }): S;
67
+ }
68
+ type Stored<T, K> = K extends "map" ? StoredMap<T> : StoredValue<T>;
69
+ type Accessor<D, InRun extends boolean> = D extends StorageDefinition<infer T, infer K, infer S> ? InRun extends true ? Stored<T, K> : S extends StorageScope.Bot ? PerBot<Stored<T, K>> : Stored<T, K> : never;
70
+ /** `storage` inside `run(bot)`: bot-scoped entries are already bound to that bot. */
71
+ export type BotStorage<S> = {
72
+ readonly [K in keyof S]: Accessor<S[K], true>;
73
+ };
74
+ /** `storage` inside `runProfile`: bot-scoped entries need `.for(bot)`. */
75
+ export type ProfileStorage<S> = {
76
+ readonly [K in keyof S]: Accessor<S[K], false>;
77
+ };
78
+ export {};
@@ -0,0 +1,24 @@
1
+ import { StorageScope } from "./generated/contracts.js";
2
+ /**
3
+ * Data your plugin keeps between runs. It belongs to the user who installed the plugin, is limited to
4
+ * 1 MB per scope and 64 KB per value, and holds JSON values only.
5
+ *
6
+ * Scopes: `StorageScope.Profile` (default, shared by every bot of the profile), `StorageScope.Bot` (one per
7
+ * account, survives renames), `StorageScope.User` (shared by all of the user's profiles).
8
+ *
9
+ * @example
10
+ * storage: {
11
+ * harvested: Storage.value({ scope: StorageScope.Bot, default: 0 }),
12
+ * homes: Storage.map<Vec3>(),
13
+ * }
14
+ */
15
+ export const Storage = {
16
+ /** A single value. `get()` returns `default` until something is set. */
17
+ value(o) {
18
+ return { schema: { kind: "value", scope: o.scope ?? StorageScope.Profile, default: o.default } };
19
+ },
20
+ /** Keys (strings, up to 128 characters) to values. */
21
+ map(o = {}) {
22
+ return { schema: { kind: "map", scope: o.scope ?? StorageScope.Profile } };
23
+ },
24
+ };
@@ -0,0 +1,175 @@
1
+ import { BotEvent, ProfileEvent } from "../generated/contracts.js";
2
+ import type { BotInfo, Manifest } from "../protocol.js";
3
+ import type { Transport } from "../runtime/connection.js";
4
+ import type { Vec3 } from "../types.js";
5
+ /** A block in the fake world. */
6
+ export interface FakeBlock {
7
+ position: Vec3;
8
+ block: string;
9
+ state?: Record<string, string | number | boolean>;
10
+ }
11
+ export interface FakeEntity {
12
+ id: number;
13
+ type: string;
14
+ position: Vec3;
15
+ uuid?: string;
16
+ name?: string;
17
+ }
18
+ export interface FakeItem {
19
+ item: string;
20
+ count: number;
21
+ slot?: number;
22
+ name?: string;
23
+ }
24
+ /** A recipe the fake bot can craft: what one craft takes, what it makes. */
25
+ export interface FakeRecipe {
26
+ result: string;
27
+ /** Made per craft (default 1). */
28
+ count?: number;
29
+ /** Item to how many one craft takes. */
30
+ ingredients: Record<string, number>;
31
+ /** Needs a crafting table (a `minecraft:crafting_table` block within reach). */
32
+ table?: boolean;
33
+ }
34
+ /** A chest (or other container) of the fake world; its block is added to `blocks`. */
35
+ export interface FakeChest {
36
+ position: Vec3;
37
+ /** Default `minecraft:chest`. */
38
+ block?: string;
39
+ /** Slots (default 27). */
40
+ size?: number;
41
+ items?: FakeItem[];
42
+ }
43
+ /** One bot of the fake profile. */
44
+ export interface FakeBotOptions {
45
+ id?: string;
46
+ name?: string;
47
+ uuid?: string;
48
+ position?: Vec3;
49
+ health?: number;
50
+ food?: number;
51
+ inventory?: FakeItem[];
52
+ connected?: boolean;
53
+ /** Whether the plugin runs on it (default true). */
54
+ enabled?: boolean;
55
+ version?: string;
56
+ }
57
+ export interface FakeContainerOptions {
58
+ bots?: FakeBotOptions[];
59
+ blocks?: FakeBlock[];
60
+ entities?: FakeEntity[];
61
+ players?: {
62
+ name: string;
63
+ uuid: string;
64
+ ping?: number;
65
+ }[];
66
+ /** Positions `goto` can't reach (NoPath). */
67
+ unreachable?: Vec3[];
68
+ /** Settings per bot id (or "*" for all). Missing keys fall back to the manifest's defaults. */
69
+ settings?: Record<string, Record<string, unknown>>;
70
+ /** Grant only these; default: whatever the manifest declares, as `minebot dev` does. */
71
+ granted?: string[];
72
+ /** Recipes `bot.craft` and `bot.recipes` know (the real container uses the game's). */
73
+ recipes?: FakeRecipe[];
74
+ containers?: FakeChest[];
75
+ profile?: {
76
+ id: string;
77
+ name: string;
78
+ };
79
+ }
80
+ export interface RecordedCall {
81
+ bot: string | null;
82
+ op: string;
83
+ args: Record<string, unknown>;
84
+ }
85
+ interface BotState {
86
+ info: BotInfo;
87
+ position: Vec3;
88
+ health: number;
89
+ food: number;
90
+ inventory: FakeItem[];
91
+ version: string;
92
+ /** The container open on this bot (a key of `chests`). */
93
+ open: string | null;
94
+ }
95
+ interface ChestState {
96
+ position: Vec3;
97
+ block: string;
98
+ size: number;
99
+ items: FakeItem[];
100
+ }
101
+ /**
102
+ * An in-memory bot container for tests: a tiny world, inventories, chat, storage, and the same permission
103
+ * checks as the real one. It speaks the real protocol over a Transport, so the SDK is exercised end to end.
104
+ */
105
+ export declare class FakeContainer {
106
+ private readonly transport;
107
+ private readonly options;
108
+ readonly calls: RecordedCall[];
109
+ readonly said: {
110
+ bot: string;
111
+ text: string;
112
+ }[];
113
+ readonly commands: {
114
+ bot: string;
115
+ command: string;
116
+ }[];
117
+ readonly logs: {
118
+ bot: string | null;
119
+ level: string;
120
+ message: string;
121
+ }[];
122
+ readonly warnings: Map<string, string>;
123
+ readonly stats: Map<string, number>;
124
+ readonly errors: {
125
+ op: string;
126
+ code: string;
127
+ message: string;
128
+ }[];
129
+ readonly blocks: Map<string, FakeBlock>;
130
+ readonly storage: Map<string, {
131
+ value: unknown;
132
+ version: number;
133
+ }>;
134
+ manifest: Manifest | null;
135
+ private readonly bots;
136
+ private readonly subscriptions;
137
+ private readonly running;
138
+ private granted;
139
+ private entities;
140
+ private readonly players;
141
+ private readonly unreachable;
142
+ private readonly pendingFollows;
143
+ /** The fake world's containers by position, readable from tests. */
144
+ readonly chests: Map<string, ChestState>;
145
+ constructor(transport: Transport, options?: FakeContainerOptions);
146
+ bot(id: string): BotState;
147
+ /** Starts run(bot) on every enabled, connected bot (and runProfile), as the container does after welcome. */
148
+ startAll(): void;
149
+ startBot(id: string): void;
150
+ stopBot(id: string, reason?: string): void;
151
+ /** Sends a bot event if the plugin subscribed to it. Returns whether it was sent. */
152
+ emit(bot: string, event: BotEvent, data: unknown): boolean;
153
+ /** Sends a profile event (`botId` in data becomes a ProfileBot in the SDK). */
154
+ emitProfile(event: ProfileEvent, data: unknown): boolean;
155
+ /** A chat message from a player (or the server, without sender) to a bot. */
156
+ chat(bot: string, text: string, sender?: string | null): boolean;
157
+ disconnectBot(id: string, reason?: string): void;
158
+ setEntities(entities: FakeEntity[]): void;
159
+ close(): void;
160
+ private settingsFor;
161
+ private send;
162
+ private receive;
163
+ private hello;
164
+ private fail;
165
+ private ok;
166
+ private error;
167
+ private call;
168
+ private describe;
169
+ /** Crafts as the real container does: whole crafts, ingredients from the inventory, a table within reach if needed. */
170
+ private craft;
171
+ private storageCall;
172
+ }
173
+ /** Hosts a declared network permission covers, for tests of fetch rules. */
174
+ export declare function declaredHosts(manifest: Manifest): string[];
175
+ export {};