@shirokasoke/webapi-sdk 2.9.0-beta3-0.15-pre → 2.9.0-beta3-0.17-pre2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # @shirokasoke/webapi-sdk
2
+
3
+ [MC WebAPI](https://github.com/Rcrwrate/McWebAPI) 的 TypeScript SDK
4
+
5
+ [![最新构建(java)](https://img.shields.io/github/actions/workflow/status/Rcrwrate/McWebAPI/build-and-test.yml?logo=github&label=Build%20and%20test)](https://github.com/Rcrwrate/McWebAPI/actions/workflows/build-and-test.yml)
6
+ [![最新发布](https://img.shields.io/github/v/release/Rcrwrate/MCWebAPI)](https://github.com/Rcrwrate/McWebAPI/releases/latest)
7
+
8
+ ## 安装
9
+
10
+ ```bash
11
+ npm install @shirokasoke/webapi-sdk
12
+ ```
13
+
14
+ ## 快速开始
15
+
16
+ ```ts
17
+ import { WebApiClient, WebApiError } from "@shirokasoke/webapi-sdk";
18
+
19
+ const client = new WebApiClient({
20
+ baseUrl: "http://localhost:40002",
21
+ authToken: "xxx", // 可选,原值作为 Authorization 头发送
22
+ });
23
+
24
+ const tps = await client.getTPS(); // Record<string, TPSInfo>
25
+ const block = await client.getBlock({ x: 64, y: 64, z: 64, dim: 0 });
26
+ const icon = await client.getItemIcon({ id: 4 }); // ArrayBuffer
27
+ ```
28
+
29
+ - 所有方法返回 `ApiResponse<T>` 解包后的 `data`;HTTP 错误或业务失败(`success=false`)抛出 `WebApiError`(含 `message` / `status` / `body`)
30
+ - 图片、贴图等二进制接口返回 `ArrayBuffer`
31
+ - 依赖全局 `fetch`(Node 18+),或通过 `options.fetch` 注入实现
32
+
33
+ ## API 一览
34
+
35
+ | 分组 | 方法 |
36
+ | --- | --- |
37
+ | 状态 | `getRoot` `getTPS` `getProfiler` `getLagAnalyzer` `getWorldInfo` `checkSSE` |
38
+ | 物品 | `getItems` `getItem` `getItemIcon` `getAEItemsDef` |
39
+ | 方块 | `getBlocks` `getBlock` `setBlock` `batchSetBlock` `getBatchSetBlockJob` `waitForBatchSetBlockJob` `getBlockFMP` `getBlockTile` |
40
+ | 区块 | `getChunks` `getChunk` `getChunkMap` `getChunkForceList` `loadChunk` `unloadChunk` |
41
+ | 实体 | `getEntities` `getEntity` |
42
+ | 流体 | `getFluids` `getFluidContainers` `getFluidIcon` |
43
+ | GT5 | `getGT5Machine` `setGT5MachineStatus` `submitGT5Batch` `getGT5BatchJob` `rerunGT5Batch` `waitForGT5BatchJob` `submitGT5ChunkScan` `getGT5ScanJob` `waitForGT5ScanJob` |
44
+ | AE2 | `aeHit` `aeNodes` `aeCPUs` `aeME` `aeMEs` `aeMESupport` `aeItems` `aeCraft` `aeCancel` `aeSuspend` |
45
+ | 配方 | `getCraftingRecipes` `getFurnaceRecipes` `getGTRecipes` `getGTRecipeMaps` |
46
+ | 3D 打印 | `printToPlayer` `submitWorldPrint` `getWorldPrintJob` `waitForWorldPrintJob` `getPrintSize` |
47
+
48
+ 每个方法都有对应的类型(`src/types`)与 Joi 校验 Schema(`src/validators`)一并导出,详见源码 JSDoc
49
+
50
+ ## SSE 订阅
51
+
52
+ ```ts
53
+ const ctrl = client.aeCpuSseCallback(
54
+ { x: 64, y: 64, z: 64 },
55
+ cpus => console.log(cpus),
56
+ err => console.error(err),
57
+ );
58
+ ctrl.abort(); // 停止订阅
59
+ ```
60
+
61
+ 基于 `@microsoft/fetch-event-source`,可携带 `Authorization` 头。相关路由仅在服务端启用虚拟线程(`useVirtualThreads`)时注册,使用前可 `await client.checkSSE()` 探测。
62
+
63
+ ## AE 合成与合成树分析
64
+
65
+ `aeCraft` 的 `detail` 参数控制合成树输出:`"all"` 始终返回、`"fail"`(默认)仅在失败时随错误 `body` 返回、`"none"` 不返回。
66
+
67
+ ```ts
68
+ import { analyzeAECraftingJobTree, type AECraftingTaskErrorBody } from "@shirokasoke/webapi-sdk";
69
+
70
+ try {
71
+ const result = await client.aeCraft({ x: 64, y: 64, z: 64 }, { id: 1234, Count: 1 });
72
+ if (result.job) {
73
+ const analysis = analyzeAECraftingJobTree(result.job);
74
+ console.log(analysis);
75
+ }
76
+ } catch (e) {
77
+ if (e instanceof WebApiError && e.body) {
78
+ // 模拟失败(材料不足)时,错误 body 中携带失败时的合成树
79
+ const tree = (e.body as AECraftingTaskErrorBody).body;
80
+ console.log(analyzeAECraftingJobTree(tree));
81
+ }
82
+ }
83
+ ```
84
+
85
+ ## 开发
86
+
87
+ ```bash
88
+ npm run build # tsc 构建到 dist/
89
+ tsx --test test/singlefile # 运行测试每次一个,勿并行
90
+ # npm run web # 构建并同步到 web/node_modules/@shirokasoke/webapi-sdk/
91
+ ```
92
+
93
+ ## License
94
+
95
+ MIT
package/dist/client.d.ts CHANGED
@@ -424,7 +424,19 @@ export declare class WebApiClient {
424
424
  dimension?: number;
425
425
  }): Promise<AEItemsResult>;
426
426
  /**
427
+ * 向 AE 合成网络提交自动合成任务
428
+ *
429
+ * 如果返回的 {@link AECraftingTaskResult} 含合成树 `job`({@link AECraftingJobTree}),
430
+ * 可配合 {@link analyzeAECraftingJobTree} 判定能否合成及缺失物品
431
+ *
432
+ * 失败时抛出 {@link WebApiError}:
433
+ * - HTTP 500 且 message 为 "Failed to simulate job" 时,`error.body` 为
434
+ * {@link AECraftingTaskErrorBody},其 `body` 携带失败时的合成树,同样可分析缺失物品;
435
+ * - HTTP 500 且 message 为 "Failed to submit job to CPU" 时,为 CPU 侧问题
436
+ * (无可用 CPU / 存储字节不足 / CPU 忙碌),与材料无关。
437
+ *
427
438
  * @java [java](../../../src/main/java/love/shirokasoke/webapi/webserver/handlers/ae2/AECPUTaskHandler.java)
439
+ * @param params 坐标参数;`detail` 控制合成树输出:`"all"` 始终输出,`"fail"`仅失败时输出,`"none"` 不输出
428
440
  * @param body 使用 {@link AECraftingTaskBodySchema} 验证
429
441
  * @returns 使用 {@link AECraftingTaskResultSchema} 验证
430
442
  */
@@ -433,6 +445,7 @@ export declare class WebApiClient {
433
445
  y: number;
434
446
  z: number;
435
447
  dimension?: number;
448
+ detail?: "all" | "fail" | "none";
436
449
  }, body: AECraftingTaskBody): Promise<AECraftingTaskResult>;
437
450
  /**
438
451
  * @java [java](../../../src/main/java/love/shirokasoke/webapi/webserver/handlers/ae2/AECPUCancelHandler.java)
package/dist/client.js CHANGED
@@ -556,7 +556,19 @@ class WebApiClient {
556
556
  return this.request(`/ae/item${buildQuery(params)}`);
557
557
  }
558
558
  /**
559
+ * 向 AE 合成网络提交自动合成任务
560
+ *
561
+ * 如果返回的 {@link AECraftingTaskResult} 含合成树 `job`({@link AECraftingJobTree}),
562
+ * 可配合 {@link analyzeAECraftingJobTree} 判定能否合成及缺失物品
563
+ *
564
+ * 失败时抛出 {@link WebApiError}:
565
+ * - HTTP 500 且 message 为 "Failed to simulate job" 时,`error.body` 为
566
+ * {@link AECraftingTaskErrorBody},其 `body` 携带失败时的合成树,同样可分析缺失物品;
567
+ * - HTTP 500 且 message 为 "Failed to submit job to CPU" 时,为 CPU 侧问题
568
+ * (无可用 CPU / 存储字节不足 / CPU 忙碌),与材料无关。
569
+ *
559
570
  * @java [java](../../../src/main/java/love/shirokasoke/webapi/webserver/handlers/ae2/AECPUTaskHandler.java)
571
+ * @param params 坐标参数;`detail` 控制合成树输出:`"all"` 始终输出,`"fail"`仅失败时输出,`"none"` 不输出
560
572
  * @param body 使用 {@link AECraftingTaskBodySchema} 验证
561
573
  * @returns 使用 {@link AECraftingTaskResultSchema} 验证
562
574
  */
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { WebApiClient, WebApiError, type WebApiClientOptions } from "./client";
2
2
  export * from "./types";
3
3
  export * from "./validators";
4
+ export * from "./utils/ae2";
package/dist/index.js CHANGED
@@ -20,3 +20,4 @@ Object.defineProperty(exports, "WebApiClient", { enumerable: true, get: function
20
20
  Object.defineProperty(exports, "WebApiError", { enumerable: true, get: function () { return client_1.WebApiError; } });
21
21
  __exportStar(require("./types"), exports);
22
22
  __exportStar(require("./validators"), exports);
23
+ __exportStar(require("./utils/ae2"), exports);
@@ -1,4 +1,4 @@
1
- import type { ClassInfo } from "./common";
1
+ import type { ApiErrorResponse, ClassInfo } from "./common";
2
2
  import type { Fluid } from "./fluid";
3
3
  import type { ItemStack } from "./item";
4
4
  export type AEStack = (ItemStack | Fluid) & {
@@ -112,12 +112,83 @@ export interface AECraftingTaskBody {
112
112
  tag?: string;
113
113
  cpu?: string;
114
114
  }
115
+ /** `appeng.crafting.v2.resolvers.CraftingTask.State` 枚举名 */
116
+ export type AECraftingTaskState = "NEEDS_MORE_WORK" | "SUCCESS" | "FAILURE";
117
+ /** `appeng.crafting.v2.CraftingRequest.SubstitutionMode` 枚举名 */
118
+ export type AECraftingSubstitutionMode = "PRECISE_FRESH" | "PRECISE" | "ACCEPT_FUZZY";
119
+ /**
120
+ * 合成树中的单个任务
121
+ *
122
+ * `type` 为任务类名,常见取值:
123
+ * - `ExtractItemTask`:从 ME 网络直接提取(真实路径)
124
+ * - `EmitableItemTask`:发射器供给
125
+ * - `CraftFromPatternTask`:按样板合成(递归拆出子材料请求)
126
+ * - `IgnoreMissingItemTask`:IGNORE_MISSING 模式下假定稍后补齐
127
+ * - `ConjureItemTask`:材料不足时"无中生有"的模拟任务,**即缺失物品**
128
+ * - `CheckOtherResolversTask`:计算器内部调度任务
129
+ */
130
+ export interface AECraftingTaskNode {
131
+ type: string;
132
+ state: AECraftingTaskState;
133
+ /** 是否仅为模拟(`isSimulated`):true 表示该任务供应的物品网络中实际不存在 */
134
+ simulated: boolean;
135
+ priority: number;
136
+ /** `task.toString()`,如 `ConjureItemTask{fulfilled=32, ...}`,fulfilled 即缺口数量 */
137
+ detail: string;
138
+ }
139
+ /** 合成树中单个请求的解析器条目 */
140
+ export interface AECraftingResolverNode {
141
+ type: string;
142
+ state: AECraftingTaskState;
143
+ /** 是否仅为模拟:true 表示该解析器通过"无中生有"满足请求,其 `resolved` 即缺失数量 */
144
+ simulated: boolean;
145
+ /** 任务 `toString()` */
146
+ detail: string;
147
+ /** 该解析器实际提供的数量(服务端 `entry.resolvedStack.getStackSize()`,物品为个数、流体为 mB) */
148
+ resolved: number;
149
+ }
150
+ /** 合成树中的单个请求节点 */
151
+ export interface AECraftingRequestNode {
152
+ stack: AEStack;
153
+ substitutionMode: AECraftingSubstitutionMode;
154
+ /** `remainingToProcess`:仍未被满足的数量,>0 表示该请求仍有缺口 */
155
+ remaining: number;
156
+ byteCost: number;
157
+ /** `wasSimulated`:该请求(含子树)是否被模拟满足 */
158
+ simulated: boolean;
159
+ /** `incomplete`:是否因超出合成步骤上限被截断 */
160
+ incomplete: boolean;
161
+ /** `request.toString()` */
162
+ detail: string;
163
+ /** 满足该请求的任务链 */
164
+ resolvers: AECraftingResolverNode[];
165
+ children?: AECraftingRequestNode[];
166
+ /** 子请求超过最大递归深度(256)被截断的数量 */
167
+ childrenTruncated?: number;
168
+ }
169
+ /** 合成树:`requests` 为自根请求展开的请求树,`tasks` 为按执行顺序的任务列表 */
170
+ export interface AECraftingJobTree {
171
+ requests: AECraftingRequestNode[];
172
+ tasks: AECraftingTaskNode[];
173
+ }
115
174
  export interface AECraftingTaskResult {
116
175
  bytes: number;
117
176
  cpu: string;
118
177
  output: ItemStack & {
119
178
  stackSize: number;
120
179
  };
180
+ /**
181
+ * 合成树
182
+ */
183
+ job?: AECraftingJobTree | null;
184
+ }
185
+ /**
186
+ * AE合成任务提交失败响应体
187
+ *
188
+ * 材料不足或无法合成时,`body` 携带失败时的合成树,可配合 `analyzeAECraftingJobTree` 分析缺失物品
189
+ */
190
+ export interface AECraftingTaskErrorBody extends ApiErrorResponse {
191
+ body?: AECraftingJobTree | null;
121
192
  }
122
193
  export interface AECPUCancelBody {
123
194
  name?: string;
@@ -15,6 +15,7 @@ export interface Chunk {
15
15
  hasEntities: boolean;
16
16
  isChunkLoaded: boolean;
17
17
  sendUpdates: boolean;
18
+ pollution: number;
18
19
  tileEntityCount: number;
19
20
  entityCount?: number;
20
21
  entityList?: Entity[][];
@@ -17,7 +17,13 @@ export interface ApiSuccessResponse<T> {
17
17
  export interface ApiErrorResponse {
18
18
  success: false;
19
19
  message: string;
20
+ /** 路由描述 */
21
+ desc?: string;
20
22
  stack?: string | null;
23
+ /**
24
+ * 失败时附带的业务数据
25
+ */
26
+ body?: unknown;
21
27
  }
22
28
  export type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
23
29
  export interface RootInfo {
@@ -2,6 +2,9 @@ import type { ClassInfo } from "./common";
2
2
  import type { Fluid } from "./fluid";
3
3
  import type { NBTCompound } from "./item";
4
4
  export type GT5MachineType = "MULTIBLOCK" | "SINGLE" | "GENERATOR" | "HATCH" | "UNKNOWN";
5
+ /**
6
+ * 注意:所有 SimpleShutDownReason 的 id 都是 "simple_result",只能靠 displayString / wasCritical 区分,不能按 id 判断
7
+ */
5
8
  export interface GT5ShutDownReason {
6
9
  id: string;
7
10
  displayString: string;
@@ -0,0 +1,42 @@
1
+ import type { AECraftingJobTree, AECraftingTaskNode, AEStack } from "../types/ae2";
2
+ /** 合成任务不可合成的原因 */
3
+ export type AECraftingJobAnalysisReason =
4
+ /** 存在 simulated 请求/解析器:材料不足,网络中没有对应物品(等价于服务端 job.isSimulation()) */
5
+ "SIMULATED"
6
+ /** 存在 FAILURE 任务:该合成路径彻底失败(如样板输出不匹配) */
7
+ | "FAILED_TASK"
8
+ /** 请求被截断:超出服务端 AEConfig.maxCraftingSteps 合成步骤上限 */
9
+ | "INCOMPLETE"
10
+ /** 存在未被满足的请求(remaining > 0) */
11
+ | "UNRESOLVED";
12
+ /** {@link analyzeAECraftingJobTree} 的分析结果 */
13
+ export interface AECraftingJobAnalysis {
14
+ /** 是否可正常合成:材料齐全、无失败任务、无截断、无未满足请求 */
15
+ craftable: boolean;
16
+ /** 不可合成的原因(craftable 为 false 时非空) */
17
+ reasons: AECraftingJobAnalysisReason[];
18
+ /** 缺失的物品/流体堆,已按物品(id + damage + NBT)合并,stackSize 为缺口总量 */
19
+ missing: AEStack[];
20
+ /**
21
+ * 所有 simulated=true 且非内部调度的任务节点(已排除 {@link INTERNAL_TASK_TYPES}),
22
+ * 缺失物品即由这些任务"无中生有"供应
23
+ */
24
+ simulatedTasks: AECraftingTaskNode[];
25
+ }
26
+ /**
27
+ * 分析合成树,判断任务能否正常合成,并汇总合成缺少的物品。
28
+ *
29
+ * 判定依据(对应服务端 AE2 v2 合成计算器):
30
+ * - 请求 `simulated`(wasSimulated)或其解析器 `simulated` ⇒ 材料不足,等价于服务端
31
+ * `job.isSimulation()`(`CraftingContext.wasSimulated`,仅由 SimulateMissingItemResolver 置位);
32
+ * - FAILURE 任务会中止整个计算;
33
+ * - `incomplete` 请求 ⇒ 超出合成步骤上限,树被截断,不可提交;
34
+ * - 缺失物品 = 请求树中所有 `simulated` 解析器(ConjureItemTask / IgnoreMissingItemTask /
35
+ * 模拟 CraftFromPatternTask),其数量为解析器的 `resolved`,物品/流体类型取父请求的 `stack`。
36
+ *
37
+ * 注意:任务列表(`tasks`)中的 `simulated` 标志不可直接作为缺失依据——内部调度任务
38
+ * {@link INTERNAL_TASK_TYPES} 的该标志为派生值,成功树中亦可能为 true,已予排除。
39
+ *
40
+ * @param tree {@link AECraftingJobTree},来自 `AECraftingTaskResult.job` 或 `AECraftingTaskErrorBody.body`
41
+ */
42
+ export declare function analyzeAECraftingJobTree(tree: AECraftingJobTree): AECraftingJobAnalysis;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analyzeAECraftingJobTree = analyzeAECraftingJobTree;
4
+ /**
5
+ * AE2 v2 计算器内部调度任务(`CraftingContext.CheckOtherResolversTask`)
6
+ *
7
+ * 该任务永远不会作为解析器输出(计划/CPU 侧均为 no-op),其 `simulated` 标志由所在请求的
8
+ * 候选解析器列表 `allMatch(isSimulated)` 派生,**即使在完全成功的合成树中也可能为 true**,
9
+ * 因此不能作为材料缺失的依据,分析时应排除。
10
+ */
11
+ const INTERNAL_TASK_TYPES = ["CheckOtherResolversTask"];
12
+ /** 流体与物品的判别字段:Fluid 具有 gaseous,ItemStack 具有 HasSubtypes */
13
+ function isFluidStack(stack) {
14
+ return "gaseous" in stack;
15
+ }
16
+ /** 堆的合并键:物品按 id + damage + NBT,流体按 id */
17
+ function stackKey(stack) {
18
+ if (isFluidStack(stack)) {
19
+ return `fluid:${stack.id}`;
20
+ }
21
+ const item = stack;
22
+ return `item:${item.id}:${item.damage}:${item.nbt?.nbtstr ?? ""}`;
23
+ }
24
+ function mergeInto(target, stack) {
25
+ const key = stackKey(stack);
26
+ const existing = target.get(key);
27
+ if (existing) {
28
+ existing.stackSize += stack.stackSize;
29
+ }
30
+ else {
31
+ target.set(key, stack);
32
+ }
33
+ }
34
+ /**
35
+ * 分析合成树,判断任务能否正常合成,并汇总合成缺少的物品。
36
+ *
37
+ * 判定依据(对应服务端 AE2 v2 合成计算器):
38
+ * - 请求 `simulated`(wasSimulated)或其解析器 `simulated` ⇒ 材料不足,等价于服务端
39
+ * `job.isSimulation()`(`CraftingContext.wasSimulated`,仅由 SimulateMissingItemResolver 置位);
40
+ * - FAILURE 任务会中止整个计算;
41
+ * - `incomplete` 请求 ⇒ 超出合成步骤上限,树被截断,不可提交;
42
+ * - 缺失物品 = 请求树中所有 `simulated` 解析器(ConjureItemTask / IgnoreMissingItemTask /
43
+ * 模拟 CraftFromPatternTask),其数量为解析器的 `resolved`,物品/流体类型取父请求的 `stack`。
44
+ *
45
+ * 注意:任务列表(`tasks`)中的 `simulated` 标志不可直接作为缺失依据——内部调度任务
46
+ * {@link INTERNAL_TASK_TYPES} 的该标志为派生值,成功树中亦可能为 true,已予排除。
47
+ *
48
+ * @param tree {@link AECraftingJobTree},来自 `AECraftingTaskResult.job` 或 `AECraftingTaskErrorBody.body`
49
+ */
50
+ function analyzeAECraftingJobTree(tree) {
51
+ const simulatedTasks = tree.tasks.filter(task => task.simulated && !INTERNAL_TASK_TYPES.includes(task.type));
52
+ const failedTasks = tree.tasks.filter(task => task.state === "FAILURE");
53
+ const reasons = new Set();
54
+ const missing = new Map();
55
+ const visitRequest = (node) => {
56
+ if (node.incomplete) {
57
+ reasons.add("INCOMPLETE");
58
+ }
59
+ if (node.remaining > 0) {
60
+ reasons.add("UNRESOLVED");
61
+ }
62
+ if (node.simulated) {
63
+ // wasSimulated:该请求(含子树)被"无中生有"满足,等价于服务端 job.isSimulation()
64
+ reasons.add("SIMULATED");
65
+ }
66
+ for (const resolver of node.resolvers) {
67
+ if (resolver.simulated && resolver.resolved > 0) {
68
+ // 模拟解析器(ConjureItemTask / IgnoreMissingItemTask / 模拟 CraftFromPatternTask):
69
+ // resolved 即缺失数量,堆类型取父请求的 stack(服务端仅输出数量,未输出完整堆)
70
+ reasons.add("SIMULATED");
71
+ mergeInto(missing, { ...node.stack, stackSize: resolver.resolved });
72
+ }
73
+ }
74
+ node.children?.forEach(visitRequest);
75
+ };
76
+ tree.requests.forEach(visitRequest);
77
+ if (simulatedTasks.length > 0) {
78
+ reasons.add("SIMULATED");
79
+ }
80
+ if (failedTasks.length > 0) {
81
+ reasons.add("FAILED_TASK");
82
+ }
83
+ return {
84
+ craftable: reasons.size === 0,
85
+ reasons: [...reasons],
86
+ missing: [...missing.values()],
87
+ simulatedTasks,
88
+ };
89
+ }
@@ -1,5 +1,5 @@
1
1
  import Joi from "joi";
2
- import type { AECPU, AECPUCancelBody, AECPUCancelResult, AECraftingTaskBody, AECraftingTaskResult, AEHitResult, AEItemsResult, AEMEInterface, AENode, AECPUSuspendResult } from "../types/ae2";
2
+ import type { AECPU, AECPUCancelBody, AECPUCancelResult, AECraftingJobTree, AECraftingRequestNode, AECraftingResolverNode, AECraftingTaskBody, AECraftingTaskErrorBody, AECraftingTaskNode, AECraftingTaskResult, AEHitResult, AEItemsResult, AEMEInterface, AENode, AECPUSuspendResult } from "../types/ae2";
3
3
  export declare const AEStackProvidersSchema: Joi.ArraySchema<any[]>;
4
4
  /** 对应服务端 Pattern.dumpAEStack 的输出:物品或流体堆,附加 stackSize 字段 */
5
5
  export declare const AEStackSchema: Joi.AlternativesSchema<{
@@ -46,7 +46,27 @@ export declare const AECPUTaskSchema: Joi.ObjectSchema<any>;
46
46
  export declare const AECPUSchema: Joi.ObjectSchema<AECPU>;
47
47
  export declare const AEMEInterfaceSchema: Joi.ObjectSchema<AEMEInterface>;
48
48
  export declare const AECraftingTaskBodySchema: Joi.ObjectSchema<AECraftingTaskBody>;
49
+ /**
50
+ * `appeng.crafting.v2.resolvers.CraftingTask.State` 枚举名。
51
+ * 严格枚举校验:计算正常结束时所有已解决任务均应为 SUCCESS,FAILURE 会中止整个计算
52
+ */
53
+ export declare const AECraftingTaskStateSchema: Joi.StringSchema<string>;
54
+ /** `appeng.crafting.v2.CraftingRequest.SubstitutionMode` 枚举名 */
55
+ export declare const AECraftingSubstitutionModeSchema: Joi.StringSchema<string>;
56
+ /** 合成树中的任务节点(`AECPUTaskHandler#dumpTree` 的 tasks 数组元素) */
57
+ export declare const AECraftingTaskNodeSchema: Joi.ObjectSchema<AECraftingTaskNode>;
58
+ /** 合成树中单个请求的解析器条目 */
59
+ export declare const AECraftingResolverNodeSchema: Joi.ObjectSchema<AECraftingResolverNode>;
60
+ /**
61
+ * 合成树中的请求节点(递归,children 为子请求)。
62
+ * Joi 18 已移除 Joi.lazy,递归通过 link 引用自身 id 实现
63
+ */
64
+ export declare const AECraftingRequestNodeSchema: Joi.ObjectSchema<AECraftingRequestNode>;
65
+ /** 合成树:requests 请求树 + tasks 任务列表 */
66
+ export declare const AECraftingJobTreeSchema: Joi.ObjectSchema<AECraftingJobTree>;
49
67
  export declare const AECraftingTaskResultSchema: Joi.ObjectSchema<AECraftingTaskResult>;
68
+ /** `/ae/cpu/task` 失败响应体:body 携带失败时的合成树 */
69
+ export declare const AECraftingTaskErrorBodySchema: Joi.ObjectSchema<AECraftingTaskErrorBody>;
50
70
  export declare const AECPUCancelBodySchema: Joi.ObjectSchema<AECPUCancelBody>;
51
71
  export declare const AECPUCancelResultSchema: Joi.ObjectSchema<AECPUCancelResult>;
52
72
  export declare const AECPUSuspendBodySchema: Joi.ObjectSchema<AECPUCancelBody>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AEHitResultSchema = exports.AEItemsResultSchema = exports.AEItemCellStatusSchema = exports.AEItemStackSchema = exports.AECPUSuspendResultSchema = exports.AECPUSuspendBodySchema = exports.AECPUCancelResultSchema = exports.AECPUCancelBodySchema = exports.AECraftingTaskResultSchema = exports.AECraftingTaskBodySchema = exports.AEMEInterfaceSchema = exports.AECPUSchema = exports.AECPUTaskSchema = exports.AECPUScheduledReasonSchema = exports.AE_CPU_SCHEDULED_REASONS = exports.AE2PatternSchema = exports.AENodeSchema = exports.AEStackWithProvidersSchema = exports.AEStackSchema = exports.AEStackProvidersSchema = void 0;
6
+ exports.AEHitResultSchema = exports.AEItemsResultSchema = exports.AEItemCellStatusSchema = exports.AEItemStackSchema = exports.AECPUSuspendResultSchema = exports.AECPUSuspendBodySchema = exports.AECPUCancelResultSchema = exports.AECPUCancelBodySchema = exports.AECraftingTaskErrorBodySchema = exports.AECraftingTaskResultSchema = exports.AECraftingJobTreeSchema = exports.AECraftingRequestNodeSchema = exports.AECraftingResolverNodeSchema = exports.AECraftingTaskNodeSchema = exports.AECraftingSubstitutionModeSchema = exports.AECraftingTaskStateSchema = exports.AECraftingTaskBodySchema = exports.AEMEInterfaceSchema = exports.AECPUSchema = exports.AECPUTaskSchema = exports.AECPUScheduledReasonSchema = exports.AE_CPU_SCHEDULED_REASONS = exports.AE2PatternSchema = exports.AENodeSchema = exports.AEStackWithProvidersSchema = exports.AEStackSchema = exports.AEStackProvidersSchema = void 0;
7
7
  const joi_1 = __importDefault(require("joi"));
8
8
  const common_1 = require("./common");
9
9
  const fluid_1 = require("./fluid");
@@ -122,10 +122,69 @@ exports.AECraftingTaskBodySchema = joi_1.default.object({
122
122
  tag: joi_1.default.string().optional(),
123
123
  cpu: joi_1.default.string().optional(),
124
124
  });
125
+ /**
126
+ * `appeng.crafting.v2.resolvers.CraftingTask.State` 枚举名。
127
+ * 严格枚举校验:计算正常结束时所有已解决任务均应为 SUCCESS,FAILURE 会中止整个计算
128
+ */
129
+ exports.AECraftingTaskStateSchema = joi_1.default.string()
130
+ .valid("NEEDS_MORE_WORK", "SUCCESS", "FAILURE")
131
+ .required();
132
+ /** `appeng.crafting.v2.CraftingRequest.SubstitutionMode` 枚举名 */
133
+ exports.AECraftingSubstitutionModeSchema = joi_1.default.string()
134
+ .valid("PRECISE_FRESH", "PRECISE", "ACCEPT_FUZZY")
135
+ .required();
136
+ /** 合成树中的任务节点(`AECPUTaskHandler#dumpTree` 的 tasks 数组元素) */
137
+ exports.AECraftingTaskNodeSchema = joi_1.default.object({
138
+ type: joi_1.default.string().required(),
139
+ state: exports.AECraftingTaskStateSchema,
140
+ simulated: joi_1.default.boolean().required(),
141
+ priority: joi_1.default.number().required(),
142
+ detail: joi_1.default.string().required(),
143
+ });
144
+ /** 合成树中单个请求的解析器条目 */
145
+ exports.AECraftingResolverNodeSchema = joi_1.default.object({
146
+ type: joi_1.default.string().required(),
147
+ state: exports.AECraftingTaskStateSchema,
148
+ simulated: joi_1.default.boolean().required(),
149
+ detail: joi_1.default.string().required(),
150
+ /** 服务端输出 `entry.resolvedStack.getStackSize()`:该解析器实际提供的数量 */
151
+ resolved: joi_1.default.number().required(),
152
+ });
153
+ /**
154
+ * 合成树中的请求节点(递归,children 为子请求)。
155
+ * Joi 18 已移除 Joi.lazy,递归通过 link 引用自身 id 实现
156
+ */
157
+ exports.AECraftingRequestNodeSchema = joi_1.default.object({
158
+ stack: exports.AEStackSchema.required(),
159
+ substitutionMode: exports.AECraftingSubstitutionModeSchema,
160
+ remaining: joi_1.default.number().required(),
161
+ byteCost: joi_1.default.number().required(),
162
+ simulated: joi_1.default.boolean().required(),
163
+ incomplete: joi_1.default.boolean().required(),
164
+ detail: joi_1.default.string().required(),
165
+ resolvers: joi_1.default.array().items(exports.AECraftingResolverNodeSchema).required(),
166
+ children: joi_1.default.array().items(joi_1.default.link("#aecraftingrequest")).optional(),
167
+ childrenTruncated: joi_1.default.number().optional(),
168
+ }).id("aecraftingrequest");
169
+ /** 合成树:requests 请求树 + tasks 任务列表 */
170
+ exports.AECraftingJobTreeSchema = joi_1.default.object({
171
+ requests: joi_1.default.array().items(exports.AECraftingRequestNodeSchema).required(),
172
+ tasks: joi_1.default.array().items(exports.AECraftingTaskNodeSchema).required(),
173
+ });
125
174
  exports.AECraftingTaskResultSchema = joi_1.default.object({
126
175
  bytes: joi_1.default.number().required(),
127
176
  cpu: joi_1.default.string().required(),
128
177
  output: item_1.ItemStackSchema.append({ stackSize: joi_1.default.number().required() }).required(),
178
+ /** 仅当请求带 detail=all 时输出 */
179
+ job: exports.AECraftingJobTreeSchema.allow(null).optional(),
180
+ });
181
+ /** `/ae/cpu/task` 失败响应体:body 携带失败时的合成树 */
182
+ exports.AECraftingTaskErrorBodySchema = joi_1.default.object({
183
+ success: joi_1.default.valid(false).required(),
184
+ message: joi_1.default.string().required(),
185
+ desc: joi_1.default.string().optional(),
186
+ stack: joi_1.default.string().allow(null).optional(),
187
+ body: exports.AECraftingJobTreeSchema.allow(null).optional(),
129
188
  });
130
189
  exports.AECPUCancelBodySchema = joi_1.default.object({
131
190
  name: joi_1.default.string().optional(),
@@ -22,6 +22,7 @@ exports.ChunkSchema = joi_1.default.object({
22
22
  hasEntities: joi_1.default.boolean().required(),
23
23
  isChunkLoaded: joi_1.default.boolean().required(),
24
24
  sendUpdates: joi_1.default.boolean().required(),
25
+ pollution: joi_1.default.number().required(),
25
26
  tileEntityCount: joi_1.default.number().required(),
26
27
  entityCount: joi_1.default.number().optional(),
27
28
  entityList: joi_1.default.array().items(joi_1.default.array().items(entity_1.EntitySchema)).optional(),
@@ -25,7 +25,9 @@ exports.ApiSuccessResponseSchema = ApiSuccessResponseSchema;
25
25
  exports.ApiErrorResponseSchema = joi_1.default.object({
26
26
  success: joi_1.default.valid(false).required(),
27
27
  message: joi_1.default.string().required(),
28
+ desc: joi_1.default.string().optional(),
28
29
  stack: joi_1.default.string().allow(null).optional(),
30
+ body: joi_1.default.any().optional(),
29
31
  });
30
32
  const ApiResponseSchema = (dataSchema) => joi_1.default.alternatives((0, exports.ApiSuccessResponseSchema)(dataSchema), exports.ApiErrorResponseSchema);
31
33
  exports.ApiResponseSchema = ApiResponseSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shirokasoke/webapi-sdk",
3
- "version": "2.9.0-beta3-0.15-pre",
3
+ "version": "2.9.0-beta3-0.17-pre2",
4
4
  "private": false,
5
5
  "description": "TypeScript SDK for the love.shirokasoke.WebAPI Minecraft Mod",
6
6
  "main": "./dist/index.js",
@@ -29,6 +29,7 @@
29
29
  ],
30
30
  "author": "Rcrwrate",
31
31
  "license": "MIT",
32
+ "homepage": "https://github.com/Rcrwrate/McWebAPI/tree/main/sdk/ts",
32
33
  "devDependencies": {
33
34
  "@types/node": "^26.6.5",
34
35
  "tsx": "^4.23.15",
@@ -36,6 +37,6 @@
36
37
  },
37
38
  "dependencies": {
38
39
  "@microsoft/fetch-event-source": "^2.0.1",
39
- "joi": "^18.2.9"
40
+ "joi": "^18.3.0"
40
41
  }
41
42
  }