minecraft-bedrock-mcp-server 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +577 -0
- package/dist/bridge/event-route.d.ts +11 -0
- package/dist/bridge/event-route.d.ts.map +1 -0
- package/dist/bridge/event-route.js +28 -0
- package/dist/bridge/event-route.js.map +1 -0
- package/dist/bridge/handshake-route.d.ts +11 -0
- package/dist/bridge/handshake-route.d.ts.map +1 -0
- package/dist/bridge/handshake-route.js +45 -0
- package/dist/bridge/handshake-route.js.map +1 -0
- package/dist/bridge/poll-route.d.ts +11 -0
- package/dist/bridge/poll-route.d.ts.map +1 -0
- package/dist/bridge/poll-route.js +28 -0
- package/dist/bridge/poll-route.js.map +1 -0
- package/dist/bridge/result-route.d.ts +10 -0
- package/dist/bridge/result-route.d.ts.map +1 -0
- package/dist/bridge/result-route.js +23 -0
- package/dist/bridge/result-route.js.map +1 -0
- package/dist/config/config-error.d.ts +12 -0
- package/dist/config/config-error.d.ts.map +1 -0
- package/dist/config/config-error.js +13 -0
- package/dist/config/config-error.js.map +1 -0
- package/dist/config/environment.d.ts +89 -0
- package/dist/config/environment.d.ts.map +1 -0
- package/dist/config/environment.js +73 -0
- package/dist/config/environment.js.map +1 -0
- package/dist/config/tls.d.ts +15 -0
- package/dist/config/tls.d.ts.map +1 -0
- package/dist/config/tls.js +27 -0
- package/dist/config/tls.js.map +1 -0
- package/dist/errors/bridge-error.d.ts +41 -0
- package/dist/errors/bridge-error.d.ts.map +1 -0
- package/dist/errors/bridge-error.js +33 -0
- package/dist/errors/bridge-error.js.map +1 -0
- package/dist/errors/error-codes.d.ts +13 -0
- package/dist/errors/error-codes.d.ts.map +1 -0
- package/dist/errors/error-codes.js +41 -0
- package/dist/errors/error-codes.js.map +1 -0
- package/dist/events/subscription-registry.d.ts +55 -0
- package/dist/events/subscription-registry.d.ts.map +1 -0
- package/dist/events/subscription-registry.js +64 -0
- package/dist/events/subscription-registry.js.map +1 -0
- package/dist/http/app.d.ts +26 -0
- package/dist/http/app.d.ts.map +1 -0
- package/dist/http/app.js +88 -0
- package/dist/http/app.js.map +1 -0
- package/dist/http/authentication.d.ts +11 -0
- package/dist/http/authentication.d.ts.map +1 -0
- package/dist/http/authentication.js +36 -0
- package/dist/http/authentication.js.map +1 -0
- package/dist/http/health-route.d.ts +10 -0
- package/dist/http/health-route.d.ts.map +1 -0
- package/dist/http/health-route.js +18 -0
- package/dist/http/health-route.js.map +1 -0
- package/dist/http/metrics-route.d.ts +8 -0
- package/dist/http/metrics-route.d.ts.map +1 -0
- package/dist/http/metrics-route.js +11 -0
- package/dist/http/metrics-route.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +134 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/mcp-route.d.ts +12 -0
- package/dist/mcp/mcp-route.d.ts.map +1 -0
- package/dist/mcp/mcp-route.js +49 -0
- package/dist/mcp/mcp-route.js.map +1 -0
- package/dist/mcp/mcp-server-factory.d.ts +20 -0
- package/dist/mcp/mcp-server-factory.d.ts.map +1 -0
- package/dist/mcp/mcp-server-factory.js +23 -0
- package/dist/mcp/mcp-server-factory.js.map +1 -0
- package/dist/mcp/session-manager.d.ts +30 -0
- package/dist/mcp/session-manager.d.ts.map +1 -0
- package/dist/mcp/session-manager.js +38 -0
- package/dist/mcp/session-manager.js.map +1 -0
- package/dist/mcp/tool-registry.d.ts +15 -0
- package/dist/mcp/tool-registry.d.ts.map +1 -0
- package/dist/mcp/tool-registry.js +27 -0
- package/dist/mcp/tool-registry.js.map +1 -0
- package/dist/observability/logger.d.ts +16 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +19 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +27 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +72 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/protocol/command.d.ts +92 -0
- package/dist/protocol/command.d.ts.map +1 -0
- package/dist/protocol/command.js +37 -0
- package/dist/protocol/command.js.map +1 -0
- package/dist/protocol/event.d.ts +82 -0
- package/dist/protocol/event.d.ts.map +1 -0
- package/dist/protocol/event.js +37 -0
- package/dist/protocol/event.js.map +1 -0
- package/dist/protocol/handshake.d.ts +150 -0
- package/dist/protocol/handshake.d.ts.map +1 -0
- package/dist/protocol/handshake.js +65 -0
- package/dist/protocol/handshake.js.map +1 -0
- package/dist/protocol/index.d.ts +14 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +14 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/protocol-version.d.ts +18 -0
- package/dist/protocol/protocol-version.d.ts.map +1 -0
- package/dist/protocol/protocol-version.js +28 -0
- package/dist/protocol/protocol-version.js.map +1 -0
- package/dist/protocol/result.d.ts +79 -0
- package/dist/protocol/result.d.ts.map +1 -0
- package/dist/protocol/result.js +35 -0
- package/dist/protocol/result.js.map +1 -0
- package/dist/queue/command-id.d.ts +15 -0
- package/dist/queue/command-id.d.ts.map +1 -0
- package/dist/queue/command-id.js +38 -0
- package/dist/queue/command-id.js.map +1 -0
- package/dist/queue/command-queue.d.ts +90 -0
- package/dist/queue/command-queue.d.ts.map +1 -0
- package/dist/queue/command-queue.js +151 -0
- package/dist/queue/command-queue.js.map +1 -0
- package/dist/queue/command-throttle.d.ts +38 -0
- package/dist/queue/command-throttle.d.ts.map +1 -0
- package/dist/queue/command-throttle.js +26 -0
- package/dist/queue/command-throttle.js.map +1 -0
- package/dist/queue/instrumented-command-queue.d.ts +9 -0
- package/dist/queue/instrumented-command-queue.d.ts.map +1 -0
- package/dist/queue/instrumented-command-queue.js +39 -0
- package/dist/queue/instrumented-command-queue.js.map +1 -0
- package/dist/queue/pending-commands.d.ts +35 -0
- package/dist/queue/pending-commands.d.ts.map +1 -0
- package/dist/queue/pending-commands.js +41 -0
- package/dist/queue/pending-commands.js.map +1 -0
- package/dist/server-info.d.ts +5 -0
- package/dist/server-info.d.ts.map +1 -0
- package/dist/server-info.js +22 -0
- package/dist/server-info.js.map +1 -0
- package/dist/structures/structure-file-store.d.ts +22 -0
- package/dist/structures/structure-file-store.d.ts.map +1 -0
- package/dist/structures/structure-file-store.js +89 -0
- package/dist/structures/structure-file-store.js.map +1 -0
- package/dist/tools/block-tools.d.ts +4 -0
- package/dist/tools/block-tools.d.ts.map +1 -0
- package/dist/tools/block-tools.js +111 -0
- package/dist/tools/block-tools.js.map +1 -0
- package/dist/tools/command-tools.d.ts +4 -0
- package/dist/tools/command-tools.d.ts.map +1 -0
- package/dist/tools/command-tools.js +23 -0
- package/dist/tools/command-tools.js.map +1 -0
- package/dist/tools/common-schemas.d.ts +65 -0
- package/dist/tools/common-schemas.d.ts.map +1 -0
- package/dist/tools/common-schemas.js +32 -0
- package/dist/tools/common-schemas.js.map +1 -0
- package/dist/tools/effect-tools.d.ts +4 -0
- package/dist/tools/effect-tools.d.ts.map +1 -0
- package/dist/tools/effect-tools.js +32 -0
- package/dist/tools/effect-tools.js.map +1 -0
- package/dist/tools/entity-tools.d.ts +4 -0
- package/dist/tools/entity-tools.d.ts.map +1 -0
- package/dist/tools/entity-tools.js +133 -0
- package/dist/tools/entity-tools.js.map +1 -0
- package/dist/tools/event-tools.d.ts +4 -0
- package/dist/tools/event-tools.d.ts.map +1 -0
- package/dist/tools/event-tools.js +84 -0
- package/dist/tools/event-tools.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +30 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/inventory-tools.d.ts +4 -0
- package/dist/tools/inventory-tools.d.ts.map +1 -0
- package/dist/tools/inventory-tools.js +52 -0
- package/dist/tools/inventory-tools.js.map +1 -0
- package/dist/tools/player-tools.d.ts +4 -0
- package/dist/tools/player-tools.d.ts.map +1 -0
- package/dist/tools/player-tools.js +117 -0
- package/dist/tools/player-tools.js.map +1 -0
- package/dist/tools/property-tools.d.ts +4 -0
- package/dist/tools/property-tools.d.ts.map +1 -0
- package/dist/tools/property-tools.js +45 -0
- package/dist/tools/property-tools.js.map +1 -0
- package/dist/tools/scoreboard-tools.d.ts +4 -0
- package/dist/tools/scoreboard-tools.d.ts.map +1 -0
- package/dist/tools/scoreboard-tools.js +68 -0
- package/dist/tools/scoreboard-tools.js.map +1 -0
- package/dist/tools/server-tools.d.ts +4 -0
- package/dist/tools/server-tools.d.ts.map +1 -0
- package/dist/tools/server-tools.js +25 -0
- package/dist/tools/server-tools.js.map +1 -0
- package/dist/tools/structure-file-tools.d.ts +4 -0
- package/dist/tools/structure-file-tools.d.ts.map +1 -0
- package/dist/tools/structure-file-tools.js +57 -0
- package/dist/tools/structure-file-tools.js.map +1 -0
- package/dist/tools/structure-tools.d.ts +4 -0
- package/dist/tools/structure-tools.d.ts.map +1 -0
- package/dist/tools/structure-tools.js +91 -0
- package/dist/tools/structure-tools.js.map +1 -0
- package/dist/tools/tool-definition.d.ts +68 -0
- package/dist/tools/tool-definition.d.ts.map +1 -0
- package/dist/tools/tool-definition.js +40 -0
- package/dist/tools/tool-definition.js.map +1 -0
- package/dist/tools/tool-result.d.ts +17 -0
- package/dist/tools/tool-result.d.ts.map +1 -0
- package/dist/tools/tool-result.js +52 -0
- package/dist/tools/tool-result.js.map +1 -0
- package/dist/tools/world-tools.d.ts +4 -0
- package/dist/tools/world-tools.d.ts.map +1 -0
- package/dist/tools/world-tools.js +97 -0
- package/dist/tools/world-tools.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** A Script API module the behavior pack depends on, e.g. `@minecraft/server`. */
|
|
3
|
+
export declare const ScriptModuleSchema: z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
version: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
}, {
|
|
10
|
+
name: string;
|
|
11
|
+
version: string;
|
|
12
|
+
}>;
|
|
13
|
+
/** A Script API module the behavior pack depends on. */
|
|
14
|
+
export type ScriptModule = z.infer<typeof ScriptModuleSchema>;
|
|
15
|
+
/**
|
|
16
|
+
* The request envelope for `POST /bridge/handshake`.
|
|
17
|
+
*
|
|
18
|
+
* Sent by the behavior pack on startup. The reported Script API module
|
|
19
|
+
* versions drive server-side capability negotiation, so tools that require an
|
|
20
|
+
* unavailable capability can fail fast with a clear error.
|
|
21
|
+
*/
|
|
22
|
+
export declare const HandshakeRequestSchema: z.ZodObject<{
|
|
23
|
+
/** Bridge protocol version the behavior pack implements. */
|
|
24
|
+
protocol_version: z.ZodString;
|
|
25
|
+
/** Version of the behavior pack itself. */
|
|
26
|
+
behavior_pack_version: z.ZodString;
|
|
27
|
+
/** Minecraft / BDS version, when the behavior pack can determine it. */
|
|
28
|
+
minecraft_version: z.ZodOptional<z.ZodString>;
|
|
29
|
+
/** Script API modules and versions the behavior pack imports. */
|
|
30
|
+
script_modules: z.ZodArray<z.ZodObject<{
|
|
31
|
+
name: z.ZodString;
|
|
32
|
+
version: z.ZodString;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
name: string;
|
|
35
|
+
version: string;
|
|
36
|
+
}, {
|
|
37
|
+
name: string;
|
|
38
|
+
version: string;
|
|
39
|
+
}>, "many">;
|
|
40
|
+
/** Stable identifier of the world the behavior pack is running in. */
|
|
41
|
+
world_id: z.ZodString;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
protocol_version: string;
|
|
44
|
+
behavior_pack_version: string;
|
|
45
|
+
script_modules: {
|
|
46
|
+
name: string;
|
|
47
|
+
version: string;
|
|
48
|
+
}[];
|
|
49
|
+
world_id: string;
|
|
50
|
+
minecraft_version?: string | undefined;
|
|
51
|
+
}, {
|
|
52
|
+
protocol_version: string;
|
|
53
|
+
behavior_pack_version: string;
|
|
54
|
+
script_modules: {
|
|
55
|
+
name: string;
|
|
56
|
+
version: string;
|
|
57
|
+
}[];
|
|
58
|
+
world_id: string;
|
|
59
|
+
minecraft_version?: string | undefined;
|
|
60
|
+
}>;
|
|
61
|
+
/** The request envelope for `POST /bridge/handshake`. */
|
|
62
|
+
export type HandshakeRequest = z.infer<typeof HandshakeRequestSchema>;
|
|
63
|
+
/**
|
|
64
|
+
* A subscription the server asks the behavior pack to re-arm.
|
|
65
|
+
*
|
|
66
|
+
* A behavior pack restart loses its Script API subscriptions; the handshake
|
|
67
|
+
* response replays the still-active ones so events resume without client
|
|
68
|
+
* involvement.
|
|
69
|
+
*/
|
|
70
|
+
export declare const ResyncSubscriptionSchema: z.ZodObject<{
|
|
71
|
+
subscription_id: z.ZodString;
|
|
72
|
+
event_type: z.ZodString;
|
|
73
|
+
filter: z.ZodOptional<z.ZodUnknown>;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
subscription_id: string;
|
|
76
|
+
event_type: string;
|
|
77
|
+
filter?: unknown;
|
|
78
|
+
}, {
|
|
79
|
+
subscription_id: string;
|
|
80
|
+
event_type: string;
|
|
81
|
+
filter?: unknown;
|
|
82
|
+
}>;
|
|
83
|
+
/** A subscription the server asks the behavior pack to re-arm. */
|
|
84
|
+
export type ResyncSubscription = z.infer<typeof ResyncSubscriptionSchema>;
|
|
85
|
+
/**
|
|
86
|
+
* The response envelope for `POST /bridge/handshake`.
|
|
87
|
+
*
|
|
88
|
+
* A discriminated union on `accepted`: the server refuses a behavior pack
|
|
89
|
+
* whose bridge protocol major version is incompatible.
|
|
90
|
+
*/
|
|
91
|
+
export declare const HandshakeResponseSchema: z.ZodDiscriminatedUnion<"accepted", [z.ZodObject<{
|
|
92
|
+
accepted: z.ZodLiteral<true>;
|
|
93
|
+
/** Version of this MCP server. */
|
|
94
|
+
server_version: z.ZodString;
|
|
95
|
+
/** Bridge protocol version this server implements. */
|
|
96
|
+
protocol_version: z.ZodString;
|
|
97
|
+
/** Long-poll timeout the behavior pack should use for `GET /bridge/poll`. */
|
|
98
|
+
poll_timeout_ms: z.ZodNumber;
|
|
99
|
+
/** Subscriptions to re-arm after a behavior-pack restart. */
|
|
100
|
+
resync_subscriptions: z.ZodArray<z.ZodObject<{
|
|
101
|
+
subscription_id: z.ZodString;
|
|
102
|
+
event_type: z.ZodString;
|
|
103
|
+
filter: z.ZodOptional<z.ZodUnknown>;
|
|
104
|
+
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
subscription_id: string;
|
|
106
|
+
event_type: string;
|
|
107
|
+
filter?: unknown;
|
|
108
|
+
}, {
|
|
109
|
+
subscription_id: string;
|
|
110
|
+
event_type: string;
|
|
111
|
+
filter?: unknown;
|
|
112
|
+
}>, "many">;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
protocol_version: string;
|
|
115
|
+
accepted: true;
|
|
116
|
+
server_version: string;
|
|
117
|
+
poll_timeout_ms: number;
|
|
118
|
+
resync_subscriptions: {
|
|
119
|
+
subscription_id: string;
|
|
120
|
+
event_type: string;
|
|
121
|
+
filter?: unknown;
|
|
122
|
+
}[];
|
|
123
|
+
}, {
|
|
124
|
+
protocol_version: string;
|
|
125
|
+
accepted: true;
|
|
126
|
+
server_version: string;
|
|
127
|
+
poll_timeout_ms: number;
|
|
128
|
+
resync_subscriptions: {
|
|
129
|
+
subscription_id: string;
|
|
130
|
+
event_type: string;
|
|
131
|
+
filter?: unknown;
|
|
132
|
+
}[];
|
|
133
|
+
}>, z.ZodObject<{
|
|
134
|
+
accepted: z.ZodLiteral<false>;
|
|
135
|
+
/** Human-readable reason the connection was refused. */
|
|
136
|
+
reason: z.ZodString;
|
|
137
|
+
/** Bridge protocol version this server implements, for diagnostics. */
|
|
138
|
+
server_protocol_version: z.ZodString;
|
|
139
|
+
}, "strip", z.ZodTypeAny, {
|
|
140
|
+
accepted: false;
|
|
141
|
+
reason: string;
|
|
142
|
+
server_protocol_version: string;
|
|
143
|
+
}, {
|
|
144
|
+
accepted: false;
|
|
145
|
+
reason: string;
|
|
146
|
+
server_protocol_version: string;
|
|
147
|
+
}>]>;
|
|
148
|
+
/** The response envelope for `POST /bridge/handshake`. */
|
|
149
|
+
export type HandshakeResponse = z.infer<typeof HandshakeResponseSchema>;
|
|
150
|
+
//# sourceMappingURL=handshake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handshake.d.ts","sourceRoot":"","sources":["../../src/protocol/handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,kFAAkF;AAClF,eAAO,MAAM,kBAAkB;;;;;;;;;EAG7B,CAAC;AAEH,wDAAwD;AACxD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB;IACjC,4DAA4D;;IAE5D,2CAA2C;;IAE3C,wEAAwE;;IAExE,iEAAiE;;;;;;;;;;;IAEjE,sEAAsE;;;;;;;;;;;;;;;;;;;;EAEtE,CAAC;AAEH,yDAAyD;AACzD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;EAInC,CAAC;AAEH,kEAAkE;AAClE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;;IAGhC,kCAAkC;;IAElC,sDAAsD;;IAEtD,6EAA6E;;IAE7E,6DAA6D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAK7D,wDAAwD;;IAExD,uEAAuE;;;;;;;;;;IAGzE,CAAC;AAEH,0DAA0D;AAC1D,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SubscriptionIdSchema } from "./event.js";
|
|
3
|
+
/** A Script API module the behavior pack depends on, e.g. `@minecraft/server`. */
|
|
4
|
+
export const ScriptModuleSchema = z.object({
|
|
5
|
+
name: z.string().min(1),
|
|
6
|
+
version: z.string().min(1),
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* The request envelope for `POST /bridge/handshake`.
|
|
10
|
+
*
|
|
11
|
+
* Sent by the behavior pack on startup. The reported Script API module
|
|
12
|
+
* versions drive server-side capability negotiation, so tools that require an
|
|
13
|
+
* unavailable capability can fail fast with a clear error.
|
|
14
|
+
*/
|
|
15
|
+
export const HandshakeRequestSchema = z.object({
|
|
16
|
+
/** Bridge protocol version the behavior pack implements. */
|
|
17
|
+
protocol_version: z.string().min(1),
|
|
18
|
+
/** Version of the behavior pack itself. */
|
|
19
|
+
behavior_pack_version: z.string().min(1),
|
|
20
|
+
/** Minecraft / BDS version, when the behavior pack can determine it. */
|
|
21
|
+
minecraft_version: z.string().min(1).optional(),
|
|
22
|
+
/** Script API modules and versions the behavior pack imports. */
|
|
23
|
+
script_modules: z.array(ScriptModuleSchema),
|
|
24
|
+
/** Stable identifier of the world the behavior pack is running in. */
|
|
25
|
+
world_id: z.string().min(1),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* A subscription the server asks the behavior pack to re-arm.
|
|
29
|
+
*
|
|
30
|
+
* A behavior pack restart loses its Script API subscriptions; the handshake
|
|
31
|
+
* response replays the still-active ones so events resume without client
|
|
32
|
+
* involvement.
|
|
33
|
+
*/
|
|
34
|
+
export const ResyncSubscriptionSchema = z.object({
|
|
35
|
+
subscription_id: SubscriptionIdSchema,
|
|
36
|
+
event_type: z.string().min(1),
|
|
37
|
+
filter: z.unknown().optional(),
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* The response envelope for `POST /bridge/handshake`.
|
|
41
|
+
*
|
|
42
|
+
* A discriminated union on `accepted`: the server refuses a behavior pack
|
|
43
|
+
* whose bridge protocol major version is incompatible.
|
|
44
|
+
*/
|
|
45
|
+
export const HandshakeResponseSchema = z.discriminatedUnion("accepted", [
|
|
46
|
+
z.object({
|
|
47
|
+
accepted: z.literal(true),
|
|
48
|
+
/** Version of this MCP server. */
|
|
49
|
+
server_version: z.string(),
|
|
50
|
+
/** Bridge protocol version this server implements. */
|
|
51
|
+
protocol_version: z.string(),
|
|
52
|
+
/** Long-poll timeout the behavior pack should use for `GET /bridge/poll`. */
|
|
53
|
+
poll_timeout_ms: z.number().int().positive(),
|
|
54
|
+
/** Subscriptions to re-arm after a behavior-pack restart. */
|
|
55
|
+
resync_subscriptions: z.array(ResyncSubscriptionSchema),
|
|
56
|
+
}),
|
|
57
|
+
z.object({
|
|
58
|
+
accepted: z.literal(false),
|
|
59
|
+
/** Human-readable reason the connection was refused. */
|
|
60
|
+
reason: z.string(),
|
|
61
|
+
/** Bridge protocol version this server implements, for diagnostics. */
|
|
62
|
+
server_protocol_version: z.string(),
|
|
63
|
+
}),
|
|
64
|
+
]);
|
|
65
|
+
//# sourceMappingURL=handshake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handshake.js","sourceRoot":"","sources":["../../src/protocol/handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,kFAAkF;AAClF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC3B,CAAC,CAAC;AAKH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,4DAA4D;IAC5D,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACnC,2CAA2C;IAC3C,qBAAqB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACxC,wEAAwE;IACxE,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAC/C,iEAAiE;IACjE,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC;IAC3C,sEAAsE;IACtE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC5B,CAAC,CAAC;AAKH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,eAAe,EAAE,oBAAoB;IACrC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC;AAKH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACtE,CAAC,CAAC,MAAM,CAAC;QACP,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QACzB,kCAAkC;QAClC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;QAC1B,sDAAsD;QACtD,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE;QAC5B,6EAA6E;QAC7E,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;QAC5C,6DAA6D;QAC7D,oBAAoB,EAAE,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC;KACxD,CAAC;IACF,CAAC,CAAC,MAAM,CAAC;QACP,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1B,wDAAwD;QACxD,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;QAClB,uEAAuE;QACvE,uBAAuB,EAAE,CAAC,CAAC,MAAM,EAAE;KACpC,CAAC;CACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge protocol — the wire contract between the MCP server and the BDS
|
|
3
|
+
* behavior pack.
|
|
4
|
+
*
|
|
5
|
+
* This module is a self-contained leaf: it depends only on `zod` and nothing
|
|
6
|
+
* else in `src/`, so it can be extracted into a package shared with the
|
|
7
|
+
* behavior-pack repository without untangling dependencies.
|
|
8
|
+
*/
|
|
9
|
+
export * from "./protocol-version.js";
|
|
10
|
+
export * from "./command.js";
|
|
11
|
+
export * from "./result.js";
|
|
12
|
+
export * from "./event.js";
|
|
13
|
+
export * from "./handshake.js";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge protocol — the wire contract between the MCP server and the BDS
|
|
3
|
+
* behavior pack.
|
|
4
|
+
*
|
|
5
|
+
* This module is a self-contained leaf: it depends only on `zod` and nothing
|
|
6
|
+
* else in `src/`, so it can be extracted into a package shared with the
|
|
7
|
+
* behavior-pack repository without untangling dependencies.
|
|
8
|
+
*/
|
|
9
|
+
export * from "./protocol-version.js";
|
|
10
|
+
export * from "./command.js";
|
|
11
|
+
export * from "./result.js";
|
|
12
|
+
export * from "./event.js";
|
|
13
|
+
export * from "./handshake.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version of the bridge protocol implemented by this server — the contract
|
|
3
|
+
* between the MCP server and the BDS behavior pack.
|
|
4
|
+
*
|
|
5
|
+
* Semantic versioning applies. The behavior pack and server are compatible
|
|
6
|
+
* when they share the same major version; the major is negotiated during the
|
|
7
|
+
* handshake (see `handshake.ts`).
|
|
8
|
+
*/
|
|
9
|
+
export declare const PROTOCOL_VERSION = "1.0.0";
|
|
10
|
+
/** Extracts the major version from a semver string, or `null` if unparseable. */
|
|
11
|
+
export declare function parseMajor(version: string): number | null;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a peer's protocol version is compatible with this server's.
|
|
14
|
+
*
|
|
15
|
+
* Compatibility requires an equal, parseable major version.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isProtocolCompatible(peerVersion: string): boolean;
|
|
18
|
+
//# sourceMappingURL=protocol-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-version.d.ts","sourceRoot":"","sources":["../../src/protocol/protocol-version.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAIxC,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIzD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAIjE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version of the bridge protocol implemented by this server — the contract
|
|
3
|
+
* between the MCP server and the BDS behavior pack.
|
|
4
|
+
*
|
|
5
|
+
* Semantic versioning applies. The behavior pack and server are compatible
|
|
6
|
+
* when they share the same major version; the major is negotiated during the
|
|
7
|
+
* handshake (see `handshake.ts`).
|
|
8
|
+
*/
|
|
9
|
+
export const PROTOCOL_VERSION = "1.0.0";
|
|
10
|
+
const SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/;
|
|
11
|
+
/** Extracts the major version from a semver string, or `null` if unparseable. */
|
|
12
|
+
export function parseMajor(version) {
|
|
13
|
+
const match = SEMVER.exec(version);
|
|
14
|
+
if (!match)
|
|
15
|
+
return null;
|
|
16
|
+
return Number(match[1]);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Whether a peer's protocol version is compatible with this server's.
|
|
20
|
+
*
|
|
21
|
+
* Compatibility requires an equal, parseable major version.
|
|
22
|
+
*/
|
|
23
|
+
export function isProtocolCompatible(peerVersion) {
|
|
24
|
+
const peerMajor = parseMajor(peerVersion);
|
|
25
|
+
const ourMajor = parseMajor(PROTOCOL_VERSION);
|
|
26
|
+
return peerMajor !== null && ourMajor !== null && peerMajor === ourMajor;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=protocol-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-version.js","sourceRoot":"","sources":["../../src/protocol/protocol-version.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAExC,MAAM,MAAM,GAAG,kCAAkC,CAAC;AAElD,iFAAiF;AACjF,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAmB;IACtD,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC9C,OAAO,SAAS,KAAK,IAAI,IAAI,QAAQ,KAAK,IAAI,IAAI,SAAS,KAAK,QAAQ,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* An error reported by the behavior pack for a failed command.
|
|
4
|
+
*
|
|
5
|
+
* `code` is a free-form string at the protocol layer — the behavior pack may
|
|
6
|
+
* report codes the server does not enumerate. The server narrows it to a known
|
|
7
|
+
* {@link import("../errors/error-codes.js").ErrorCode} where possible.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CommandErrorSchema: z.ZodObject<{
|
|
10
|
+
code: z.ZodString;
|
|
11
|
+
message: z.ZodString;
|
|
12
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
details?: unknown;
|
|
17
|
+
}, {
|
|
18
|
+
code: string;
|
|
19
|
+
message: string;
|
|
20
|
+
details?: unknown;
|
|
21
|
+
}>;
|
|
22
|
+
/** An error reported by the behavior pack for a failed command. */
|
|
23
|
+
export type CommandError = z.infer<typeof CommandErrorSchema>;
|
|
24
|
+
/**
|
|
25
|
+
* The result of a command, reported by the behavior pack via
|
|
26
|
+
* `POST /bridge/result`.
|
|
27
|
+
*
|
|
28
|
+
* Modeled as a discriminated union on `status`: an `ok` result carries a
|
|
29
|
+
* `result` payload and an `error` result carries an `error` — the two are
|
|
30
|
+
* mutually exclusive by construction.
|
|
31
|
+
*/
|
|
32
|
+
export declare const CommandResultSchema: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
|
|
33
|
+
id: z.ZodString;
|
|
34
|
+
status: z.ZodLiteral<"ok">;
|
|
35
|
+
result: z.ZodUnknown;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
status: "ok";
|
|
38
|
+
id: string;
|
|
39
|
+
result?: unknown;
|
|
40
|
+
}, {
|
|
41
|
+
status: "ok";
|
|
42
|
+
id: string;
|
|
43
|
+
result?: unknown;
|
|
44
|
+
}>, z.ZodObject<{
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
status: z.ZodLiteral<"error">;
|
|
47
|
+
error: z.ZodObject<{
|
|
48
|
+
code: z.ZodString;
|
|
49
|
+
message: z.ZodString;
|
|
50
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
51
|
+
}, "strip", z.ZodTypeAny, {
|
|
52
|
+
code: string;
|
|
53
|
+
message: string;
|
|
54
|
+
details?: unknown;
|
|
55
|
+
}, {
|
|
56
|
+
code: string;
|
|
57
|
+
message: string;
|
|
58
|
+
details?: unknown;
|
|
59
|
+
}>;
|
|
60
|
+
}, "strip", z.ZodTypeAny, {
|
|
61
|
+
error: {
|
|
62
|
+
code: string;
|
|
63
|
+
message: string;
|
|
64
|
+
details?: unknown;
|
|
65
|
+
};
|
|
66
|
+
status: "error";
|
|
67
|
+
id: string;
|
|
68
|
+
}, {
|
|
69
|
+
error: {
|
|
70
|
+
code: string;
|
|
71
|
+
message: string;
|
|
72
|
+
details?: unknown;
|
|
73
|
+
};
|
|
74
|
+
status: "error";
|
|
75
|
+
id: string;
|
|
76
|
+
}>]>;
|
|
77
|
+
/** The result of a command, reported by the behavior pack. */
|
|
78
|
+
export type CommandResult = z.infer<typeof CommandResultSchema>;
|
|
79
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/protocol/result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;EAI7B,CAAC;AAEH,mEAAmE;AACnE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAW9B,CAAC;AAEH,8DAA8D;AAC9D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CommandIdSchema } from "./command.js";
|
|
3
|
+
/**
|
|
4
|
+
* An error reported by the behavior pack for a failed command.
|
|
5
|
+
*
|
|
6
|
+
* `code` is a free-form string at the protocol layer — the behavior pack may
|
|
7
|
+
* report codes the server does not enumerate. The server narrows it to a known
|
|
8
|
+
* {@link import("../errors/error-codes.js").ErrorCode} where possible.
|
|
9
|
+
*/
|
|
10
|
+
export const CommandErrorSchema = z.object({
|
|
11
|
+
code: z.string().min(1),
|
|
12
|
+
message: z.string(),
|
|
13
|
+
details: z.unknown().optional(),
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* The result of a command, reported by the behavior pack via
|
|
17
|
+
* `POST /bridge/result`.
|
|
18
|
+
*
|
|
19
|
+
* Modeled as a discriminated union on `status`: an `ok` result carries a
|
|
20
|
+
* `result` payload and an `error` result carries an `error` — the two are
|
|
21
|
+
* mutually exclusive by construction.
|
|
22
|
+
*/
|
|
23
|
+
export const CommandResultSchema = z.discriminatedUnion("status", [
|
|
24
|
+
z.object({
|
|
25
|
+
id: CommandIdSchema,
|
|
26
|
+
status: z.literal("ok"),
|
|
27
|
+
result: z.unknown(),
|
|
28
|
+
}),
|
|
29
|
+
z.object({
|
|
30
|
+
id: CommandIdSchema,
|
|
31
|
+
status: z.literal("error"),
|
|
32
|
+
error: CommandErrorSchema,
|
|
33
|
+
}),
|
|
34
|
+
]);
|
|
35
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/protocol/result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAKH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,kBAAkB,CAAC,QAAQ,EAAE;IAChE,CAAC,CAAC,MAAM,CAAC;QACP,EAAE,EAAE,eAAe;QACnB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QACvB,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;KACpB,CAAC;IACF,CAAC,CAAC,MAAM,CAAC;QACP,EAAE,EAAE,eAAe;QACnB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;QAC1B,KAAK,EAAE,kBAAkB;KAC1B,CAAC;CACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Correlation identifier for a queued command (`cmd_<ULID>`).
|
|
3
|
+
*
|
|
4
|
+
* A plain `string` alias: the wire protocol carries these as strings, and a
|
|
5
|
+
* branded type would force casts at every protocol boundary for no real
|
|
6
|
+
* safety gain here.
|
|
7
|
+
*/
|
|
8
|
+
export type CommandId = string;
|
|
9
|
+
/** Identifier for an event subscription (`sub_<ULID>`). */
|
|
10
|
+
export type SubscriptionId = string;
|
|
11
|
+
/** Creates a new command identifier. */
|
|
12
|
+
export declare function newCommandId(): CommandId;
|
|
13
|
+
/** Creates a new subscription identifier. */
|
|
14
|
+
export declare function newSubscriptionId(): SubscriptionId;
|
|
15
|
+
//# sourceMappingURL=command-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-id.d.ts","sourceRoot":"","sources":["../../src/queue/command-id.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,2DAA2D;AAC3D,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAkCpC,wCAAwC;AACxC,wBAAgB,YAAY,IAAI,SAAS,CAExC;AAED,6CAA6C;AAC7C,wBAAgB,iBAAiB,IAAI,cAAc,CAElD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { randomInt } from "node:crypto";
|
|
2
|
+
const CROCKFORD_BASE32 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
3
|
+
const TIMESTAMP_LENGTH = 10;
|
|
4
|
+
const RANDOMNESS_LENGTH = 16;
|
|
5
|
+
/** Encodes a millisecond timestamp as 10 Crockford base32 characters. */
|
|
6
|
+
function encodeTimestamp(timestamp) {
|
|
7
|
+
let remaining = timestamp;
|
|
8
|
+
let encoded = "";
|
|
9
|
+
for (let i = 0; i < TIMESTAMP_LENGTH; i += 1) {
|
|
10
|
+
encoded = CROCKFORD_BASE32.charAt(remaining % 32) + encoded;
|
|
11
|
+
remaining = Math.floor(remaining / 32);
|
|
12
|
+
}
|
|
13
|
+
return encoded;
|
|
14
|
+
}
|
|
15
|
+
/** Generates 16 Crockford base32 characters of cryptographic randomness. */
|
|
16
|
+
function encodeRandomness() {
|
|
17
|
+
let encoded = "";
|
|
18
|
+
for (let i = 0; i < RANDOMNESS_LENGTH; i += 1) {
|
|
19
|
+
encoded += CROCKFORD_BASE32.charAt(randomInt(32));
|
|
20
|
+
}
|
|
21
|
+
return encoded;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generates a ULID — a 26-character, lexicographically sortable identifier
|
|
25
|
+
* combining a 48-bit timestamp with 80 bits of randomness.
|
|
26
|
+
*/
|
|
27
|
+
function ulid() {
|
|
28
|
+
return encodeTimestamp(Date.now()) + encodeRandomness();
|
|
29
|
+
}
|
|
30
|
+
/** Creates a new command identifier. */
|
|
31
|
+
export function newCommandId() {
|
|
32
|
+
return `cmd_${ulid()}`;
|
|
33
|
+
}
|
|
34
|
+
/** Creates a new subscription identifier. */
|
|
35
|
+
export function newSubscriptionId() {
|
|
36
|
+
return `sub_${ulid()}`;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=command-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-id.js","sourceRoot":"","sources":["../../src/queue/command-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAcxC,MAAM,gBAAgB,GAAG,kCAAkC,CAAC;AAC5D,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,yEAAyE;AACzE,SAAS,eAAe,CAAC,SAAiB;IACxC,IAAI,SAAS,GAAG,SAAS,CAAC;IAC1B,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;QAC5D,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,4EAA4E;AAC5E,SAAS,gBAAgB;IACvB,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,iBAAiB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,SAAS,IAAI;IACX,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,gBAAgB,EAAE,CAAC;AAC1D,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,IAAI,EAAE,EAAE,CAAC;AACzB,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,IAAI,EAAE,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Command } from "../protocol/command.js";
|
|
2
|
+
import type { CommandResult } from "../protocol/result.js";
|
|
3
|
+
import type { CommandThrottle } from "./command-throttle.js";
|
|
4
|
+
/** A request to enqueue a command and await its correlated result. */
|
|
5
|
+
export interface EnqueueRequest {
|
|
6
|
+
/** Command kind — the MCP tool name, e.g. `mc_block_set`. */
|
|
7
|
+
readonly kind: string;
|
|
8
|
+
/** Command payload, validated against the tool's input schema by the caller. */
|
|
9
|
+
readonly payload: unknown;
|
|
10
|
+
/** Server-side correlation id linking the originating request to this command. */
|
|
11
|
+
readonly correlationId: string;
|
|
12
|
+
/** How long, in milliseconds, to await a result before failing. */
|
|
13
|
+
readonly timeoutMs: number;
|
|
14
|
+
}
|
|
15
|
+
/** Options for a long-poll dequeue. */
|
|
16
|
+
export interface DequeueOptions {
|
|
17
|
+
/** Maximum number of commands to return in one batch. */
|
|
18
|
+
readonly max: number;
|
|
19
|
+
/** How long, in milliseconds, to hold the poll open while the queue is empty. */
|
|
20
|
+
readonly timeoutMs: number;
|
|
21
|
+
/** Aborts the poll when the underlying HTTP connection closes. */
|
|
22
|
+
readonly signal: AbortSignal;
|
|
23
|
+
}
|
|
24
|
+
/** A point-in-time snapshot of queue state, for health checks and metrics. */
|
|
25
|
+
export interface CommandQueueStats {
|
|
26
|
+
/** Commands enqueued but not yet dequeued. */
|
|
27
|
+
readonly depth: number;
|
|
28
|
+
/** Commands dequeued but not yet settled. */
|
|
29
|
+
readonly inFlight: number;
|
|
30
|
+
/** Whether a behavior pack is currently considered connected. */
|
|
31
|
+
readonly bridgeConnected: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* In-memory command queue bridging MCP tool calls to the behavior pack.
|
|
35
|
+
*
|
|
36
|
+
* Tool calls enqueue commands and await their correlated results; the behavior
|
|
37
|
+
* pack drains commands via a long poll and reports results back. The queue is
|
|
38
|
+
* not persisted across restarts.
|
|
39
|
+
*/
|
|
40
|
+
export interface CommandQueue {
|
|
41
|
+
/**
|
|
42
|
+
* Enqueues a command and resolves with the behavior pack's result.
|
|
43
|
+
*
|
|
44
|
+
* Resolves with a {@link CommandResult} (`ok` or `error`) once the pack
|
|
45
|
+
* reports one. Rejects with a `BridgeError` when the bridge itself cannot
|
|
46
|
+
* complete the command: `COMMAND_THROTTLED`, `QUEUE_FULL`,
|
|
47
|
+
* `BRIDGE_DISCONNECTED`, or `COMMAND_TIMEOUT`.
|
|
48
|
+
*/
|
|
49
|
+
enqueueAndAwait(request: EnqueueRequest): Promise<CommandResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Long-poll dequeue for the behavior pack.
|
|
52
|
+
*
|
|
53
|
+
* Resolves immediately with up to `max` commands when work is available,
|
|
54
|
+
* otherwise holds the poll open until a command arrives, `timeoutMs`
|
|
55
|
+
* elapses, or the request is aborted — resolving with `[]` in the latter
|
|
56
|
+
* two cases.
|
|
57
|
+
*/
|
|
58
|
+
dequeue(options: DequeueOptions): Promise<Command[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Delivers a result reported by the behavior pack.
|
|
61
|
+
*
|
|
62
|
+
* @returns `false` if no pending command matches `result.id` — typically a
|
|
63
|
+
* result that arrived after the command's deadline.
|
|
64
|
+
*/
|
|
65
|
+
settle(result: CommandResult): boolean;
|
|
66
|
+
/** Returns a snapshot of queue state. */
|
|
67
|
+
stats(): CommandQueueStats;
|
|
68
|
+
/**
|
|
69
|
+
* Rejects all pending commands and releases parked polls. Used during
|
|
70
|
+
* graceful shutdown; the queue must not be used afterwards.
|
|
71
|
+
*/
|
|
72
|
+
close(): void;
|
|
73
|
+
}
|
|
74
|
+
/** Configuration for {@link createCommandQueue}. */
|
|
75
|
+
export interface CommandQueueOptions {
|
|
76
|
+
/** Per-kind throttle protecting the behavior pack's script watchdog. */
|
|
77
|
+
readonly throttle: CommandThrottle;
|
|
78
|
+
/** Maximum outstanding commands before enqueue fails with `QUEUE_FULL`. */
|
|
79
|
+
readonly maxOutstanding: number;
|
|
80
|
+
/**
|
|
81
|
+
* Milliseconds after the last poll during which the behavior pack is still
|
|
82
|
+
* considered connected. Should exceed the poll timeout.
|
|
83
|
+
*/
|
|
84
|
+
readonly livenessWindowMs: number;
|
|
85
|
+
/** Clock source, injectable for tests. Defaults to `Date.now`. */
|
|
86
|
+
readonly now?: () => number;
|
|
87
|
+
}
|
|
88
|
+
/** Creates an in-memory {@link CommandQueue}. */
|
|
89
|
+
export declare function createCommandQueue(options: CommandQueueOptions): CommandQueue;
|
|
90
|
+
//# sourceMappingURL=command-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-queue.d.ts","sourceRoot":"","sources":["../../src/queue/command-queue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,sEAAsE;AACtE,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,kFAAkF;IAClF,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,iFAAiF;IACjF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B;AAED,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACnC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAEjE;;;;;;;OAOG;IACH,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAErD;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC;IAEvC,yCAAyC;IACzC,KAAK,IAAI,iBAAiB,CAAC;IAE3B;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,2EAA2E;IAC3E,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,kEAAkE;IAClE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAiBD,iDAAiD;AACjD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CA8J7E"}
|