@ankorcs/protocol 0.0.0-stage → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.6.1
4
+
5
+ No contract changes. The first release that the release workflow publishes.
6
+
7
+ ## 0.6.0
8
+
9
+ Initial release.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Nicolai Cornelis
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # @ankorcs/protocol
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The wire protocol between Ankor game-host agents and the controller that runs them: the agent
4
+ socket, the event-batch upload and the gameplay events it carries, `agent.yml`, and the paths,
5
+ limits and timings both ends share. It holds zod schemas, constants and types, and an `agent.yml`
6
+ renderer.
7
+
8
+ ```sh
9
+ npm install @ankorcs/protocol
10
+ ```
11
+
12
+ ```ts
13
+ import { AgentToControllerMessage, PROTOCOL_VERSION } from '@ankorcs/protocol';
14
+
15
+ const message = AgentToControllerMessage.parse(JSON.parse(frame));
16
+ ```
17
+
18
+ - `@ankorcs/protocol` is the wire: schemas and constants. The
19
+ [protocol reference](https://docs.ankor.sh/reference/) documents every message from their JSDoc.
20
+ - `@ankorcs/protocol/helpers` has functions both ends share, such as slot layout checks and
21
+ `gsltHint`. It is not part of the protocol reference.
22
+ - `@ankorcs/protocol/agent-yml` renders the `agent.yml` a service hands a node. It is the only
23
+ module that loads `yaml`.
24
+ - `@ankorcs/protocol/session` is the controller's session on top of these schemas, described under
25
+ [Agent session](#agent-session).
26
+ - `@ankorcs/protocol/container` is the interface between the agent and the game containers it runs:
27
+ the environment the CS2 image and the plugin read, the local plugin socket's messages, the cfg
28
+ files both sides exec and the handoff to a replacement agent. It is not part of the wire to the
29
+ controller.
30
+ - `@ankorcs/protocol/node-setup.sh` is the script that installs a game node, which a controller
31
+ serves to operators at [`SETUP_SCRIPT_PATH`](https://github.com/ankorcs/ankor/blob/e50c71d936be7ef7401fca02723c79f2d550870b/packages/protocol/src/paths.ts).
32
+ - `@ankorcs/protocol/asyncapi.yaml` and `@ankorcs/protocol/agent-yml.schema.json` are the
33
+ protocol's AsyncAPI 3.1 document and the JSON Schema of `agent.yml`, built from the schemas and
34
+ their JSDoc.
35
+
36
+ ## Agent session
37
+
38
+ `@ankorcs/protocol/session` pairs each request with its reply on the agent socket and types the
39
+ reply's `data` by the request. The [protocol overview](https://docs.ankor.sh/protocol/) shows how a
40
+ controller uses it, and [A minimal controller](https://docs.ankor.sh/protocol/minimal-controller/)
41
+ uses it step by step. Each export's JSDoc documents it. Tests drive the session with a fake
42
+ `send` and frames as text.
43
+
44
+ ## Changing the protocol
45
+
46
+ 1. Edit the zod schemas in [`src`](https://github.com/ankorcs/ankor/tree/e50c71d936be7ef7401fca02723c79f2d550870b/packages/protocol/src). JSDoc on a schema or key becomes its description in the
47
+ reference; per-event semantics belong there, not in the guides.
48
+ [Conventions](https://github.com/ankorcs/ankor/blob/e50c71d936be7ef7401fca02723c79f2d550870b/packages/protocol/CONVENTIONS.md) says how to write it.
49
+ 2. Add or update the message's example in [reference/examples.json](https://github.com/ankorcs/ankor/blob/e50c71d936be7ef7401fca02723c79f2d550870b/packages/protocol/reference/examples.json), and a
50
+ new message's support and group in [reference/asyncapi.ts](https://github.com/ankorcs/ankor/blob/e50c71d936be7ef7401fca02723c79f2d550870b/packages/protocol/reference/asyncapi.ts).
51
+ 3. Run `npm run build`. After `tsc`, it writes `dist/asyncapi.yaml` and `dist/agent-yml.schema.json`.
52
+ It fails on a missing or mismatched example, an unlisted message, a link it cannot place, or a
53
+ refinement whose JSDoc does not state its rule. Then
54
+ [reference/dist-links.ts](https://github.com/ankorcs/ankor/blob/e50c71d936be7ef7401fca02723c79f2d550870b/packages/protocol/reference/dist-links.ts) makes the guide links in the comments of
55
+ `dist/` absolute, and [tsconfig.dist.json](https://github.com/ankorcs/ankor/blob/e50c71d936be7ef7401fca02723c79f2d550870b/packages/protocol/tsconfig.dist.json) checks that `dist/` still parses
56
+ and typechecks. The package ships `dist/` and no source. Preview the reference with `npm run docs:dev`
57
+ from the repository root, at `/reference/`.
58
+
59
+ - `unsupportedAgentYmlKeys` stays in agent-config.ts, beside the private `agent.yml` schema it reads.
60
+ - values.ts must not import helpers.ts: the cycle through agent-socket.ts would leave its schemas
61
+ undefined at load. What both need lives in [checks.ts](https://github.com/ankorcs/ankor/blob/e50c71d936be7ef7401fca02723c79f2d550870b/packages/protocol/src/checks.ts).
62
+ - The plugin's C# copies of the contract are kept in step by hand, as
63
+ [Change the contract](https://github.com/ankorcs/ankor/blob/e50c71d936be7ef7401fca02723c79f2d550870b/DEVELOPMENT.md#change-the-contract) describes.
64
+ - Judge a field against the protocol, not [ankor.sh](https://ankor.sh). A value ankor.sh always sends as a constant, or
65
+ never reads, can serve another controller. The agent is the only node-side implementation,
66
+ so it alone shows whether a field is written or read on that side.
67
+ - Make a field only as strict as the agent needs; rules [ankor.sh](https://ankor.sh) sets for its users stay in ankor.sh.
68
+ A rule both ends depend on is an exported value the agent itself uses, not JSDoc prose.
69
+ - `PROTOCOL_VERSION` is the package's `major.minor`, and a test holds it to `package.json`.
70
+ [Versioning](https://docs.ankor.sh/protocol/versioning/) says what a minor may change and how a receiver
71
+ treats what a newer peer adds.
72
+ - Keep a schema a plain `z.object`, so that unknown keys are ignored, and check a new union with
73
+ `unknownMessageType` from the receiver's side.
@@ -0,0 +1,101 @@
1
+ /**
2
+ * The `agent.yml` schema that the agent's reader and whoever renders the file for a node share.
3
+ * Parsing fills in the defaults for the keys the file may leave out.
4
+ */
5
+ import { z } from 'zod';
6
+ /**
7
+ * The node's `agent.yml` as the agent reads it. It is {@link RawAgentConfigSchema} with the checks
8
+ * that span slots, and it fills in `pinned_ip` and `demo_upload` as null when absent.
9
+ *
10
+ * Rejected when two `slots` share an `id` or a `gslt`, or when two ports are equal. Every slot's
11
+ * `port` and `tv_port` count, so a slot's two ports differ too. It is also rejected when a port is
12
+ * {@link EVENT_RELAY_PORT}, where the agent listens for plugins.
13
+ */
14
+ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
15
+ token: z.ZodString;
16
+ controller: z.ZodObject<{
17
+ host: z.ZodString;
18
+ tls: z.ZodBoolean;
19
+ socket_path: z.ZodDefault<z.ZodString>;
20
+ events_path: z.ZodDefault<z.ZodString>;
21
+ }, z.core.$strip>;
22
+ pinned_ip: z.ZodOptional<z.ZodString>;
23
+ cs2_image: z.ZodString;
24
+ agent_image: z.ZodString;
25
+ memory_mb: z.ZodOptional<z.ZodNumber>;
26
+ auto_update: z.ZodDefault<z.ZodBoolean>;
27
+ official_images_only: z.ZodDefault<z.ZodBoolean>;
28
+ slots: z.ZodArray<z.ZodObject<{
29
+ id: z.ZodString;
30
+ port: z.ZodNumber;
31
+ tv_port: z.ZodNumber;
32
+ gslt: z.ZodString;
33
+ }, z.core.$strip>>;
34
+ demo_upload: z.ZodOptional<z.ZodObject<{
35
+ url: z.ZodURL;
36
+ header: z.ZodOptional<z.ZodObject<{
37
+ name: z.ZodString;
38
+ value: z.ZodString;
39
+ }, z.core.$strip>>;
40
+ limit_mbit: z.ZodOptional<z.ZodNumber>;
41
+ }, z.core.$strip>>;
42
+ }, z.core.$strip>, z.ZodTransform<{
43
+ pinned_ip: string | null;
44
+ demo_upload: {
45
+ url: string;
46
+ header: {
47
+ name: string;
48
+ value: string;
49
+ } | null;
50
+ limit_mbit: number | null;
51
+ } | null;
52
+ token: string;
53
+ controller: {
54
+ host: string;
55
+ tls: boolean;
56
+ socket_path: string;
57
+ events_path: string;
58
+ };
59
+ cs2_image: string;
60
+ agent_image: string;
61
+ auto_update: boolean;
62
+ official_images_only: boolean;
63
+ slots: {
64
+ id: string;
65
+ port: number;
66
+ tv_port: number;
67
+ gslt: string;
68
+ }[];
69
+ memory_mb?: number | undefined;
70
+ }, {
71
+ token: string;
72
+ controller: {
73
+ host: string;
74
+ tls: boolean;
75
+ socket_path: string;
76
+ events_path: string;
77
+ };
78
+ cs2_image: string;
79
+ agent_image: string;
80
+ auto_update: boolean;
81
+ official_images_only: boolean;
82
+ slots: {
83
+ id: string;
84
+ port: number;
85
+ tv_port: number;
86
+ gslt: string;
87
+ }[];
88
+ pinned_ip?: string | undefined;
89
+ memory_mb?: number | undefined;
90
+ demo_upload?: {
91
+ url: string;
92
+ header?: {
93
+ name: string;
94
+ value: string;
95
+ } | undefined;
96
+ limit_mbit?: number | undefined;
97
+ } | undefined;
98
+ }>>;
99
+ export type AgentConfig = z.infer<typeof AgentConfigSchema>;
100
+ /** Keys the file carries that this agent does not read, as dotted paths. Parsing ignores them. */
101
+ export declare function unsupportedAgentYmlKeys(raw: unknown): string[];
@@ -0,0 +1,144 @@
1
+ /**
2
+ * The `agent.yml` schema that the agent's reader and whoever renders the file for a node share.
3
+ * Parsing fills in the defaults for the keys the file may leave out.
4
+ */
5
+ import { z } from 'zod';
6
+ import { MAX_SLOTS } from './limits.js';
7
+ import { addGsltIssues, addSlotLayoutIssues } from './helpers.js';
8
+ import { AGENT_MIN_SLOT_PORT, ConfiguredSlot, DemoUploadHeader, DemoUploadLimit, DemoUploadUrl, ImageReference, Ipv4, MemoryLimit, NodeToken, ControllerHost, ControllerPath, } from './values.js';
9
+ import { DEFAULT_EVENTS_PATH, DEFAULT_SOCKET_PATH } from './paths.js';
10
+ const DemoUploadFields = z.object({
11
+ /**
12
+ * The `http` or `https` URL finished demos are posted to. Rejected when it carries a user name or a
13
+ * password, which belong in `header`.
14
+ */
15
+ url: DemoUploadUrl,
16
+ /** One header sent with every upload. */
17
+ header: DemoUploadHeader.optional(),
18
+ /**
19
+ * Megabits a second an upload may send while a game server runs on the node. Without it, uploads
20
+ * run at full speed.
21
+ */
22
+ limit_mbit: DemoUploadLimit.optional(),
23
+ });
24
+ const ControllerFields = z.object({
25
+ /**
26
+ * The controller's host with an optional port, without scheme or path, such as
27
+ * `cs.example.com`, `192.168.0.10:3000` or `[fd00::1]`. The agent may dial over IPv6, but players
28
+ * need IPv4.
29
+ *
30
+ * Rejected when it contains whitespace, a control character, `/`, `\`, `?` or `#`. It is also
31
+ * rejected unless `http://` followed by the value parses as a URL that has a host, an optional
32
+ * port and nothing else, such as a user name.
33
+ */
34
+ host: ControllerHost,
35
+ /** Whether the agent dials `wss://` and `https://` rather than `ws://` and `http://`. */
36
+ tls: z.boolean(),
37
+ /** The agent socket's path on `host`, a `/` followed by URL path characters. */
38
+ socket_path: ControllerPath.default(DEFAULT_SOCKET_PATH),
39
+ /** The path on `host` that event batches are posted to, a `/` followed by URL path characters. */
40
+ events_path: ControllerPath.default(DEFAULT_EVENTS_PATH),
41
+ });
42
+ const RawAgentConfigSchema = z
43
+ .object({
44
+ /**
45
+ * The node token from the controller, 32 to 128 letters and digits. [Node
46
+ * tokens](https://docs.ankor.sh/protocol/#node-tokens) explains how one is made. **Keep the file secret.**
47
+ */
48
+ token: NodeToken,
49
+ /** Where the agent dials the controller. */
50
+ controller: ControllerFields,
51
+ /**
52
+ * The IPv4 address players connect to, in place of the one the agent looks up. Rejected unless it
53
+ * is four numbers from 0 to 255 joined by dots, each without leading zeros.
54
+ */
55
+ pinned_ip: Ipv4.optional(),
56
+ /** The `ankor-cs2` image future game servers run, as a Docker image reference. */
57
+ cs2_image: ImageReference,
58
+ /**
59
+ * The agent's image, which `node-setup.sh --update` runs and the agent replaces itself from, as
60
+ * a Docker image reference.
61
+ */
62
+ agent_image: ImageReference,
63
+ /**
64
+ * MiB of memory each game container may use. Without it, game containers are not capped. CS2
65
+ * installs and updates are exempt.
66
+ *
67
+ * Rejected when it is not a whole number from {@link MIN_MEMORY_MB} to {@link MAX_MEMORY_MB}.
68
+ */
69
+ memory_mb: MemoryLimit.optional(),
70
+ /**
71
+ * Whether the agent keeps the node up to date on its own. It updates CS2 to the newest public
72
+ * build and refuses launches while it is behind that build. It also moves `cs2_image` and
73
+ * `agent_image` to the newest release or rebuild in their major. It reads their tags from the
74
+ * registry every {@link IMAGE_UPDATE_POLL_INTERVAL_MS}, and leaves an image named by digest or
75
+ * by a custom tag alone. When false, only {@link ControllerUpdateCs2 | update_cs2},
76
+ * {@link ControllerUpdateCs2Image | update_cs2_image} and {@link ControllerUpdateAgent | update_agent} change
77
+ * the build and the images.
78
+ */
79
+ auto_update: z.boolean().default(true),
80
+ /**
81
+ * Whether the node runs only the official images: `agent_image` from
82
+ * {@link OFFICIAL_IMAGES.agent} and `cs2_image` from {@link OFFICIAL_IMAGES.cs2}, with any tag or
83
+ * digest. While it is on, the agent refuses an {@link ControllerUpdateAgent | update_agent} or
84
+ * {@link ControllerUpdateCs2Image | update_cs2_image} to any other image with
85
+ * `image_not_allowed`, and `node-setup.sh` refuses to run one.
86
+ *
87
+ * Only the node's operator can turn it off, by setting it to false in the file, to run images of
88
+ * their own. {@link ControllerSetConfig | set_config} cannot change it. If the `agent.yml` that
89
+ * `node-setup.sh` fetches from the controller turns it off, the script stops.
90
+ */
91
+ official_images_only: z.boolean().default(true),
92
+ /**
93
+ * The node's game server slots. Empty for a node that runs no servers yet. Such a node connects
94
+ * and reports, but accepts no launch.
95
+ */
96
+ slots: z.array(ConfiguredSlot).max(MAX_SLOTS),
97
+ /**
98
+ * Where finished demos are uploaded. Without it, demos stay on the node.
99
+ * [Demo uploads](https://docs.ankor.sh/protocol/demos/) describes the request.
100
+ */
101
+ demo_upload: DemoUploadFields.optional(),
102
+ });
103
+ /**
104
+ * The node's `agent.yml` as the agent reads it. It is {@link RawAgentConfigSchema} with the checks
105
+ * that span slots, and it fills in `pinned_ip` and `demo_upload` as null when absent.
106
+ *
107
+ * Rejected when two `slots` share an `id` or a `gslt`, or when two ports are equal. Every slot's
108
+ * `port` and `tv_port` count, so a slot's two ports differ too. It is also rejected when a port is
109
+ * {@link EVENT_RELAY_PORT}, where the agent listens for plugins.
110
+ */
111
+ export const AgentConfigSchema = RawAgentConfigSchema.superRefine((config, ctx) => {
112
+ // Add list-wide issues not already covered by individual slot schemas.
113
+ addSlotLayoutIssues(ctx, config.slots, AGENT_MIN_SLOT_PORT, ['slots']);
114
+ addGsltIssues(ctx, config.slots, ['slots']);
115
+ }).transform((config) => ({
116
+ ...config,
117
+ pinned_ip: config.pinned_ip ?? null,
118
+ demo_upload: config.demo_upload === undefined
119
+ ? null
120
+ : { url: config.demo_upload.url, header: config.demo_upload.header ?? null, limit_mbit: config.demo_upload.limit_mbit ?? null },
121
+ }));
122
+ function isRecord(value) {
123
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
124
+ }
125
+ /** Keys the file carries that this agent does not read, as dotted paths. Parsing ignores them. */
126
+ export function unsupportedAgentYmlKeys(raw) {
127
+ const unknown = (value, known, prefix) => isRecord(value)
128
+ ? Object.keys(value).filter((key) => !(key in known)).map((key) => `${prefix}${key}`)
129
+ : [];
130
+ if (!isRecord(raw)) {
131
+ return [];
132
+ }
133
+ const keys = unknown(raw, RawAgentConfigSchema.shape, '');
134
+ if (Array.isArray(raw['slots'])) {
135
+ raw['slots'].forEach((slot, index) => keys.push(...unknown(slot, ConfiguredSlot.shape, `slots.${index}.`)));
136
+ }
137
+ keys.push(...unknown(raw['controller'], ControllerFields.shape, 'controller.'));
138
+ const upload = raw['demo_upload'];
139
+ keys.push(...unknown(upload, DemoUploadFields.shape, 'demo_upload.'));
140
+ if (isRecord(upload)) {
141
+ keys.push(...unknown(upload['header'], DemoUploadHeader.shape, 'demo_upload.header.'));
142
+ }
143
+ return keys;
144
+ }
@@ -0,0 +1,12 @@
1
+ export declare const SELF_UPDATE_COMMAND: readonly ["ankor-self-update"];
2
+ export declare const SELF_UPDATE_ENV: {
3
+ /** The Docker create payload for the replacement container as JSON, including its name. */
4
+ readonly spec: "ANKOR_SELF_UPDATE_SPEC";
5
+ /** The id of the container being replaced. */
6
+ readonly previousId: "ANKOR_SELF_UPDATE_PREVIOUS";
7
+ /**
8
+ * Where the helper records a swap that failed, for the agent that comes up after it. A swap that
9
+ * succeeds removes the record.
10
+ */
11
+ readonly failure: "ANKOR_SELF_UPDATE_FAILURE";
12
+ };
@@ -0,0 +1,12 @@
1
+ export const SELF_UPDATE_COMMAND = ['ankor-self-update'];
2
+ export const SELF_UPDATE_ENV = {
3
+ /** The Docker create payload for the replacement container as JSON, including its name. */
4
+ spec: 'ANKOR_SELF_UPDATE_SPEC',
5
+ /** The id of the container being replaced. */
6
+ previousId: 'ANKOR_SELF_UPDATE_PREVIOUS',
7
+ /**
8
+ * Where the helper records a swap that failed, for the agent that comes up after it. A swap that
9
+ * succeeds removes the record.
10
+ */
11
+ failure: 'ANKOR_SELF_UPDATE_FAILURE',
12
+ };