@elizaos/plugin-minecraft 2.0.0-alpha.6 → 2.0.0-beta.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.
Files changed (39) hide show
  1. package/dist/actions/helpers.d.ts +18 -0
  2. package/dist/actions/helpers.d.ts.map +1 -0
  3. package/dist/actions/index.d.ts +9 -12
  4. package/dist/actions/index.d.ts.map +1 -1
  5. package/dist/actions/mc.d.ts +25 -0
  6. package/dist/actions/mc.d.ts.map +1 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +755 -1210
  9. package/dist/index.js.map +15 -25
  10. package/dist/providers/vision.d.ts.map +1 -1
  11. package/dist/providers/waypoints.d.ts.map +1 -1
  12. package/dist/providers/world-state.d.ts +1 -1
  13. package/dist/providers/world-state.d.ts.map +1 -1
  14. package/dist/services/websocket-client.d.ts.map +1 -1
  15. package/package.json +7 -7
  16. package/dist/actions/attack.d.ts +0 -3
  17. package/dist/actions/attack.d.ts.map +0 -1
  18. package/dist/actions/chat.d.ts +0 -3
  19. package/dist/actions/chat.d.ts.map +0 -1
  20. package/dist/actions/connect.d.ts +0 -3
  21. package/dist/actions/connect.d.ts.map +0 -1
  22. package/dist/actions/control.d.ts +0 -3
  23. package/dist/actions/control.d.ts.map +0 -1
  24. package/dist/actions/dig.d.ts +0 -3
  25. package/dist/actions/dig.d.ts.map +0 -1
  26. package/dist/actions/disconnect.d.ts +0 -3
  27. package/dist/actions/disconnect.d.ts.map +0 -1
  28. package/dist/actions/goto.d.ts +0 -3
  29. package/dist/actions/goto.d.ts.map +0 -1
  30. package/dist/actions/look.d.ts +0 -3
  31. package/dist/actions/look.d.ts.map +0 -1
  32. package/dist/actions/place.d.ts +0 -3
  33. package/dist/actions/place.d.ts.map +0 -1
  34. package/dist/actions/scan.d.ts +0 -3
  35. package/dist/actions/scan.d.ts.map +0 -1
  36. package/dist/actions/stop.d.ts +0 -3
  37. package/dist/actions/stop.d.ts.map +0 -1
  38. package/dist/actions/waypoints.d.ts +0 -6
  39. package/dist/actions/waypoints.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -4,21 +4,35 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
33
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
20
34
 
21
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/constants.js
35
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/constants.js
22
36
  var require_constants = __commonJS((exports, module) => {
23
37
  var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
24
38
  var hasBlob = typeof Blob !== "undefined";
@@ -38,7 +52,7 @@ var require_constants = __commonJS((exports, module) => {
38
52
  };
39
53
  });
40
54
 
41
- // ../../../node_modules/.bun/node-gyp-build@4.8.4/node_modules/node-gyp-build/node-gyp-build.js
55
+ // ../../node_modules/.bun/node-gyp-build@4.8.4/node_modules/node-gyp-build/node-gyp-build.js
42
56
  var require_node_gyp_build = __commonJS((exports, module) => {
43
57
  var fs = __require("fs");
44
58
  var path = __require("path");
@@ -227,7 +241,7 @@ var require_node_gyp_build = __commonJS((exports, module) => {
227
241
  load.compareTuples = compareTuples;
228
242
  });
229
243
 
230
- // ../../../node_modules/.bun/node-gyp-build@4.8.4/node_modules/node-gyp-build/index.js
244
+ // ../../node_modules/.bun/node-gyp-build@4.8.4/node_modules/node-gyp-build/index.js
231
245
  var require_node_gyp_build2 = __commonJS((exports, module) => {
232
246
  var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
233
247
  if (typeof runtimeRequire.addon === "function") {
@@ -237,7 +251,7 @@ var require_node_gyp_build2 = __commonJS((exports, module) => {
237
251
  }
238
252
  });
239
253
 
240
- // ../../../node_modules/.bun/bufferutil@4.1.0/node_modules/bufferutil/fallback.js
254
+ // ../../node_modules/.bun/bufferutil@4.1.0/node_modules/bufferutil/fallback.js
241
255
  var require_fallback = __commonJS((exports, module) => {
242
256
  var mask = (source, mask2, output, offset, length) => {
243
257
  for (var i = 0;i < length; i++) {
@@ -253,9 +267,9 @@ var require_fallback = __commonJS((exports, module) => {
253
267
  module.exports = { mask, unmask };
254
268
  });
255
269
 
256
- // ../../../node_modules/.bun/bufferutil@4.1.0/node_modules/bufferutil/index.js
270
+ // ../../node_modules/.bun/bufferutil@4.1.0/node_modules/bufferutil/index.js
257
271
  var require_bufferutil = __commonJS((exports, module) => {
258
- var __dirname = "/Users/shawwalters/eliza-workspace/milady/node_modules/.bun/bufferutil@4.1.0/node_modules/bufferutil";
272
+ var __dirname = "/Users/shawwalters/eliza-workspace/milady/eliza/node_modules/.bun/bufferutil@4.1.0/node_modules/bufferutil";
259
273
  try {
260
274
  module.exports = require_node_gyp_build2()(__dirname);
261
275
  } catch (e) {
@@ -263,7 +277,7 @@ var require_bufferutil = __commonJS((exports, module) => {
263
277
  }
264
278
  });
265
279
 
266
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/buffer-util.js
280
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/buffer-util.js
267
281
  var require_buffer_util = __commonJS((exports, module) => {
268
282
  var { EMPTY_BUFFER } = require_constants();
269
283
  var FastBuffer = Buffer[Symbol.species];
@@ -341,7 +355,7 @@ var require_buffer_util = __commonJS((exports, module) => {
341
355
  }
342
356
  });
343
357
 
344
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/limiter.js
358
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/limiter.js
345
359
  var require_limiter = __commonJS((exports, module) => {
346
360
  var kDone = Symbol("kDone");
347
361
  var kRun = Symbol("kRun");
@@ -373,7 +387,7 @@ var require_limiter = __commonJS((exports, module) => {
373
387
  module.exports = Limiter;
374
388
  });
375
389
 
376
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/permessage-deflate.js
390
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/permessage-deflate.js
377
391
  var require_permessage_deflate = __commonJS((exports, module) => {
378
392
  var zlib = __require("zlib");
379
393
  var bufferUtil = require_buffer_util();
@@ -389,11 +403,11 @@ var require_permessage_deflate = __commonJS((exports, module) => {
389
403
  var zlibLimiter;
390
404
 
391
405
  class PerMessageDeflate {
392
- constructor(options, isServer, maxPayload) {
393
- this._maxPayload = maxPayload | 0;
406
+ constructor(options) {
394
407
  this._options = options || {};
395
408
  this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
396
- this._isServer = !!isServer;
409
+ this._maxPayload = this._options.maxPayload | 0;
410
+ this._isServer = !!this._options.isServer;
397
411
  this._deflate = null;
398
412
  this._inflate = null;
399
413
  this.params = null;
@@ -637,7 +651,7 @@ var require_permessage_deflate = __commonJS((exports, module) => {
637
651
  }
638
652
  });
639
653
 
640
- // ../../../node_modules/.bun/utf-8-validate@5.0.10/node_modules/utf-8-validate/fallback.js
654
+ // ../../node_modules/.bun/utf-8-validate@5.0.10/node_modules/utf-8-validate/fallback.js
641
655
  var require_fallback2 = __commonJS((exports, module) => {
642
656
  function isValidUTF8(buf) {
643
657
  const len = buf.length;
@@ -669,9 +683,9 @@ var require_fallback2 = __commonJS((exports, module) => {
669
683
  module.exports = isValidUTF8;
670
684
  });
671
685
 
672
- // ../../../node_modules/.bun/utf-8-validate@5.0.10/node_modules/utf-8-validate/index.js
686
+ // ../../node_modules/.bun/utf-8-validate@5.0.10/node_modules/utf-8-validate/index.js
673
687
  var require_utf_8_validate = __commonJS((exports, module) => {
674
- var __dirname = "/Users/shawwalters/eliza-workspace/milady/node_modules/.bun/utf-8-validate@5.0.10/node_modules/utf-8-validate";
688
+ var __dirname = "/Users/shawwalters/eliza-workspace/milady/eliza/node_modules/.bun/utf-8-validate@5.0.10/node_modules/utf-8-validate";
675
689
  try {
676
690
  module.exports = require_node_gyp_build2()(__dirname);
677
691
  } catch (e) {
@@ -679,7 +693,7 @@ var require_utf_8_validate = __commonJS((exports, module) => {
679
693
  }
680
694
  });
681
695
 
682
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/validation.js
696
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/validation.js
683
697
  var require_validation = __commonJS((exports, module) => {
684
698
  var { isUtf8 } = __require("buffer");
685
699
  var { hasBlob } = require_constants();
@@ -866,7 +880,7 @@ var require_validation = __commonJS((exports, module) => {
866
880
  }
867
881
  });
868
882
 
869
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/receiver.js
883
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/receiver.js
870
884
  var require_receiver = __commonJS((exports, module) => {
871
885
  var { Writable } = __require("stream");
872
886
  var PerMessageDeflate = require_permessage_deflate();
@@ -1247,7 +1261,7 @@ var require_receiver = __commonJS((exports, module) => {
1247
1261
  module.exports = Receiver;
1248
1262
  });
1249
1263
 
1250
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/sender.js
1264
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/sender.js
1251
1265
  var require_sender = __commonJS((exports, module) => {
1252
1266
  var { Duplex } = __require("stream");
1253
1267
  var { randomFillSync } = __require("crypto");
@@ -1601,7 +1615,7 @@ var require_sender = __commonJS((exports, module) => {
1601
1615
  }
1602
1616
  });
1603
1617
 
1604
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/event-target.js
1618
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/event-target.js
1605
1619
  var require_event_target = __commonJS((exports, module) => {
1606
1620
  var { kForOnEventAttribute, kListener } = require_constants();
1607
1621
  var kCode = Symbol("kCode");
@@ -1752,7 +1766,7 @@ var require_event_target = __commonJS((exports, module) => {
1752
1766
  }
1753
1767
  });
1754
1768
 
1755
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/extension.js
1769
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/extension.js
1756
1770
  var require_extension = __commonJS((exports, module) => {
1757
1771
  var { tokenChars } = require_validation();
1758
1772
  function push(dest, name, elem) {
@@ -1917,7 +1931,7 @@ var require_extension = __commonJS((exports, module) => {
1917
1931
  module.exports = { format, parse };
1918
1932
  });
1919
1933
 
1920
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/websocket.js
1934
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/websocket.js
1921
1935
  var require_websocket = __commonJS((exports, module) => {
1922
1936
  var EventEmitter = __require("events");
1923
1937
  var https = __require("https");
@@ -2306,7 +2320,7 @@ var require_websocket = __commonJS((exports, module) => {
2306
2320
  } else {
2307
2321
  try {
2308
2322
  parsedUrl = new URL(address);
2309
- } catch (e) {
2323
+ } catch {
2310
2324
  throw new SyntaxError(`Invalid URL: ${address}`);
2311
2325
  }
2312
2326
  }
@@ -2354,7 +2368,11 @@ var require_websocket = __commonJS((exports, module) => {
2354
2368
  opts.path = parsedUrl.pathname + parsedUrl.search;
2355
2369
  opts.timeout = opts.handshakeTimeout;
2356
2370
  if (opts.perMessageDeflate) {
2357
- perMessageDeflate = new PerMessageDeflate(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
2371
+ perMessageDeflate = new PerMessageDeflate({
2372
+ ...opts.perMessageDeflate,
2373
+ isServer: false,
2374
+ maxPayload: opts.maxPayload
2375
+ });
2358
2376
  opts.headers["Sec-WebSocket-Extensions"] = format({
2359
2377
  [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
2360
2378
  });
@@ -2679,7 +2697,7 @@ var require_websocket = __commonJS((exports, module) => {
2679
2697
  }
2680
2698
  });
2681
2699
 
2682
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/stream.js
2700
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/stream.js
2683
2701
  var require_stream = __commonJS((exports, module) => {
2684
2702
  var WebSocket = require_websocket();
2685
2703
  var { Duplex } = __require("stream");
@@ -2782,7 +2800,7 @@ var require_stream = __commonJS((exports, module) => {
2782
2800
  module.exports = createWebSocketStream;
2783
2801
  });
2784
2802
 
2785
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/subprotocol.js
2803
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/subprotocol.js
2786
2804
  var require_subprotocol = __commonJS((exports, module) => {
2787
2805
  var { tokenChars } = require_validation();
2788
2806
  function parse(header) {
@@ -2827,7 +2845,7 @@ var require_subprotocol = __commonJS((exports, module) => {
2827
2845
  module.exports = { parse };
2828
2846
  });
2829
2847
 
2830
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/lib/websocket-server.js
2848
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/lib/websocket-server.js
2831
2849
  var require_websocket_server = __commonJS((exports, module) => {
2832
2850
  var EventEmitter = __require("events");
2833
2851
  var http = __require("http");
@@ -3000,7 +3018,11 @@ var require_websocket_server = __commonJS((exports, module) => {
3000
3018
  const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3001
3019
  const extensions = {};
3002
3020
  if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
3003
- const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
3021
+ const perMessageDeflate = new PerMessageDeflate({
3022
+ ...this.options.perMessageDeflate,
3023
+ isServer: true,
3024
+ maxPayload: this.options.maxPayload
3025
+ });
3004
3026
  try {
3005
3027
  const offers = extension.parse(secWebSocketExtensions);
3006
3028
  if (offers[PerMessageDeflate.extensionName]) {
@@ -3131,7 +3153,7 @@ var require_websocket_server = __commonJS((exports, module) => {
3131
3153
 
3132
3154
  // src/index.ts
3133
3155
  import { logger as logger5 } from "@elizaos/core";
3134
- import { z as z9 } from "zod";
3156
+ import { z as z4 } from "zod";
3135
3157
 
3136
3158
  // src/services/minecraft-service.ts
3137
3159
  import { logger as logger3, Service } from "@elizaos/core";
@@ -3272,10 +3294,13 @@ class MinecraftProcessManager {
3272
3294
  // src/services/websocket-client.ts
3273
3295
  import { logger as logger2 } from "@elizaos/core";
3274
3296
 
3275
- // ../../../node_modules/.bun/ws@8.19.0+4789783d1fa00420/node_modules/ws/wrapper.mjs
3297
+ // ../../node_modules/.bun/ws@8.20.0+4789783d1fa00420/node_modules/ws/wrapper.mjs
3276
3298
  var import_stream = __toESM(require_stream(), 1);
3299
+ var import_extension = __toESM(require_extension(), 1);
3300
+ var import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
3277
3301
  var import_receiver = __toESM(require_receiver(), 1);
3278
3302
  var import_sender = __toESM(require_sender(), 1);
3303
+ var import_subprotocol = __toESM(require_subprotocol(), 1);
3279
3304
  var import_websocket = __toESM(require_websocket(), 1);
3280
3305
  var import_websocket_server = __toESM(require_websocket_server(), 1);
3281
3306
  var wrapper_default = import_websocket.default;
@@ -3333,7 +3358,8 @@ class MinecraftWebSocketClient {
3333
3358
  return resp.success && resp.data?.status === "ok";
3334
3359
  }
3335
3360
  async sendMessage(type, botId, data, timeoutMs = 30000) {
3336
- if (!this.ws || this.ws.readyState !== wrapper_default.OPEN) {
3361
+ const ws = this.ws;
3362
+ if (!ws || ws.readyState !== wrapper_default.OPEN) {
3337
3363
  throw new Error("Not connected to Mineflayer bridge server");
3338
3364
  }
3339
3365
  const requestId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
@@ -3350,7 +3376,7 @@ class MinecraftWebSocketClient {
3350
3376
  reject(new Error(`Request timeout: ${type}`));
3351
3377
  }, timeoutMs);
3352
3378
  this.pending.set(requestId, { resolve, reject, timeoutId });
3353
- this.ws?.send(payload, (err) => {
3379
+ ws.send(payload, (err) => {
3354
3380
  if (err) {
3355
3381
  clearTimeout(timeoutId);
3356
3382
  this.pending.delete(requestId);
@@ -3502,847 +3528,6 @@ class MinecraftService extends Service {
3502
3528
  }
3503
3529
  }
3504
3530
 
3505
- // src/actions/attack.ts
3506
- function parseEntityId(text) {
3507
- const trimmed = text.trim();
3508
- if (!trimmed)
3509
- return null;
3510
- const id = Number(trimmed);
3511
- return Number.isFinite(id) ? id : null;
3512
- }
3513
- var minecraftAttackAction = {
3514
- name: "MC_ATTACK",
3515
- similes: ["MINECRAFT_ATTACK", "HIT_ENTITY"],
3516
- description: "Attack an entity by numeric entityId (from MC_WORLD_STATE.nearbyEntities).",
3517
- validate: async (runtime, message, state, options) => {
3518
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
3519
- const __avText = __avTextRaw.toLowerCase();
3520
- const __avKeywords = ["attack"];
3521
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
3522
- const __avRegex = /\b(?:attack)\b/i;
3523
- const __avRegexOk = __avRegex.test(__avText);
3524
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
3525
- const __avExpectedSource = "";
3526
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
3527
- const __avOptions = options && typeof options === "object" ? options : {};
3528
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
3529
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
3530
- return false;
3531
- }
3532
- const __avLegacyValidate = async (runtime2, message2) => {
3533
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
3534
- return Boolean(service) && parseEntityId(message2.content.text ?? "") !== null;
3535
- };
3536
- try {
3537
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
3538
- } catch {
3539
- return false;
3540
- }
3541
- },
3542
- handler: async (runtime, message, _state, _options, callback) => {
3543
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
3544
- if (!service)
3545
- return { text: "Minecraft service is not available", success: false };
3546
- const entityId = parseEntityId(message.content.text ?? "");
3547
- if (entityId === null)
3548
- return { text: "Missing entityId", success: false };
3549
- try {
3550
- await service.request("attack", { entityId });
3551
- const content = {
3552
- text: `Attacked entity ${entityId}.`,
3553
- actions: ["MC_ATTACK"],
3554
- source: message.content.source
3555
- };
3556
- await callback?.(content);
3557
- return { text: content.text ?? "", success: true };
3558
- } catch (err) {
3559
- const msg = err instanceof Error ? err.message : String(err);
3560
- const content = {
3561
- text: `Failed to attack: ${msg}`,
3562
- actions: ["MC_ATTACK"],
3563
- source: message.content.source
3564
- };
3565
- await callback?.(content);
3566
- return { text: content.text ?? "", success: false };
3567
- }
3568
- }
3569
- };
3570
- // src/actions/chat.ts
3571
- var minecraftChatAction = {
3572
- name: "MC_CHAT",
3573
- similes: ["MINECRAFT_CHAT", "SAY_IN_MINECRAFT", "CHAT"],
3574
- description: "Send a chat message in Minecraft as the bot",
3575
- validate: async (runtime, message, state, options) => {
3576
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
3577
- const __avText = __avTextRaw.toLowerCase();
3578
- const __avKeywords = ["chat"];
3579
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
3580
- const __avRegex = /\b(?:chat)\b/i;
3581
- const __avRegexOk = __avRegex.test(__avText);
3582
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
3583
- const __avExpectedSource = "";
3584
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
3585
- const __avOptions = options && typeof options === "object" ? options : {};
3586
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
3587
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
3588
- return false;
3589
- }
3590
- const __avLegacyValidate = async (runtime2, message2) => {
3591
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
3592
- return Boolean(service) && (message2.content.text ?? "").trim().length > 0;
3593
- };
3594
- try {
3595
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
3596
- } catch {
3597
- return false;
3598
- }
3599
- },
3600
- handler: async (runtime, message, _state, _options, callback) => {
3601
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
3602
- if (!service) {
3603
- return { text: "Minecraft service is not available", success: false };
3604
- }
3605
- const text = (message.content.text ?? "").trim();
3606
- if (!text)
3607
- return { text: "No chat message provided", success: false };
3608
- try {
3609
- await service.chat(text);
3610
- const content = {
3611
- text: `Sent Minecraft chat: ${text}`,
3612
- actions: ["MC_CHAT"],
3613
- source: message.content.source
3614
- };
3615
- await callback?.(content);
3616
- return {
3617
- text: content.text ?? "",
3618
- success: true,
3619
- values: { sent: true }
3620
- };
3621
- } catch (err) {
3622
- const msg = err instanceof Error ? err.message : String(err);
3623
- const content = {
3624
- text: `Failed to send Minecraft chat: ${msg}`,
3625
- actions: ["MC_CHAT"],
3626
- source: message.content.source
3627
- };
3628
- await callback?.(content);
3629
- return { text: content.text ?? "", success: false };
3630
- }
3631
- }
3632
- };
3633
- // src/actions/connect.ts
3634
- import { z as z3 } from "zod";
3635
- var connectOverridesSchema = z3.object({
3636
- host: z3.string().optional(),
3637
- port: z3.number().int().positive().optional(),
3638
- username: z3.string().optional(),
3639
- auth: z3.enum(["offline", "microsoft"]).optional(),
3640
- version: z3.string().optional()
3641
- }).passthrough();
3642
- function parseOverrides(text) {
3643
- const trimmed = text.trim();
3644
- if (!trimmed.startsWith("{") || !trimmed.endsWith("}"))
3645
- return {};
3646
- try {
3647
- const parsed = JSON.parse(trimmed);
3648
- const validated = connectOverridesSchema.parse(parsed);
3649
- const out = {};
3650
- if (typeof validated.host === "string")
3651
- out.host = validated.host;
3652
- if (typeof validated.port === "number")
3653
- out.port = validated.port;
3654
- if (typeof validated.username === "string")
3655
- out.username = validated.username;
3656
- if (typeof validated.auth === "string")
3657
- out.auth = validated.auth;
3658
- if (typeof validated.version === "string")
3659
- out.version = validated.version;
3660
- return out;
3661
- } catch {
3662
- return {};
3663
- }
3664
- }
3665
- var minecraftConnectAction = {
3666
- name: "MC_CONNECT",
3667
- similes: ["MINECRAFT_CONNECT", "JOIN_SERVER", "CONNECT_TO_MINECRAFT"],
3668
- description: "Connect the Mineflayer bot to a Minecraft server",
3669
- validate: async (runtime, message, state, options) => {
3670
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
3671
- const __avText = __avTextRaw.toLowerCase();
3672
- const __avKeywords = ["connect"];
3673
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
3674
- const __avRegex = /\b(?:connect)\b/i;
3675
- const __avRegexOk = __avRegex.test(__avText);
3676
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
3677
- const __avExpectedSource = "";
3678
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
3679
- const __avOptions = options && typeof options === "object" ? options : {};
3680
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
3681
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
3682
- return false;
3683
- }
3684
- const __avLegacyValidate = async (runtime2) => {
3685
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
3686
- return Boolean(service);
3687
- };
3688
- try {
3689
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
3690
- } catch {
3691
- return false;
3692
- }
3693
- },
3694
- handler: async (runtime, message, _state, _options, callback) => {
3695
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
3696
- if (!service) {
3697
- return { text: "Minecraft service is not available", success: false };
3698
- }
3699
- try {
3700
- const overrides = parseOverrides(message.content.text ?? "");
3701
- const session = await service.createBot(overrides);
3702
- const content = {
3703
- text: `Connected Minecraft bot (botId=${session.botId}).`,
3704
- actions: ["MC_CONNECT"],
3705
- source: message.content.source
3706
- };
3707
- await callback?.(content);
3708
- return {
3709
- text: content.text ?? "",
3710
- success: true,
3711
- data: { botId: session.botId },
3712
- values: { connected: true }
3713
- };
3714
- } catch (err) {
3715
- const msg = err instanceof Error ? err.message : String(err);
3716
- const content = {
3717
- text: `Failed to connect Minecraft bot: ${msg}`,
3718
- actions: ["MC_CONNECT"],
3719
- source: message.content.source
3720
- };
3721
- await callback?.(content);
3722
- return {
3723
- text: content.text ?? "",
3724
- success: false,
3725
- data: { error: msg },
3726
- values: { connected: false }
3727
- };
3728
- }
3729
- }
3730
- };
3731
- // src/actions/control.ts
3732
- import { z as z4 } from "zod";
3733
- var controlSchema = z4.object({
3734
- control: z4.string(),
3735
- state: z4.boolean(),
3736
- durationMs: z4.number().int().positive().optional()
3737
- });
3738
- function parseControl(text) {
3739
- const trimmed = text.trim();
3740
- if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
3741
- try {
3742
- const parsed = JSON.parse(trimmed);
3743
- return controlSchema.parse(parsed);
3744
- } catch {
3745
- return null;
3746
- }
3747
- }
3748
- const m = trimmed.match(/^(\S+)\s+(true|false)(?:\s+(\d+))?$/i);
3749
- if (!m)
3750
- return null;
3751
- const control = m[1];
3752
- const state = m[2].toLowerCase() === "true";
3753
- const durationMs = m[3] ? Number(m[3]) : undefined;
3754
- if (durationMs !== undefined && !Number.isFinite(durationMs))
3755
- return null;
3756
- return durationMs ? { control, state, durationMs } : { control, state };
3757
- }
3758
- var minecraftControlAction = {
3759
- name: "MC_CONTROL",
3760
- similes: ["MINECRAFT_CONTROL", "SET_CONTROL_STATE"],
3761
- description: "Set a control state (e.g. forward/back/left/right/jump/sprint/sneak). Provide JSON {control,state,durationMs?} or 'forward true 1000'.",
3762
- validate: async (runtime, message, state, options) => {
3763
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
3764
- const __avText = __avTextRaw.toLowerCase();
3765
- const __avKeywords = ["control"];
3766
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
3767
- const __avRegex = /\b(?:control)\b/i;
3768
- const __avRegexOk = __avRegex.test(__avText);
3769
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
3770
- const __avExpectedSource = "";
3771
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
3772
- const __avOptions = options && typeof options === "object" ? options : {};
3773
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
3774
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
3775
- return false;
3776
- }
3777
- const __avLegacyValidate = async (runtime2, message2) => {
3778
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
3779
- return Boolean(service) && Boolean(parseControl(message2.content.text ?? ""));
3780
- };
3781
- try {
3782
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
3783
- } catch {
3784
- return false;
3785
- }
3786
- },
3787
- handler: async (runtime, message, _state, _options, callback) => {
3788
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
3789
- if (!service)
3790
- return { text: "Minecraft service is not available", success: false };
3791
- const req = parseControl(message.content.text ?? "");
3792
- if (!req)
3793
- return { text: "Missing control command", success: false };
3794
- try {
3795
- await service.request("control", {
3796
- control: req.control,
3797
- state: req.state,
3798
- ...typeof req.durationMs === "number" ? { durationMs: req.durationMs } : {}
3799
- });
3800
- const content = {
3801
- text: `Set control ${req.control}=${String(req.state)}${req.durationMs ? ` for ${req.durationMs}ms` : ""}.`,
3802
- actions: ["MC_CONTROL"],
3803
- source: message.content.source
3804
- };
3805
- await callback?.(content);
3806
- return { text: content.text ?? "", success: true };
3807
- } catch (err) {
3808
- const msg = err instanceof Error ? err.message : String(err);
3809
- const content = {
3810
- text: `Failed to set control: ${msg}`,
3811
- actions: ["MC_CONTROL"],
3812
- source: message.content.source
3813
- };
3814
- await callback?.(content);
3815
- return { text: content.text ?? "", success: false };
3816
- }
3817
- }
3818
- };
3819
- // src/actions/utils.ts
3820
- import { z as z5 } from "zod";
3821
- var vec3Schema = z5.object({ x: z5.number(), y: z5.number(), z: z5.number() });
3822
- function extractVec3(text) {
3823
- const trimmed = text.trim();
3824
- if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
3825
- try {
3826
- const parsed = JSON.parse(trimmed);
3827
- const v = vec3Schema.parse(parsed);
3828
- return v;
3829
- } catch {}
3830
- }
3831
- const m = trimmed.match(/(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/);
3832
- if (!m)
3833
- return null;
3834
- const x = Number(m[1]);
3835
- const y = Number(m[2]);
3836
- const z6 = Number(m[3]);
3837
- if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z6))
3838
- return null;
3839
- return { x, y, z: z6 };
3840
- }
3841
-
3842
- // src/actions/dig.ts
3843
- var minecraftDigAction = {
3844
- name: "MC_DIG",
3845
- similes: ["MINECRAFT_DIG", "MINE_BLOCK", "BREAK_BLOCK"],
3846
- description: `Dig/break the block at (x y z). Provide coordinates like '10 64 -20' or JSON {"x":10,"y":64,"z":-20}.`,
3847
- validate: async (runtime, message, state, options) => {
3848
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
3849
- const __avText = __avTextRaw.toLowerCase();
3850
- const __avKeywords = ["dig"];
3851
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
3852
- const __avRegex = /\b(?:dig)\b/i;
3853
- const __avRegexOk = __avRegex.test(__avText);
3854
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
3855
- const __avExpectedSource = "";
3856
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
3857
- const __avOptions = options && typeof options === "object" ? options : {};
3858
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
3859
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
3860
- return false;
3861
- }
3862
- const __avLegacyValidate = async (runtime2, message2) => {
3863
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
3864
- return Boolean(service) && Boolean(extractVec3(message2.content.text ?? ""));
3865
- };
3866
- try {
3867
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
3868
- } catch {
3869
- return false;
3870
- }
3871
- },
3872
- handler: async (runtime, message, _state, _options, callback) => {
3873
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
3874
- if (!service)
3875
- return { text: "Minecraft service is not available", success: false };
3876
- const vec = extractVec3(message.content.text ?? "");
3877
- if (!vec)
3878
- return { text: "Missing coordinates (x y z)", success: false };
3879
- try {
3880
- const data = await service.request("dig", {
3881
- x: vec.x,
3882
- y: vec.y,
3883
- z: vec.z
3884
- });
3885
- const blockName = typeof data.blockName === "string" ? data.blockName : "block";
3886
- const content = {
3887
- text: `Dug ${blockName} at (${vec.x}, ${vec.y}, ${vec.z}).`,
3888
- actions: ["MC_DIG"],
3889
- source: message.content.source
3890
- };
3891
- await callback?.(content);
3892
- return { text: content.text ?? "", success: true };
3893
- } catch (err) {
3894
- const msg = err instanceof Error ? err.message : String(err);
3895
- const content = {
3896
- text: `Failed to dig: ${msg}`,
3897
- actions: ["MC_DIG"],
3898
- source: message.content.source
3899
- };
3900
- await callback?.(content);
3901
- return { text: content.text ?? "", success: false };
3902
- }
3903
- }
3904
- };
3905
- // src/actions/disconnect.ts
3906
- var minecraftDisconnectAction = {
3907
- name: "MC_DISCONNECT",
3908
- similes: ["MINECRAFT_DISCONNECT", "LEAVE_SERVER", "QUIT_MINECRAFT"],
3909
- description: "Disconnect the Mineflayer bot from the Minecraft server",
3910
- validate: async (runtime, message, state, options) => {
3911
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
3912
- const __avText = __avTextRaw.toLowerCase();
3913
- const __avKeywords = ["disconnect"];
3914
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
3915
- const __avRegex = /\b(?:disconnect)\b/i;
3916
- const __avRegexOk = __avRegex.test(__avText);
3917
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
3918
- const __avExpectedSource = "";
3919
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
3920
- const __avOptions = options && typeof options === "object" ? options : {};
3921
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
3922
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
3923
- return false;
3924
- }
3925
- const __avLegacyValidate = async (runtime2) => {
3926
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
3927
- return Boolean(service?.getCurrentSession());
3928
- };
3929
- try {
3930
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
3931
- } catch {
3932
- return false;
3933
- }
3934
- },
3935
- handler: async (runtime, message, _state, _options, callback) => {
3936
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
3937
- if (!service) {
3938
- return { text: "Minecraft service is not available", success: false };
3939
- }
3940
- const session = service.getCurrentSession();
3941
- if (!session) {
3942
- return { text: "No Minecraft bot is connected", success: false };
3943
- }
3944
- try {
3945
- await service.destroyBot(session.botId);
3946
- const content = {
3947
- text: "Disconnected Minecraft bot.",
3948
- actions: ["MC_DISCONNECT"],
3949
- source: message.content.source
3950
- };
3951
- await callback?.(content);
3952
- return {
3953
- text: content.text ?? "",
3954
- success: true,
3955
- values: { connected: false }
3956
- };
3957
- } catch (err) {
3958
- const msg = err instanceof Error ? err.message : String(err);
3959
- const content = {
3960
- text: `Failed to disconnect Minecraft bot: ${msg}`,
3961
- actions: ["MC_DISCONNECT"],
3962
- source: message.content.source
3963
- };
3964
- await callback?.(content);
3965
- return { text: content.text ?? "", success: false };
3966
- }
3967
- }
3968
- };
3969
- // src/actions/goto.ts
3970
- var minecraftGotoAction = {
3971
- name: "MC_GOTO",
3972
- similes: ["MINECRAFT_GOTO", "WALK_TO", "MOVE_TO_COORDS"],
3973
- description: `Pathfind to a target (x y z). Provide coordinates like '10 64 -20' or JSON {"x":10,"y":64,"z":-20}.`,
3974
- validate: async (runtime, message, state, options) => {
3975
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
3976
- const __avText = __avTextRaw.toLowerCase();
3977
- const __avKeywords = ["goto"];
3978
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
3979
- const __avRegex = /\b(?:goto)\b/i;
3980
- const __avRegexOk = __avRegex.test(__avText);
3981
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
3982
- const __avExpectedSource = "";
3983
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
3984
- const __avOptions = options && typeof options === "object" ? options : {};
3985
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
3986
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
3987
- return false;
3988
- }
3989
- const __avLegacyValidate = async (runtime2, message2) => {
3990
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
3991
- return Boolean(service) && Boolean(extractVec3(message2.content.text ?? ""));
3992
- };
3993
- try {
3994
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
3995
- } catch {
3996
- return false;
3997
- }
3998
- },
3999
- handler: async (runtime, message, _state, _options, callback) => {
4000
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
4001
- if (!service)
4002
- return { text: "Minecraft service is not available", success: false };
4003
- const vec = extractVec3(message.content.text ?? "");
4004
- if (!vec)
4005
- return { text: "Missing coordinates (x y z)", success: false };
4006
- try {
4007
- await service.request("goto", { x: vec.x, y: vec.y, z: vec.z });
4008
- const content = {
4009
- text: `Moving to (${vec.x}, ${vec.y}, ${vec.z}).`,
4010
- actions: ["MC_GOTO"],
4011
- source: message.content.source
4012
- };
4013
- await callback?.(content);
4014
- return { text: content.text ?? "", success: true };
4015
- } catch (err) {
4016
- const msg = err instanceof Error ? err.message : String(err);
4017
- const content = {
4018
- text: `Failed to pathfind: ${msg}`,
4019
- actions: ["MC_GOTO"],
4020
- source: message.content.source
4021
- };
4022
- await callback?.(content);
4023
- return { text: content.text ?? "", success: false };
4024
- }
4025
- }
4026
- };
4027
- // src/actions/look.ts
4028
- import { z as z6 } from "zod";
4029
- var lookSchema = z6.object({ yaw: z6.number(), pitch: z6.number() });
4030
- function parseLook(text) {
4031
- const trimmed = text.trim();
4032
- if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
4033
- try {
4034
- const parsed = JSON.parse(trimmed);
4035
- return lookSchema.parse(parsed);
4036
- } catch {
4037
- return null;
4038
- }
4039
- }
4040
- const m = trimmed.match(/(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/);
4041
- if (!m)
4042
- return null;
4043
- const yaw = Number(m[1]);
4044
- const pitch = Number(m[2]);
4045
- if (!Number.isFinite(yaw) || !Number.isFinite(pitch))
4046
- return null;
4047
- return { yaw, pitch };
4048
- }
4049
- var minecraftLookAction = {
4050
- name: "MC_LOOK",
4051
- similes: ["MINECRAFT_LOOK", "TURN_HEAD"],
4052
- description: "Look to yaw/pitch (radians). Provide 'yaw pitch' or JSON {yaw,pitch}.",
4053
- validate: async (runtime, message, state, options) => {
4054
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
4055
- const __avText = __avTextRaw.toLowerCase();
4056
- const __avKeywords = ["look"];
4057
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
4058
- const __avRegex = /\b(?:look)\b/i;
4059
- const __avRegexOk = __avRegex.test(__avText);
4060
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
4061
- const __avExpectedSource = "";
4062
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
4063
- const __avOptions = options && typeof options === "object" ? options : {};
4064
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
4065
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
4066
- return false;
4067
- }
4068
- const __avLegacyValidate = async (runtime2, message2) => {
4069
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
4070
- return Boolean(service) && Boolean(parseLook(message2.content.text ?? ""));
4071
- };
4072
- try {
4073
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
4074
- } catch {
4075
- return false;
4076
- }
4077
- },
4078
- handler: async (runtime, message, _state, _options, callback) => {
4079
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
4080
- if (!service)
4081
- return { text: "Minecraft service is not available", success: false };
4082
- const req = parseLook(message.content.text ?? "");
4083
- if (!req)
4084
- return { text: "Missing yaw/pitch", success: false };
4085
- try {
4086
- await service.request("look", { yaw: req.yaw, pitch: req.pitch });
4087
- const content = {
4088
- text: "Adjusted view.",
4089
- actions: ["MC_LOOK"],
4090
- source: message.content.source
4091
- };
4092
- await callback?.(content);
4093
- return { text: content.text ?? "", success: true };
4094
- } catch (err) {
4095
- const msg = err instanceof Error ? err.message : String(err);
4096
- const content = {
4097
- text: `Failed to look: ${msg}`,
4098
- actions: ["MC_LOOK"],
4099
- source: message.content.source
4100
- };
4101
- await callback?.(content);
4102
- return { text: content.text ?? "", success: false };
4103
- }
4104
- }
4105
- };
4106
- // src/actions/place.ts
4107
- import { z as z7 } from "zod";
4108
- var placeSchema = z7.object({
4109
- x: z7.number(),
4110
- y: z7.number(),
4111
- z: z7.number(),
4112
- face: z7.enum(["up", "down", "north", "south", "east", "west"])
4113
- });
4114
- function parsePlace(text) {
4115
- const trimmed = text.trim();
4116
- if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
4117
- try {
4118
- const parsed = JSON.parse(trimmed);
4119
- const v = placeSchema.parse(parsed);
4120
- return v;
4121
- } catch {
4122
- return null;
4123
- }
4124
- }
4125
- const m = trimmed.match(/(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(up|down|north|south|east|west)\b/i);
4126
- if (!m)
4127
- return null;
4128
- const x = Number(m[1]);
4129
- const y = Number(m[2]);
4130
- const zVal = Number(m[3]);
4131
- const face = m[4].toLowerCase();
4132
- if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(zVal))
4133
- return null;
4134
- return { x, y, z: zVal, face };
4135
- }
4136
- var minecraftPlaceAction = {
4137
- name: "MC_PLACE",
4138
- similes: ["MINECRAFT_PLACE", "PLACE_BLOCK"],
4139
- description: "Place the currently-held block onto a reference block face. Provide 'x y z face' (face=up/down/north/south/east/west) or JSON {x,y,z,face}.",
4140
- validate: async (runtime, message, state, options) => {
4141
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
4142
- const __avText = __avTextRaw.toLowerCase();
4143
- const __avKeywords = ["place"];
4144
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
4145
- const __avRegex = /\b(?:place)\b/i;
4146
- const __avRegexOk = __avRegex.test(__avText);
4147
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
4148
- const __avExpectedSource = "";
4149
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
4150
- const __avOptions = options && typeof options === "object" ? options : {};
4151
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
4152
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
4153
- return false;
4154
- }
4155
- const __avLegacyValidate = async (runtime2, message2) => {
4156
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
4157
- return Boolean(service) && Boolean(parsePlace(message2.content.text ?? ""));
4158
- };
4159
- try {
4160
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
4161
- } catch {
4162
- return false;
4163
- }
4164
- },
4165
- handler: async (runtime, message, _state, _options, callback) => {
4166
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
4167
- if (!service)
4168
- return { text: "Minecraft service is not available", success: false };
4169
- const req = parsePlace(message.content.text ?? "");
4170
- if (!req)
4171
- return { text: "Missing placement target (x y z face)", success: false };
4172
- try {
4173
- await service.request("place", {
4174
- x: req.x,
4175
- y: req.y,
4176
- z: req.z,
4177
- face: req.face
4178
- });
4179
- const content = {
4180
- text: `Placed block at (${req.x}, ${req.y}, ${req.z}) face=${req.face}.`,
4181
- actions: ["MC_PLACE"],
4182
- source: message.content.source
4183
- };
4184
- await callback?.(content);
4185
- return { text: content.text ?? "", success: true };
4186
- } catch (err) {
4187
- const msg = err instanceof Error ? err.message : String(err);
4188
- const content = {
4189
- text: `Failed to place: ${msg}`,
4190
- actions: ["MC_PLACE"],
4191
- source: message.content.source
4192
- };
4193
- await callback?.(content);
4194
- return { text: content.text ?? "", success: false };
4195
- }
4196
- }
4197
- };
4198
- // src/actions/scan.ts
4199
- import { z as z8 } from "zod";
4200
- var scanSchema = z8.object({
4201
- blocks: z8.array(z8.string()).optional(),
4202
- radius: z8.number().int().positive().optional(),
4203
- maxResults: z8.number().int().positive().optional()
4204
- }).passthrough();
4205
- function parseScan(text) {
4206
- const trimmed = text.trim();
4207
- if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) {
4208
- return {};
4209
- }
4210
- try {
4211
- const parsed = JSON.parse(trimmed);
4212
- const validated = scanSchema.parse({
4213
- blocks: Array.isArray(parsed.blocks) ? parsed.blocks.filter((b) => typeof b === "string") : undefined,
4214
- radius: typeof parsed.radius === "number" ? parsed.radius : undefined,
4215
- maxResults: typeof parsed.maxResults === "number" ? parsed.maxResults : undefined
4216
- });
4217
- return {
4218
- blocks: validated.blocks,
4219
- radius: validated.radius,
4220
- maxResults: validated.maxResults
4221
- };
4222
- } catch {
4223
- return {};
4224
- }
4225
- }
4226
- var minecraftScanAction = {
4227
- name: "MC_SCAN",
4228
- similes: ["MINECRAFT_SCAN", "FIND_BLOCKS", "SCAN_BLOCKS"],
4229
- description: 'Scan nearby blocks. Optional JSON input: {"blocks":["oak_log"],"radius":16,"maxResults":32}. If omitted, scans for any non-air blocks.',
4230
- validate: async (runtime, message, state, options) => {
4231
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
4232
- const __avText = __avTextRaw.toLowerCase();
4233
- const __avKeywords = ["scan"];
4234
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
4235
- const __avRegex = /\b(?:scan)\b/i;
4236
- const __avRegexOk = __avRegex.test(__avText);
4237
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
4238
- const __avExpectedSource = "";
4239
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
4240
- const __avOptions = options && typeof options === "object" ? options : {};
4241
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
4242
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
4243
- return false;
4244
- }
4245
- const __avLegacyValidate = async (runtime2) => {
4246
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
4247
- return Boolean(service);
4248
- };
4249
- try {
4250
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
4251
- } catch {
4252
- return false;
4253
- }
4254
- },
4255
- handler: async (runtime, message, _state, _options, callback) => {
4256
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
4257
- if (!service)
4258
- return { text: "Minecraft service is not available", success: false };
4259
- try {
4260
- const params = parseScan(message.content.text ?? "");
4261
- const data = await service.request("scan", {
4262
- ...params.blocks ? { blocks: params.blocks } : {},
4263
- ...typeof params.radius === "number" ? { radius: params.radius } : {},
4264
- ...typeof params.maxResults === "number" ? { maxResults: params.maxResults } : {}
4265
- });
4266
- const blocks = Array.isArray(data.blocks) ? data.blocks : [];
4267
- const content = {
4268
- text: `Scan found ${blocks.length} blocks.`,
4269
- actions: ["MC_SCAN"],
4270
- source: message.content.source
4271
- };
4272
- await callback?.(content);
4273
- return {
4274
- text: content.text ?? "",
4275
- success: true,
4276
- data,
4277
- values: { count: blocks.length }
4278
- };
4279
- } catch (err) {
4280
- const msg = err instanceof Error ? err.message : String(err);
4281
- const content = {
4282
- text: `Scan failed: ${msg}`,
4283
- actions: ["MC_SCAN"],
4284
- source: message.content.source
4285
- };
4286
- await callback?.(content);
4287
- return { text: content.text ?? "", success: false };
4288
- }
4289
- }
4290
- };
4291
- // src/actions/stop.ts
4292
- var minecraftStopAction = {
4293
- name: "MC_STOP",
4294
- similes: ["MINECRAFT_STOP", "STOP_PATHFINDER", "STOP_MOVING"],
4295
- description: "Stop pathfinding / movement goals.",
4296
- validate: async (runtime, message, state, options) => {
4297
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
4298
- const __avText = __avTextRaw.toLowerCase();
4299
- const __avKeywords = ["stop"];
4300
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
4301
- const __avRegex = /\b(?:stop)\b/i;
4302
- const __avRegexOk = __avRegex.test(__avText);
4303
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
4304
- const __avExpectedSource = "";
4305
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
4306
- const __avOptions = options && typeof options === "object" ? options : {};
4307
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
4308
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
4309
- return false;
4310
- }
4311
- const __avLegacyValidate = async (runtime2) => {
4312
- const service = runtime2.getService(MINECRAFT_SERVICE_TYPE);
4313
- return Boolean(service);
4314
- };
4315
- try {
4316
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
4317
- } catch {
4318
- return false;
4319
- }
4320
- },
4321
- handler: async (runtime, message, _state, _options, callback) => {
4322
- const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
4323
- if (!service)
4324
- return { text: "Minecraft service is not available", success: false };
4325
- try {
4326
- await service.request("stop", {});
4327
- const content = {
4328
- text: "Stopped movement.",
4329
- actions: ["MC_STOP"],
4330
- source: message.content.source
4331
- };
4332
- await callback?.(content);
4333
- return { text: content.text ?? "", success: true };
4334
- } catch (err) {
4335
- const msg = err instanceof Error ? err.message : String(err);
4336
- const content = {
4337
- text: `Failed to stop: ${msg}`,
4338
- actions: ["MC_STOP"],
4339
- source: message.content.source
4340
- };
4341
- await callback?.(content);
4342
- return { text: content.text ?? "", success: false };
4343
- }
4344
- }
4345
- };
4346
3531
  // src/services/waypoints-service.ts
4347
3532
  import { ChannelType, MemoryType, Service as Service2, stringToUuid } from "@elizaos/core";
4348
3533
  var WAYPOINTS_SERVICE_TYPE = "minecraft_waypoints";
@@ -4458,14 +3643,14 @@ class WaypointsService extends Service2 {
4458
3643
  unique: true
4459
3644
  };
4460
3645
  }
4461
- async setWaypoint(name, x, y, z9) {
3646
+ async setWaypoint(name, x, y, z3) {
4462
3647
  const key = name.trim().toLowerCase();
4463
3648
  const wp = {
4464
3649
  id: this.waypointIdForKey(key),
4465
3650
  name: name.trim(),
4466
3651
  x,
4467
3652
  y,
4468
- z: z9,
3653
+ z: z3,
4469
3654
  createdAt: new Date
4470
3655
  };
4471
3656
  this.waypoints.set(key, wp);
@@ -4504,243 +3689,536 @@ class WaypointsService extends Service2 {
4504
3689
  }
4505
3690
  }
4506
3691
 
4507
- // src/actions/waypoints.ts
4508
- function parseName(text) {
4509
- const name = text.trim();
4510
- return name.length > 0 ? name : null;
4511
- }
4512
- var minecraftWaypointSetAction = {
4513
- name: "MC_WAYPOINT_SET",
4514
- similes: ["MINECRAFT_WAYPOINT_SET", "SET_WAYPOINT", "SAVE_WAYPOINT"],
4515
- description: "Save the bot's current position as a named waypoint (message text is the name).",
4516
- validate: async (runtime, message, state, options) => {
4517
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
4518
- const __avText = __avTextRaw.toLowerCase();
4519
- const __avKeywords = ["waypoint", "set"];
4520
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
4521
- const __avRegex = /\b(?:waypoint|set)\b/i;
4522
- const __avRegexOk = __avRegex.test(__avText);
4523
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
4524
- const __avExpectedSource = "";
4525
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
4526
- const __avOptions = options && typeof options === "object" ? options : {};
4527
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
4528
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
4529
- return false;
4530
- }
4531
- const __avLegacyValidate = async (runtime2, message2) => {
4532
- return Boolean(runtime2.getService(WAYPOINTS_SERVICE_TYPE)) && Boolean(parseName(message2.content.text ?? ""));
4533
- };
3692
+ // src/actions/utils.ts
3693
+ import { z as z3 } from "zod";
3694
+ var vec3Schema = z3.object({ x: z3.number(), y: z3.number(), z: z3.number() });
3695
+ function extractVec3(text) {
3696
+ const trimmed = text.trim();
3697
+ if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
4534
3698
  try {
4535
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
4536
- } catch {
4537
- return false;
4538
- }
4539
- },
4540
- handler: async (runtime, message, _state, _options, callback) => {
4541
- const waypoints = runtime.getService(WAYPOINTS_SERVICE_TYPE);
4542
- const mc = runtime.getService(MINECRAFT_SERVICE_TYPE);
4543
- const name = parseName(message.content.text ?? "");
4544
- if (!waypoints || !mc)
4545
- return {
4546
- text: "Waypoint or Minecraft service not available",
4547
- success: false
4548
- };
4549
- if (!name)
4550
- return { text: "Missing waypoint name", success: false };
4551
- const ws = await mc.getWorldState();
4552
- const pos = ws.position;
4553
- if (!pos)
4554
- return {
4555
- text: "No position available (is the bot connected?)",
4556
- success: false
4557
- };
4558
- const wp = await waypoints.setWaypoint(name, pos.x, pos.y, pos.z);
4559
- const content = {
4560
- text: `Saved waypoint "${wp.name}" at (${wp.x.toFixed(1)}, ${wp.y.toFixed(1)}, ${wp.z.toFixed(1)}).`,
4561
- actions: ["MC_WAYPOINT_SET"],
4562
- source: message.content.source
4563
- };
4564
- await callback?.(content);
4565
- return {
4566
- text: content.text ?? "",
4567
- success: true,
4568
- data: {
4569
- name: wp.name,
4570
- x: wp.x,
4571
- y: wp.y,
4572
- z: wp.z,
4573
- createdAt: wp.createdAt.toISOString()
4574
- }
4575
- };
3699
+ const parsed = JSON.parse(trimmed);
3700
+ const v = vec3Schema.parse(parsed);
3701
+ return v;
3702
+ } catch {}
4576
3703
  }
4577
- };
4578
- var minecraftWaypointDeleteAction = {
4579
- name: "MC_WAYPOINT_DELETE",
4580
- similes: ["MINECRAFT_WAYPOINT_DELETE", "DELETE_WAYPOINT", "REMOVE_WAYPOINT"],
4581
- description: "Delete a named waypoint (message text is the name).",
4582
- validate: async (runtime, message, state, options) => {
4583
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
4584
- const __avText = __avTextRaw.toLowerCase();
4585
- const __avKeywords = ["waypoint", "delete"];
4586
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
4587
- const __avRegex = /\b(?:waypoint|delete)\b/i;
4588
- const __avRegexOk = __avRegex.test(__avText);
4589
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
4590
- const __avExpectedSource = "";
4591
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
4592
- const __avOptions = options && typeof options === "object" ? options : {};
4593
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
4594
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
4595
- return false;
4596
- }
4597
- const __avLegacyValidate = async (runtime2, message2) => {
4598
- return Boolean(runtime2.getService(WAYPOINTS_SERVICE_TYPE)) && Boolean(parseName(message2.content.text ?? ""));
4599
- };
4600
- try {
4601
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
4602
- } catch {
4603
- return false;
3704
+ const m = trimmed.match(/(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/);
3705
+ if (!m)
3706
+ return null;
3707
+ const x = Number(m[1]);
3708
+ const y = Number(m[2]);
3709
+ const z4 = Number(m[3]);
3710
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z4))
3711
+ return null;
3712
+ return { x, y, z: z4 };
3713
+ }
3714
+
3715
+ // src/actions/helpers.ts
3716
+ var MINECRAFT_ACTION_TIMEOUT_MS = 15000;
3717
+ var MAX_MINECRAFT_TEXT_LENGTH = 2000;
3718
+ function isRecord(value) {
3719
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
3720
+ }
3721
+ function parseJsonObject(text) {
3722
+ const trimmed = text.trim();
3723
+ if (!trimmed.startsWith("{") || !trimmed.endsWith("}"))
3724
+ return {};
3725
+ try {
3726
+ const parsed = JSON.parse(trimmed);
3727
+ return isRecord(parsed) ? parsed : {};
3728
+ } catch {
3729
+ return {};
3730
+ }
3731
+ }
3732
+ function readParams(options) {
3733
+ const maybe = isRecord(options) && isRecord(options.parameters) ? options.parameters : {};
3734
+ return maybe;
3735
+ }
3736
+ function mergedInput(message, options) {
3737
+ return {
3738
+ ...parseJsonObject(message.content.text ?? ""),
3739
+ ...readParams(options)
3740
+ };
3741
+ }
3742
+ function readString(params, ...keys) {
3743
+ for (const key of keys) {
3744
+ const value = params[key];
3745
+ if (typeof value === "string" && value.trim())
3746
+ return value.trim();
3747
+ }
3748
+ return null;
3749
+ }
3750
+ function readNumber(params, ...keys) {
3751
+ for (const key of keys) {
3752
+ const value = params[key];
3753
+ if (typeof value === "number" && Number.isFinite(value))
3754
+ return value;
3755
+ if (typeof value === "string" && value.trim()) {
3756
+ const parsed = Number(value);
3757
+ if (Number.isFinite(parsed))
3758
+ return parsed;
3759
+ }
3760
+ }
3761
+ return null;
3762
+ }
3763
+ function readBoolean(params, ...keys) {
3764
+ for (const key of keys) {
3765
+ const value = params[key];
3766
+ if (typeof value === "boolean")
3767
+ return value;
3768
+ if (typeof value === "string") {
3769
+ const normalized = value.trim().toLowerCase();
3770
+ if (normalized === "true")
3771
+ return true;
3772
+ if (normalized === "false")
3773
+ return false;
4604
3774
  }
4605
- },
4606
- handler: async (runtime, message, _state, _options, callback) => {
4607
- const waypoints = runtime.getService(WAYPOINTS_SERVICE_TYPE);
4608
- const name = parseName(message.content.text ?? "");
4609
- if (!waypoints)
4610
- return { text: "Waypoints service not available", success: false };
4611
- if (!name)
4612
- return { text: "Missing waypoint name", success: false };
4613
- const deleted = await waypoints.deleteWaypoint(name);
4614
- const content = {
4615
- text: deleted ? `Deleted waypoint "${name}".` : `No waypoint named "${name}".`,
4616
- actions: ["MC_WAYPOINT_DELETE"],
4617
- source: message.content.source
4618
- };
4619
- await callback?.(content);
4620
- return { text: content.text ?? "", success: deleted, values: { deleted } };
4621
3775
  }
4622
- };
4623
- var minecraftWaypointListAction = {
4624
- name: "MC_WAYPOINT_LIST",
4625
- similes: ["MINECRAFT_WAYPOINT_LIST", "LIST_WAYPOINTS", "SHOW_WAYPOINTS"],
4626
- description: "List saved waypoints.",
4627
- validate: async (runtime, message, state, options) => {
4628
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
4629
- const __avText = __avTextRaw.toLowerCase();
4630
- const __avKeywords = ["waypoint", "list"];
4631
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
4632
- const __avRegex = /\b(?:waypoint|list)\b/i;
4633
- const __avRegexOk = __avRegex.test(__avText);
4634
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
4635
- const __avExpectedSource = "";
4636
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
4637
- const __avOptions = options && typeof options === "object" ? options : {};
4638
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
4639
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
4640
- return false;
4641
- }
4642
- const __avLegacyValidate = async (runtime2) => {
4643
- return Boolean(runtime2.getService(WAYPOINTS_SERVICE_TYPE));
4644
- };
4645
- try {
4646
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
4647
- } catch {
4648
- return false;
3776
+ return null;
3777
+ }
3778
+ function parseVec3(params, text) {
3779
+ const x = readNumber(params, "x");
3780
+ const y = readNumber(params, "y");
3781
+ const z4 = readNumber(params, "z");
3782
+ if (x !== null && y !== null && z4 !== null)
3783
+ return { x, y, z: z4 };
3784
+ return extractVec3(text);
3785
+ }
3786
+ function isPlaceFace(value) {
3787
+ return value === "up" || value === "down" || value === "north" || value === "south" || value === "east" || value === "west";
3788
+ }
3789
+ function callbackContent(actionName, text, source) {
3790
+ return {
3791
+ text,
3792
+ actions: [actionName],
3793
+ source: typeof source === "string" ? source : undefined
3794
+ };
3795
+ }
3796
+ async function emit(actionName, callback, text, source, result) {
3797
+ const content = callbackContent(actionName, text.slice(0, MAX_MINECRAFT_TEXT_LENGTH), source);
3798
+ await callback?.(content, actionName);
3799
+ return { text: content.text ?? text, ...result };
3800
+ }
3801
+ async function withMinecraftTimeout(promise, label) {
3802
+ return Promise.race([
3803
+ promise,
3804
+ new Promise((_, reject) => setTimeout(() => reject(new Error(`${label} timed out`)), MINECRAFT_ACTION_TIMEOUT_MS))
3805
+ ]);
3806
+ }
3807
+
3808
+ // src/actions/mc.ts
3809
+ var ACTION_NAME = "MC";
3810
+ var MC_OPS = [
3811
+ "connect",
3812
+ "disconnect",
3813
+ "goto",
3814
+ "stop",
3815
+ "look",
3816
+ "control",
3817
+ "waypoint_goto",
3818
+ "dig",
3819
+ "place",
3820
+ "chat",
3821
+ "attack",
3822
+ "waypoint_set",
3823
+ "waypoint_delete"
3824
+ ];
3825
+ function normalizeOp(value) {
3826
+ if (typeof value !== "string")
3827
+ return null;
3828
+ const normalized = value.trim().replace(/[\s-]+/g, "_").toLowerCase();
3829
+ switch (normalized) {
3830
+ case "connect":
3831
+ case "join":
3832
+ case "mc_connect":
3833
+ return "connect";
3834
+ case "disconnect":
3835
+ case "leave":
3836
+ case "quit":
3837
+ case "mc_disconnect":
3838
+ return "disconnect";
3839
+ case "goto":
3840
+ case "go_to":
3841
+ case "move":
3842
+ case "walk":
3843
+ case "pathfind":
3844
+ return "goto";
3845
+ case "stop":
3846
+ case "cancel":
3847
+ return "stop";
3848
+ case "look":
3849
+ case "view":
3850
+ case "turn":
3851
+ return "look";
3852
+ case "control":
3853
+ case "press":
3854
+ case "key":
3855
+ return "control";
3856
+ case "waypoint_goto":
3857
+ case "waypointgoto":
3858
+ case "navigate":
3859
+ return "waypoint_goto";
3860
+ case "dig":
3861
+ case "mine":
3862
+ case "break":
3863
+ return "dig";
3864
+ case "place":
3865
+ case "build":
3866
+ return "place";
3867
+ case "chat":
3868
+ case "say":
3869
+ case "tell":
3870
+ case "message":
3871
+ case "mc_chat":
3872
+ return "chat";
3873
+ case "attack":
3874
+ case "hit":
3875
+ case "mc_attack":
3876
+ return "attack";
3877
+ case "waypoint_set":
3878
+ case "waypointset":
3879
+ case "save_waypoint":
3880
+ return "waypoint_set";
3881
+ case "waypoint_delete":
3882
+ case "waypointdelete":
3883
+ case "delete_waypoint":
3884
+ return "waypoint_delete";
3885
+ default:
3886
+ return MC_OPS.includes(normalized) ? normalized : null;
3887
+ }
3888
+ }
3889
+ function parseConnectOverrides(params) {
3890
+ const out = {};
3891
+ const host = readString(params, "host");
3892
+ const port = readNumber(params, "port");
3893
+ const username = readString(params, "username");
3894
+ const auth = readString(params, "auth");
3895
+ const version = readString(params, "version");
3896
+ if (host)
3897
+ out.host = host;
3898
+ if (port !== null && Number.isInteger(port) && port > 0)
3899
+ out.port = port;
3900
+ if (username)
3901
+ out.username = username;
3902
+ if (auth === "offline" || auth === "microsoft")
3903
+ out.auth = auth;
3904
+ if (version)
3905
+ out.version = version;
3906
+ return out;
3907
+ }
3908
+ function parseControl(params, text) {
3909
+ const control = readString(params, "control", "key", "direction");
3910
+ const state = readBoolean(params, "state", "pressed", "enabled");
3911
+ const durationMs = readNumber(params, "durationMs", "duration");
3912
+ if (control && state !== null) {
3913
+ return durationMs && durationMs > 0 ? { control, state, durationMs } : { control, state };
3914
+ }
3915
+ const match = text.trim().match(/^(\S+)\s+(true|false)(?:\s+(\d+))?$/i);
3916
+ if (!match)
3917
+ return null;
3918
+ const parsedDuration = match[3] ? Number(match[3]) : undefined;
3919
+ if (parsedDuration !== undefined && !Number.isFinite(parsedDuration))
3920
+ return null;
3921
+ return parsedDuration ? {
3922
+ control: match[1],
3923
+ state: match[2].toLowerCase() === "true",
3924
+ durationMs: parsedDuration
3925
+ } : { control: match[1], state: match[2].toLowerCase() === "true" };
3926
+ }
3927
+ function parseLook(params, text) {
3928
+ const yaw = readNumber(params, "yaw");
3929
+ const pitch = readNumber(params, "pitch");
3930
+ if (yaw !== null && pitch !== null)
3931
+ return { yaw, pitch };
3932
+ const match = text.trim().match(/(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/);
3933
+ if (!match)
3934
+ return null;
3935
+ const parsedYaw = Number(match[1]);
3936
+ const parsedPitch = Number(match[2]);
3937
+ if (!Number.isFinite(parsedYaw) || !Number.isFinite(parsedPitch))
3938
+ return null;
3939
+ return { yaw: parsedYaw, pitch: parsedPitch };
3940
+ }
3941
+ function parseWaypointName(text, params) {
3942
+ const explicit = readString(params, "name", "waypointName", "waypoint", "target");
3943
+ if (explicit)
3944
+ return explicit;
3945
+ const stripped = text.trim().replace(/\b(?:minecraft|mc|waypoints?|set|save|create|delete|remove|goto|go to|navigate|to)\b/gi, " ").replace(/\s+/g, " ").trim();
3946
+ return stripped || null;
3947
+ }
3948
+ function parsePlaceFace(params, text) {
3949
+ const explicit = readString(params, "face");
3950
+ if (isPlaceFace(explicit))
3951
+ return explicit;
3952
+ const match = text.trim().match(/\b(up|down|north|south|east|west)\b/i);
3953
+ if (!match)
3954
+ return null;
3955
+ const candidate = match[1].toLowerCase();
3956
+ return isPlaceFace(candidate) ? candidate : null;
3957
+ }
3958
+ function parseEntityId(params, text) {
3959
+ const fromParams = readNumber(params, "entityId", "entity");
3960
+ if (fromParams !== null)
3961
+ return fromParams;
3962
+ const match = text.trim().match(/\b(?:entity\s*)?(\d+)\b/i);
3963
+ if (!match)
3964
+ return null;
3965
+ const entityId = Number(match[1]);
3966
+ return Number.isFinite(entityId) ? entityId : null;
3967
+ }
3968
+ var MC_SIMILES = [
3969
+ "MC_ATTACK",
3970
+ "MC_HIT",
3971
+ "MC_BLOCK",
3972
+ "MC_DIG",
3973
+ "MC_PLACE",
3974
+ "MC_BUILD",
3975
+ "MC_MINE",
3976
+ "MC_CHAT",
3977
+ "MC_SAY",
3978
+ "MC_MESSAGE",
3979
+ "MC_CONNECT",
3980
+ "MC_JOIN",
3981
+ "MINECRAFT_CONNECT",
3982
+ "MC_DISCONNECT",
3983
+ "MC_LEAVE",
3984
+ "MC_QUIT",
3985
+ "MC_LOCOMOTE",
3986
+ "MC_MOVE",
3987
+ "MC_GOTO",
3988
+ "MC_STOP",
3989
+ "MC_LOOK",
3990
+ "MC_CONTROL",
3991
+ "MC_WAYPOINT",
3992
+ "MC_WAYPOINT_SET",
3993
+ "MC_WAYPOINT_DELETE",
3994
+ "MC_WAYPOINT_GOTO"
3995
+ ];
3996
+ var minecraftAction = {
3997
+ name: ACTION_NAME,
3998
+ contexts: ["connectors", "automation", "media", "messaging", "memory"],
3999
+ contextGate: {
4000
+ anyOf: ["connectors", "automation", "media", "messaging", "memory"]
4001
+ },
4002
+ roleGate: { minRole: "USER" },
4003
+ similes: MC_SIMILES,
4004
+ description: "Drive a Minecraft bot. Choose one op: connect (host?,port?,username?,auth?,version?), disconnect, goto (x,y,z), stop, look (yaw,pitch), control (control,state,durationMs?), waypoint_goto (name), dig (x,y,z), place (x,y,z,face), chat (message), attack (entityId), waypoint_set (name), waypoint_delete (name).",
4005
+ descriptionCompressed: "minecraft ops: connect|disconnect|goto|stop|look|control|waypoint_*|dig|place|chat|attack",
4006
+ parameters: [
4007
+ {
4008
+ name: "subaction",
4009
+ description: "Operation to run.",
4010
+ descriptionCompressed: "Op.",
4011
+ required: true,
4012
+ schema: { type: "string", enum: MC_OPS }
4013
+ },
4014
+ {
4015
+ name: "params",
4016
+ description: "Optional JSON object containing the fields required by the chosen op.",
4017
+ descriptionCompressed: "Op fields.",
4018
+ required: false,
4019
+ schema: { type: "object" }
4649
4020
  }
4021
+ ],
4022
+ validate: async (runtime, _message, _state) => {
4023
+ return runtime.getService(MINECRAFT_SERVICE_TYPE) != null;
4650
4024
  },
4651
- handler: async (runtime, message, _state, _options, callback) => {
4652
- const waypoints = runtime.getService(WAYPOINTS_SERVICE_TYPE);
4653
- if (!waypoints)
4654
- return { text: "Waypoints service not available", success: false };
4655
- const list = waypoints.listWaypoints();
4656
- const lines = list.map((w) => `- ${w.name}: (${w.x.toFixed(1)}, ${w.y.toFixed(1)}, ${w.z.toFixed(1)})`);
4657
- const content = {
4658
- text: list.length ? `Waypoints:
4659
- ${lines.join(`
4660
- `)}` : "No waypoints saved.",
4661
- actions: ["MC_WAYPOINT_LIST"],
4662
- source: message.content.source
4663
- };
4664
- await callback?.(content);
4665
- return {
4666
- text: content.text ?? "",
4667
- success: true,
4668
- data: {
4669
- waypoints: list.map((w) => ({
4670
- name: w.name,
4671
- x: w.x,
4672
- y: w.y,
4673
- z: w.z,
4674
- createdAt: w.createdAt.toISOString()
4675
- }))
4676
- }
4677
- };
4678
- }
4679
- };
4680
- var minecraftWaypointGotoAction = {
4681
- name: "MC_WAYPOINT_GOTO",
4682
- similes: ["MINECRAFT_WAYPOINT_GOTO", "GOTO_WAYPOINT", "NAVIGATE_WAYPOINT"],
4683
- description: "Pathfind to a named waypoint (message text is the name).",
4684
- validate: async (runtime, message, state, options) => {
4685
- const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
4686
- const __avText = __avTextRaw.toLowerCase();
4687
- const __avKeywords = ["waypoint", "goto"];
4688
- const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
4689
- const __avRegex = /\b(?:waypoint|goto)\b/i;
4690
- const __avRegexOk = __avRegex.test(__avText);
4691
- const __avSource = String(message?.content?.source ?? message?.source ?? "");
4692
- const __avExpectedSource = "";
4693
- const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
4694
- const __avOptions = options && typeof options === "object" ? options : {};
4695
- const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
4696
- if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
4697
- return false;
4698
- }
4699
- const __avLegacyValidate = async (runtime2, message2) => {
4700
- return Boolean(runtime2.getService(WAYPOINTS_SERVICE_TYPE)) && Boolean(runtime2.getService(MINECRAFT_SERVICE_TYPE)) && Boolean(parseName(message2.content.text ?? ""));
4701
- };
4025
+ handler: async (runtime, message, _state, options, callback) => {
4026
+ const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
4027
+ if (!service)
4028
+ return { text: "Minecraft service is not available", success: false };
4029
+ const params = mergedInput(message, options);
4030
+ const text = message.content.text ?? "";
4031
+ const op = normalizeOp(params.op ?? params.subaction ?? params.actionType ?? params.type);
4032
+ if (!op) {
4033
+ return emit(ACTION_NAME, callback, `MC requires an op: one of ${MC_OPS.join("|")}.`, message.content.source, { success: false });
4034
+ }
4702
4035
  try {
4703
- return Boolean(await __avLegacyValidate(runtime, message, state, options));
4704
- } catch {
4705
- return false;
4036
+ switch (op) {
4037
+ case "connect": {
4038
+ const session = await withMinecraftTimeout(service.createBot(parseConnectOverrides(params)), "minecraft connect");
4039
+ return await emit(ACTION_NAME, callback, `Connected Minecraft bot (botId=${session.botId}).`, message.content.source, {
4040
+ success: true,
4041
+ data: { botId: session.botId },
4042
+ values: { connected: true }
4043
+ });
4044
+ }
4045
+ case "disconnect": {
4046
+ const session = service.getCurrentSession();
4047
+ if (!session) {
4048
+ return emit(ACTION_NAME, callback, "No Minecraft bot is connected.", message.content.source, { success: false });
4049
+ }
4050
+ await withMinecraftTimeout(service.destroyBot(session.botId), "minecraft disconnect");
4051
+ return await emit(ACTION_NAME, callback, "Disconnected Minecraft bot.", message.content.source, { success: true, values: { connected: false } });
4052
+ }
4053
+ case "stop": {
4054
+ await withMinecraftTimeout(service.request("stop", {}), "minecraft stop");
4055
+ return await emit(ACTION_NAME, callback, "Stopped movement.", message.content.source, {
4056
+ success: true
4057
+ });
4058
+ }
4059
+ case "goto": {
4060
+ const vec = parseVec3(params, text);
4061
+ if (!vec) {
4062
+ return emit(ACTION_NAME, callback, "Missing coordinates (x y z).", message.content.source, { success: false });
4063
+ }
4064
+ await withMinecraftTimeout(service.request("goto", { x: vec.x, y: vec.y, z: vec.z }), "minecraft goto");
4065
+ return await emit(ACTION_NAME, callback, `Moving to (${vec.x}, ${vec.y}, ${vec.z}).`, message.content.source, { success: true });
4066
+ }
4067
+ case "look": {
4068
+ const req = parseLook(params, text);
4069
+ if (!req) {
4070
+ return emit(ACTION_NAME, callback, "Missing yaw/pitch.", message.content.source, {
4071
+ success: false
4072
+ });
4073
+ }
4074
+ await withMinecraftTimeout(service.request("look", { yaw: req.yaw, pitch: req.pitch }), "minecraft look");
4075
+ return await emit(ACTION_NAME, callback, "Adjusted view.", message.content.source, {
4076
+ success: true
4077
+ });
4078
+ }
4079
+ case "control": {
4080
+ const req = parseControl(params, text);
4081
+ if (!req) {
4082
+ return emit(ACTION_NAME, callback, "Missing control command.", message.content.source, {
4083
+ success: false
4084
+ });
4085
+ }
4086
+ await withMinecraftTimeout(service.request("control", {
4087
+ control: req.control,
4088
+ state: req.state,
4089
+ ...typeof req.durationMs === "number" ? { durationMs: Math.min(req.durationMs, 1e4) } : {}
4090
+ }), "minecraft control");
4091
+ return await emit(ACTION_NAME, callback, `Set control ${req.control}=${String(req.state)}${req.durationMs ? ` for ${req.durationMs}ms` : ""}.`, message.content.source, { success: true });
4092
+ }
4093
+ case "waypoint_goto": {
4094
+ const waypoints = runtime.getService(WAYPOINTS_SERVICE_TYPE);
4095
+ if (!waypoints) {
4096
+ return emit(ACTION_NAME, callback, "Waypoints service not available.", message.content.source, { success: false });
4097
+ }
4098
+ const name = parseWaypointName(text, params);
4099
+ if (!name) {
4100
+ return emit(ACTION_NAME, callback, "Missing waypoint name.", message.content.source, {
4101
+ success: false
4102
+ });
4103
+ }
4104
+ const wp = waypoints.getWaypoint(name);
4105
+ if (!wp) {
4106
+ return emit(ACTION_NAME, callback, `No waypoint named "${name}".`, message.content.source, { success: false });
4107
+ }
4108
+ await withMinecraftTimeout(service.request("goto", { x: wp.x, y: wp.y, z: wp.z }), "minecraft waypoint goto");
4109
+ return await emit(ACTION_NAME, callback, `Navigating to waypoint "${wp.name}" at (${wp.x.toFixed(1)}, ${wp.y.toFixed(1)}, ${wp.z.toFixed(1)}).`, message.content.source, { success: true });
4110
+ }
4111
+ case "dig": {
4112
+ const vec = parseVec3(params, text);
4113
+ if (!vec) {
4114
+ return emit(ACTION_NAME, callback, "Missing coordinates (x y z).", message.content.source, { success: false });
4115
+ }
4116
+ const data = await withMinecraftTimeout(service.request("dig", { x: vec.x, y: vec.y, z: vec.z }), "minecraft dig");
4117
+ const blockName = typeof data.blockName === "string" ? data.blockName : "block";
4118
+ return await emit(ACTION_NAME, callback, `Dug ${blockName} at (${vec.x}, ${vec.y}, ${vec.z}).`, message.content.source, { success: true, data });
4119
+ }
4120
+ case "place": {
4121
+ const vec = parseVec3(params, text);
4122
+ if (!vec) {
4123
+ return emit(ACTION_NAME, callback, "Missing coordinates (x y z).", message.content.source, { success: false });
4124
+ }
4125
+ const face = parsePlaceFace(params, text);
4126
+ if (!face) {
4127
+ return emit(ACTION_NAME, callback, "Missing placement face (up/down/north/south/east/west).", message.content.source, { success: false });
4128
+ }
4129
+ await withMinecraftTimeout(service.request("place", { x: vec.x, y: vec.y, z: vec.z, face }), "minecraft place");
4130
+ return await emit(ACTION_NAME, callback, `Placed block at (${vec.x}, ${vec.y}, ${vec.z}) face=${face}.`, message.content.source, { success: true });
4131
+ }
4132
+ case "chat": {
4133
+ const msg = readString(params, "message", "text") ?? text.trim();
4134
+ if (!msg) {
4135
+ return emit(ACTION_NAME, callback, "No chat message provided.", message.content.source, { success: false });
4136
+ }
4137
+ const maxChatPreviewLength = 500;
4138
+ await withMinecraftTimeout(service.chat(msg), "minecraft chat");
4139
+ return await emit(ACTION_NAME, callback, `Sent Minecraft chat: ${msg.slice(0, maxChatPreviewLength)}`, message.content.source, { success: true, values: { sent: true } });
4140
+ }
4141
+ case "attack": {
4142
+ const entityId = parseEntityId(params, text);
4143
+ if (entityId === null) {
4144
+ return emit(ACTION_NAME, callback, "Missing entityId.", message.content.source, {
4145
+ success: false
4146
+ });
4147
+ }
4148
+ await withMinecraftTimeout(service.request("attack", { entityId }), "minecraft attack");
4149
+ return await emit(ACTION_NAME, callback, `Attacked entity ${entityId}.`, message.content.source, { success: true });
4150
+ }
4151
+ case "waypoint_set": {
4152
+ const waypoints = runtime.getService(WAYPOINTS_SERVICE_TYPE);
4153
+ if (!waypoints) {
4154
+ return emit(ACTION_NAME, callback, "Waypoints service not available.", message.content.source, { success: false });
4155
+ }
4156
+ const name = parseWaypointName(text, params);
4157
+ if (!name) {
4158
+ return emit(ACTION_NAME, callback, "Missing waypoint name.", message.content.source, {
4159
+ success: false
4160
+ });
4161
+ }
4162
+ const worldState = await withMinecraftTimeout(service.getWorldState(), "minecraft world state");
4163
+ const pos = worldState.position;
4164
+ if (!pos) {
4165
+ return emit(ACTION_NAME, callback, "No position available (is the bot connected?).", message.content.source, { success: false });
4166
+ }
4167
+ const wp = await waypoints.setWaypoint(name, pos.x, pos.y, pos.z);
4168
+ return await emit(ACTION_NAME, callback, `Saved waypoint "${wp.name}" at (${wp.x.toFixed(1)}, ${wp.y.toFixed(1)}, ${wp.z.toFixed(1)}).`, message.content.source, {
4169
+ success: true,
4170
+ data: {
4171
+ name: wp.name,
4172
+ x: wp.x,
4173
+ y: wp.y,
4174
+ z: wp.z,
4175
+ createdAt: wp.createdAt.toISOString()
4176
+ }
4177
+ });
4178
+ }
4179
+ case "waypoint_delete": {
4180
+ const waypoints = runtime.getService(WAYPOINTS_SERVICE_TYPE);
4181
+ if (!waypoints) {
4182
+ return emit(ACTION_NAME, callback, "Waypoints service not available.", message.content.source, { success: false });
4183
+ }
4184
+ const name = parseWaypointName(text, params);
4185
+ if (!name) {
4186
+ return emit(ACTION_NAME, callback, "Missing waypoint name.", message.content.source, {
4187
+ success: false
4188
+ });
4189
+ }
4190
+ const deleted = await waypoints.deleteWaypoint(name);
4191
+ return await emit(ACTION_NAME, callback, deleted ? `Deleted waypoint "${name}".` : `No waypoint named "${name}".`, message.content.source, { success: deleted, values: { deleted } });
4192
+ }
4193
+ default: {
4194
+ const _exhaustive = op;
4195
+ return emit(ACTION_NAME, callback, "Unknown MC op.", message.content.source, {
4196
+ success: false
4197
+ });
4198
+ }
4199
+ }
4200
+ } catch (err) {
4201
+ const msg = err instanceof Error ? err.message : String(err);
4202
+ return emit(ACTION_NAME, callback, `MC ${op} failed: ${msg}`, message.content.source, {
4203
+ success: false,
4204
+ data: { error: msg }
4205
+ });
4706
4206
  }
4707
4207
  },
4708
- handler: async (runtime, message, _state, _options, callback) => {
4709
- const waypoints = runtime.getService(WAYPOINTS_SERVICE_TYPE);
4710
- const mc = runtime.getService(MINECRAFT_SERVICE_TYPE);
4711
- const name = parseName(message.content.text ?? "");
4712
- if (!waypoints || !mc)
4713
- return {
4714
- text: "Waypoint or Minecraft service not available",
4715
- success: false
4716
- };
4717
- if (!name)
4718
- return { text: "Missing waypoint name", success: false };
4719
- const wp = waypoints.getWaypoint(name);
4720
- if (!wp) {
4721
- const content2 = {
4722
- text: `No waypoint named "${name}".`,
4723
- actions: ["MC_WAYPOINT_GOTO"],
4724
- source: message.content.source
4725
- };
4726
- await callback?.(content2);
4727
- return { text: content2.text ?? "", success: false };
4728
- }
4729
- await mc.request("goto", { x: wp.x, y: wp.y, z: wp.z });
4730
- const content = {
4731
- text: `Navigating to waypoint "${wp.name}" at (${wp.x.toFixed(1)}, ${wp.y.toFixed(1)}, ${wp.z.toFixed(1)}).`,
4732
- actions: ["MC_WAYPOINT_GOTO"],
4733
- source: message.content.source
4734
- };
4735
- await callback?.(content);
4736
- return { text: content.text ?? "", success: true };
4737
- }
4208
+ examples: []
4738
4209
  };
4739
4210
  // src/providers/vision.ts
4211
+ var MAX_NEARBY_ENTITIES_IN_STATE = 24;
4212
+ var MAX_NEARBY_BLOCKS_IN_STATE = 24;
4740
4213
  var minecraftVisionProvider = {
4741
4214
  name: "MC_VISION",
4742
4215
  description: "Semantic environment context: biome, what I'm looking at, key nearby blocks (logs/ores), nearby entities",
4216
+ descriptionCompressed: "Read live Minecraft biome, looked-at block, nearby blocks, and nearby entities.",
4743
4217
  dynamic: true,
4218
+ contexts: ["automation", "agent_internal"],
4219
+ contextGate: { anyOf: ["automation", "agent_internal"] },
4220
+ cacheStable: false,
4221
+ cacheScope: "turn",
4744
4222
  get: async (runtime, _message, _state) => {
4745
4223
  const mc = runtime.getService(MINECRAFT_SERVICE_TYPE);
4746
4224
  if (!mc) {
@@ -4750,68 +4228,84 @@ var minecraftVisionProvider = {
4750
4228
  data: {}
4751
4229
  };
4752
4230
  }
4753
- const ws = await mc.getWorldState();
4754
- if (!ws.connected) {
4231
+ try {
4232
+ const ws = await mc.getWorldState();
4233
+ if (!ws.connected) {
4234
+ return {
4235
+ text: "Minecraft bot not connected",
4236
+ values: { connected: false },
4237
+ data: {}
4238
+ };
4239
+ }
4240
+ const scan = await mc.request("scan", {
4241
+ blocks: [
4242
+ "oak_log",
4243
+ "spruce_log",
4244
+ "birch_log",
4245
+ "jungle_log",
4246
+ "acacia_log",
4247
+ "dark_oak_log",
4248
+ "stone",
4249
+ "coal_ore",
4250
+ "iron_ore"
4251
+ ],
4252
+ radius: 16,
4253
+ maxResults: MAX_NEARBY_BLOCKS_IN_STATE
4254
+ });
4255
+ const blocks = Array.isArray(scan.blocks) ? scan.blocks.slice(0, MAX_NEARBY_BLOCKS_IN_STATE) : [];
4256
+ const nearbyEntities = Array.isArray(ws.nearbyEntities) ? ws.nearbyEntities.slice(0, MAX_NEARBY_ENTITIES_IN_STATE) : [];
4257
+ const pos = ws.position ? `(${ws.position.x.toFixed(1)}, ${ws.position.y.toFixed(1)}, ${ws.position.z.toFixed(1)})` : "(unknown)";
4258
+ const biomeName = ws.biome && typeof ws.biome === "object" && "name" in ws.biome && typeof ws.biome.name === "string" ? ws.biome.name : null;
4259
+ const lookingAt = ws.lookingAt;
4260
+ const laName = lookingAt && typeof lookingAt.name === "string" ? lookingAt.name : null;
4261
+ const laPos = lookingAt?.position ? {
4262
+ x: typeof lookingAt.position.x === "number" ? lookingAt.position.x : null,
4263
+ y: typeof lookingAt.position.y === "number" ? lookingAt.position.y : null,
4264
+ z: typeof lookingAt.position.z === "number" ? lookingAt.position.z : null
4265
+ } : null;
4266
+ const lookingText = laName && laPos && laPos.x !== null && laPos.y !== null && laPos.z !== null ? `Looking at: ${laName} at (${laPos.x}, ${laPos.y}, ${laPos.z})` : "Looking at: (unknown)";
4267
+ const entityCount = Array.isArray(ws.nearbyEntities) ? ws.nearbyEntities.length : 0;
4755
4268
  return {
4756
- text: "Minecraft bot not connected",
4757
- values: { connected: false },
4758
- data: {}
4759
- };
4760
- }
4761
- const scan = await mc.request("scan", {
4762
- blocks: [
4763
- "oak_log",
4764
- "spruce_log",
4765
- "birch_log",
4766
- "jungle_log",
4767
- "acacia_log",
4768
- "dark_oak_log",
4769
- "stone",
4770
- "coal_ore",
4771
- "iron_ore"
4772
- ],
4773
- radius: 16,
4774
- maxResults: 24
4775
- });
4776
- const blocks = Array.isArray(scan.blocks) ? scan.blocks : [];
4777
- const pos = ws.position ? `(${ws.position.x.toFixed(1)}, ${ws.position.y.toFixed(1)}, ${ws.position.z.toFixed(1)})` : "(unknown)";
4778
- const biomeName = ws.biome && typeof ws.biome === "object" && "name" in ws.biome && typeof ws.biome.name === "string" ? ws.biome.name : null;
4779
- const lookingAt = ws.lookingAt;
4780
- const laName = lookingAt && typeof lookingAt.name === "string" ? lookingAt.name : null;
4781
- const laPos = lookingAt?.position ? {
4782
- x: typeof lookingAt.position.x === "number" ? lookingAt.position.x : null,
4783
- y: typeof lookingAt.position.y === "number" ? lookingAt.position.y : null,
4784
- z: typeof lookingAt.position.z === "number" ? lookingAt.position.z : null
4785
- } : null;
4786
- const lookingText = laName && laPos && laPos.x !== null && laPos.y !== null && laPos.z !== null ? `Looking at: ${laName} at (${laPos.x}, ${laPos.y}, ${laPos.z})` : "Looking at: (unknown)";
4787
- const entityCount = Array.isArray(ws.nearbyEntities) ? ws.nearbyEntities.length : 0;
4788
- return {
4789
- text: `Biome: ${biomeName ?? "unknown"}
4269
+ text: `Biome: ${biomeName ?? "unknown"}
4790
4270
  Position: ${pos}
4791
4271
  ${lookingText}
4792
4272
  NearbyEntities: ${entityCount}
4793
4273
  NearbyBlocksFound: ${blocks.length}`,
4794
- values: {
4795
- connected: true,
4796
- biome: biomeName ?? null,
4797
- entityCount,
4798
- blocksFound: blocks.length
4799
- },
4800
- data: {
4801
- biome: ws.biome ?? null,
4802
- position: ws.position ?? null,
4803
- lookingAt: ws.lookingAt ?? null,
4804
- nearbyEntities: ws.nearbyEntities ?? [],
4805
- nearbyBlocks: blocks
4806
- }
4807
- };
4274
+ values: {
4275
+ connected: true,
4276
+ biome: biomeName ?? null,
4277
+ entityCount,
4278
+ shownEntityCount: nearbyEntities.length,
4279
+ blocksFound: blocks.length
4280
+ },
4281
+ data: {
4282
+ biome: ws.biome ?? null,
4283
+ position: ws.position ?? null,
4284
+ lookingAt: ws.lookingAt ?? null,
4285
+ nearbyEntities,
4286
+ nearbyBlocks: blocks
4287
+ }
4288
+ };
4289
+ } catch (error) {
4290
+ return {
4291
+ text: "Unable to load Minecraft vision context",
4292
+ values: { connected: false, error: true },
4293
+ data: { error: error instanceof Error ? error.message : String(error) }
4294
+ };
4295
+ }
4808
4296
  }
4809
4297
  };
4810
4298
  // src/providers/waypoints.ts
4299
+ var MAX_WAYPOINTS_IN_STATE = 50;
4811
4300
  var minecraftWaypointsProvider = {
4812
4301
  name: "MC_WAYPOINTS",
4813
4302
  description: "Saved Minecraft waypoints (names and coordinates)",
4303
+ descriptionCompressed: "List saved Minecraft waypoint names and coordinates.",
4814
4304
  dynamic: true,
4305
+ contexts: ["automation", "agent_internal"],
4306
+ contextGate: { anyOf: ["automation", "agent_internal"] },
4307
+ cacheStable: false,
4308
+ cacheScope: "turn",
4815
4309
  get: async (runtime, _message, _state) => {
4816
4310
  const service = runtime.getService(WAYPOINTS_SERVICE_TYPE);
4817
4311
  if (!service) {
@@ -4821,31 +4315,98 @@ var minecraftWaypointsProvider = {
4821
4315
  data: { waypoints: [] }
4822
4316
  };
4823
4317
  }
4824
- const list = service.listWaypoints();
4825
- const lines = list.map((w) => `- ${w.name}: (${w.x.toFixed(1)}, ${w.y.toFixed(1)}, ${w.z.toFixed(1)})`);
4826
- return {
4827
- text: list.length ? `Waypoints:
4318
+ try {
4319
+ const list = service.listWaypoints();
4320
+ const shown = list.slice(0, MAX_WAYPOINTS_IN_STATE);
4321
+ const truncated = list.length > shown.length;
4322
+ const lines = shown.map((w) => `- ${w.name}: (${w.x.toFixed(1)}, ${w.y.toFixed(1)}, ${w.z.toFixed(1)})`);
4323
+ return {
4324
+ text: list.length ? `Waypoints (${shown.length}/${list.length}${truncated ? ", truncated" : ""}):
4828
4325
  ${lines.join(`
4829
4326
  `)}` : "No waypoints saved.",
4830
- values: { count: list.length },
4831
- data: {
4832
- waypoints: list.map((w) => ({
4833
- name: w.name,
4834
- x: w.x,
4835
- y: w.y,
4836
- z: w.z,
4837
- createdAt: w.createdAt.toISOString()
4838
- }))
4839
- }
4840
- };
4327
+ values: { count: list.length, shown: shown.length, truncated },
4328
+ data: {
4329
+ waypoints: shown.map((w) => ({
4330
+ name: w.name,
4331
+ x: w.x,
4332
+ y: w.y,
4333
+ z: w.z,
4334
+ createdAt: w.createdAt.toISOString()
4335
+ }))
4336
+ }
4337
+ };
4338
+ } catch (error) {
4339
+ return {
4340
+ text: "Unable to load Minecraft waypoints",
4341
+ values: { count: 0, error: true },
4342
+ data: { waypoints: [], error: error instanceof Error ? error.message : String(error) }
4343
+ };
4344
+ }
4841
4345
  }
4842
4346
  };
4843
4347
  // src/providers/world-state.ts
4844
- import { logger as logger4 } from "@elizaos/core";
4348
+ import {
4349
+ logger as logger4
4350
+ } from "@elizaos/core";
4351
+ var MAX_INVENTORY_ROWS_IN_STATE = 36;
4352
+ var MAX_ENTITY_ROWS_IN_STATE = 24;
4353
+ function isRecord2(value) {
4354
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
4355
+ }
4356
+ function pickInventoryRows(inventory) {
4357
+ if (!Array.isArray(inventory))
4358
+ return [];
4359
+ const rows = [];
4360
+ for (const item of inventory) {
4361
+ if (!isRecord2(item))
4362
+ continue;
4363
+ const slot = typeof item.slot === "number" ? item.slot : null;
4364
+ const count = typeof item.count === "number" ? item.count : null;
4365
+ const name = typeof item.displayName === "string" ? item.displayName : typeof item.name === "string" ? item.name : null;
4366
+ if (slot === null || count === null || !name)
4367
+ continue;
4368
+ rows.push({ slot, name, count });
4369
+ }
4370
+ return rows;
4371
+ }
4372
+ function pickEntityRows(nearby) {
4373
+ if (!Array.isArray(nearby))
4374
+ return [];
4375
+ const rows = [];
4376
+ for (const ent of nearby) {
4377
+ if (!isRecord2(ent))
4378
+ continue;
4379
+ const id = typeof ent.id === "number" ? ent.id : null;
4380
+ const type = typeof ent.type === "string" ? ent.type : null;
4381
+ const username = typeof ent.username === "string" ? ent.username : null;
4382
+ const entName = typeof ent.name === "string" ? ent.name : null;
4383
+ const name = username ?? entName ?? type ?? "unknown";
4384
+ const pos = isRecord2(ent.position) ? ent.position : null;
4385
+ const x = pos && typeof pos.x === "number" ? pos.x : null;
4386
+ const y = pos && typeof pos.y === "number" ? pos.y : null;
4387
+ const z4 = pos && typeof pos.z === "number" ? pos.z : null;
4388
+ if (id === null || !type || x === null || y === null || z4 === null)
4389
+ continue;
4390
+ rows.push({
4391
+ id,
4392
+ type,
4393
+ name,
4394
+ x: Math.round(x * 10) / 10,
4395
+ y: Math.round(y * 10) / 10,
4396
+ z: Math.round(z4 * 10) / 10
4397
+ });
4398
+ }
4399
+ return rows;
4400
+ }
4845
4401
  var minecraftWorldStateProvider = {
4846
4402
  name: "MC_WORLD_STATE",
4847
- description: "Minecraft world state: position, health, inventory, nearby entities",
4403
+ description: "Minecraft world state: connection, position, health, inventory, nearby entities",
4404
+ descriptionCompressed: "Read live Minecraft connection, position, health, inventory, and nearby entities.",
4848
4405
  dynamic: true,
4406
+ contexts: ["automation", "agent_internal"],
4407
+ contextGate: { anyOf: ["automation", "agent_internal"] },
4408
+ cacheStable: false,
4409
+ cacheScope: "turn",
4849
4410
  get: async (runtime, _message, _state) => {
4850
4411
  const service = runtime.getService(MINECRAFT_SERVICE_TYPE);
4851
4412
  if (!service) {
@@ -4865,10 +4426,20 @@ var minecraftWorldStateProvider = {
4865
4426
  };
4866
4427
  }
4867
4428
  const pos = state.position ? `(${state.position.x.toFixed(1)}, ${state.position.y.toFixed(1)}, ${state.position.z.toFixed(1)})` : "(unknown)";
4868
- const invCount = Array.isArray(state.inventory) ? state.inventory.length : 0;
4869
- const entCount = Array.isArray(state.nearbyEntities) ? state.nearbyEntities.length : 0;
4429
+ const inventoryRows = pickInventoryRows(state.inventory).slice(0, MAX_INVENTORY_ROWS_IN_STATE);
4430
+ const entityRows = pickEntityRows(state.nearbyEntities).slice(0, MAX_ENTITY_ROWS_IN_STATE);
4431
+ const headerLines = [
4432
+ `Minecraft: hp=${state.health ?? "?"} food=${state.food ?? "?"} pos=${pos} invItems=${inventoryRows.length} nearbyEntities=${entityRows.length}`
4433
+ ];
4434
+ if (inventoryRows.length > 0) {
4435
+ headerLines.push(JSON.stringify({ inventory: inventoryRows }));
4436
+ }
4437
+ if (entityRows.length > 0) {
4438
+ headerLines.push(JSON.stringify({ nearbyEntities: entityRows }));
4439
+ }
4870
4440
  return {
4871
- text: `Minecraft: hp=${state.health ?? "?"} food=${state.food ?? "?"} pos=${pos} invItems=${invCount} nearbyEntities=${entCount}`,
4441
+ text: headerLines.join(`
4442
+ `),
4872
4443
  values: {
4873
4444
  connected: true,
4874
4445
  health: state.health ?? null,
@@ -4876,10 +4447,14 @@ var minecraftWorldStateProvider = {
4876
4447
  x: state.position?.x ?? null,
4877
4448
  y: state.position?.y ?? null,
4878
4449
  z: state.position?.z ?? null,
4879
- inventoryCount: invCount,
4880
- nearbyEntitiesCount: entCount
4450
+ inventoryCount: inventoryRows.length,
4451
+ nearbyEntitiesCount: entityRows.length
4881
4452
  },
4882
- data: state
4453
+ data: {
4454
+ ...state,
4455
+ inventory: inventoryRows,
4456
+ nearbyEntities: entityRows
4457
+ }
4883
4458
  };
4884
4459
  } catch (err) {
4885
4460
  const msg = err instanceof Error ? err.message : String(err);
@@ -4893,13 +4468,13 @@ var minecraftWorldStateProvider = {
4893
4468
  }
4894
4469
  };
4895
4470
  // src/index.ts
4896
- var configSchema = z9.object({
4897
- MC_SERVER_PORT: z9.string().optional().default("3457"),
4898
- MC_HOST: z9.string().optional().default("127.0.0.1"),
4899
- MC_PORT: z9.string().optional().default("25565"),
4900
- MC_USERNAME: z9.string().optional(),
4901
- MC_AUTH: z9.string().optional().default("offline"),
4902
- MC_VERSION: z9.string().optional()
4471
+ var configSchema = z4.object({
4472
+ MC_SERVER_PORT: z4.string().optional().default("3457"),
4473
+ MC_HOST: z4.string().optional().default("127.0.0.1"),
4474
+ MC_PORT: z4.string().optional().default("25565"),
4475
+ MC_USERNAME: z4.string().optional(),
4476
+ MC_AUTH: z4.string().optional().default("offline"),
4477
+ MC_VERSION: z4.string().optional()
4903
4478
  });
4904
4479
  var minecraftStateProvider = minecraftWorldStateProvider;
4905
4480
  var minecraftPlugin = {
@@ -4924,23 +4499,7 @@ var minecraftPlugin = {
4924
4499
  logger5.info("Minecraft plugin initialized");
4925
4500
  },
4926
4501
  services: [MinecraftService, WaypointsService],
4927
- actions: [
4928
- minecraftConnectAction,
4929
- minecraftDisconnectAction,
4930
- minecraftChatAction,
4931
- minecraftGotoAction,
4932
- minecraftStopAction,
4933
- minecraftLookAction,
4934
- minecraftControlAction,
4935
- minecraftDigAction,
4936
- minecraftPlaceAction,
4937
- minecraftAttackAction,
4938
- minecraftScanAction,
4939
- minecraftWaypointSetAction,
4940
- minecraftWaypointListAction,
4941
- minecraftWaypointGotoAction,
4942
- minecraftWaypointDeleteAction
4943
- ],
4502
+ actions: [minecraftAction],
4944
4503
  providers: [minecraftStateProvider, minecraftWaypointsProvider, minecraftVisionProvider]
4945
4504
  };
4946
4505
  var src_default = minecraftPlugin;
@@ -4948,23 +4507,9 @@ export {
4948
4507
  minecraftWorldStateSchema,
4949
4508
  minecraftWorldStateProvider,
4950
4509
  minecraftWaypointsProvider,
4951
- minecraftWaypointSetAction,
4952
- minecraftWaypointListAction,
4953
- minecraftWaypointGotoAction,
4954
- minecraftWaypointDeleteAction,
4955
4510
  minecraftVisionProvider,
4956
- minecraftStopAction,
4957
- minecraftScanAction,
4958
4511
  minecraftPlugin,
4959
- minecraftPlaceAction,
4960
- minecraftLookAction,
4961
- minecraftGotoAction,
4962
- minecraftDisconnectAction,
4963
- minecraftDigAction,
4964
- minecraftControlAction,
4965
- minecraftConnectAction,
4966
- minecraftChatAction,
4967
- minecraftAttackAction,
4512
+ minecraftAction,
4968
4513
  src_default as default,
4969
4514
  WaypointsService,
4970
4515
  WAYPOINTS_SERVICE_TYPE,
@@ -4975,4 +4520,4 @@ export {
4975
4520
  MINECRAFT_SERVICE_TYPE
4976
4521
  };
4977
4522
 
4978
- //# debugId=ED8964D2CEB375D564756E2164756E21
4523
+ //# debugId=2AA030689A95D7BF64756E2164756E21