@openrois/sdk 0.0.1-stage → 0.1.0-alpha.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/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 Coarobo GK
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/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ OpenRoIS
2
+ Copyright 2026 Coarobo GK
3
+
4
+ OpenRoIS is developed by Coarobo GK (https://coarobo.com/)
5
+ and the OpenRoIS community (https://openrois.org/).
6
+
7
+ OpenRoIS is a trademark of Coarobo GK.
package/README.md ADDED
@@ -0,0 +1,269 @@
1
+ # @openrois/sdk
2
+
3
+ ![Node.js](https://img.shields.io/badge/Node.js-22.12+-5FA04E?logo=nodedotjs&logoColor=white)
4
+
5
+ JavaScript client SDK for [OpenRoIS](https://openrois.org/), an open-source middleware implementing the [OMG RoIS Framework 2.0](https://www.omg.org/spec/RoIS/2.0).
6
+
7
+ Connect to an OpenRoIS engine, discover the components of every connected physical robot, virtual avatar, or AI service, and drive them through the standard RoIS interfaces. Runs in browsers and in Node.js.
8
+
9
+ > **Alpha, pre-1.0, unstable API.**
10
+
11
+ ## Installation
12
+
13
+ ### npm
14
+
15
+ ```bash
16
+ npm install @openrois/sdk
17
+ ```
18
+
19
+ ### From Source
20
+
21
+ ```bash
22
+ git clone https://github.com/openrois/openrois.git
23
+ cd openrois/sdk/javascript
24
+ npm install
25
+ npm run build
26
+ ```
27
+
28
+ Then reference from your project:
29
+
30
+ ```json
31
+ {
32
+ "dependencies": {
33
+ "@openrois/sdk": "file:../path/to/openrois/sdk/javascript"
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```ts
41
+ import { RoISClient, componentRef, componentType } from "@openrois/sdk";
42
+
43
+ const client = await RoISClient.connect("ws://localhost:8765");
44
+
45
+ // Find a component by type, and select it by ref in later calls.
46
+ const [nav] = await client.search(componentType({ authority: "OMG", code: "Navigation" }));
47
+ const target = componentRef(nav);
48
+
49
+ // Read state.
50
+ const status = await client.query("component_status", target);
51
+
52
+ // React to events.
53
+ client.on("rois.event.notify_event", ({ event_type, results }) => {
54
+ console.log(event_type, results);
55
+ });
56
+ await client.subscribe("reached_target", target);
57
+
58
+ // Record how each command ends, before running any.
59
+ const statuses = new Map<string, string>();
60
+ const waiters = new Map<string, () => void>();
61
+ client.on("rois.command.completed", ({ command_id, status }) => {
62
+ statuses.set(command_id, status);
63
+ waiters.get(command_id)?.();
64
+ });
65
+
66
+ // Reserve, configure, command, wait, release.
67
+ await client.bind(nav);
68
+ await client.setParameter(nav, [
69
+ { name: "target_positions", data_type_ref: "string[]", value: '["kitchen"]' },
70
+ ]);
71
+ const [commandId] = await client.execute([{ component_ref: nav, command_type: "start" }]);
72
+ // Wait here, because release aborts a running command, which then ends with ABORT.
73
+ if (!statuses.has(commandId)) {
74
+ await new Promise<void>((resolve) => waiters.set(commandId, resolve));
75
+ }
76
+ console.log(statuses.get(commandId));
77
+ await client.release(nav);
78
+
79
+ await client.disconnect();
80
+ ```
81
+
82
+ Run it against the Docker Compose stack at the repository root, which serves simulated components through a gateway.
83
+
84
+ ## Waiting for a Command
85
+
86
+ RoIS has no operation that waits for a command, so neither does the client. `execute()` returns as soon as the engine accepts the commands. Each command ends later, with a `rois.command.completed` notification that names its id. `setParameter()` works the same way.
87
+
88
+ A command that ends at once can complete before the reply reaches your code, so a listener added after `execute()` can miss it. The recipe has three steps:
89
+
90
+ 1. Add the listener before the call, once for the whole session.
91
+ 2. Record each status by `command_id`.
92
+ 3. Read the status with the ids in the reply.
93
+
94
+ The quickstart above does this, and checks the record first, because a command that has already ended fires no listener. A real application also stops waiting on `close`, or after a timeout.
95
+
96
+ Wait before you release the component: `release()` aborts your running commands on it, and they end with `ABORT`. `disconnect()` aborts them too.
97
+
98
+ ## API
99
+
100
+ `RoISClient` has one method per operation of the RoIS method catalog. Each takes the operation's IDL parameters in IDL order, validates them and the result against the catalog schemas in `@openrois/interfaces`, and returns the result's out parameters.
101
+
102
+ | RoIS interface | Methods |
103
+ |----------------|---------|
104
+ | System | `RoISClient.connect(url, options?)`, `disconnect()`, `getProfile(condition?)`, `getErrorDetail(errorId, condition?)` |
105
+ | Command | `search(condition?)`, `bind(ref)`, `bindAny(condition?)`, `release(ref)`, `getParameter(ref)`, `setParameter(ref, parameters)`, `execute(commandUnitList)`, `getCommandResult(commandId, condition?)` |
106
+ | Query | `query(queryType, condition?)` |
107
+ | Event | `subscribe(eventType, condition?)`, `unsubscribe(subscribeId)`, `getEventDetail(eventId, condition?)` |
108
+
109
+ A streaming component is driven with these same methods. Carrying its media is planned.
110
+
111
+ - `getProfile()` returns `{ profile, component_profiles }`: the engine profile and the profile of every component it lists, keyed by fully qualified ref.
112
+ - `execute()` takes a `command_unit_list`: commands that run in order, and `{ branch_list, delay_time }` groups whose branches run at the same time, each branch in order. The commands carry no `command_id`: the engine assigns one to each, and `execute()` returns them in order, branch by branch.
113
+ - `query()` and `subscribe()` go to the one component that declares the query or event type and matches the condition.
114
+
115
+ One client is one session. Bindings and subscriptions end with it, and there is no automatic reconnect, because a silent reconnect would hide that loss. After `close`, connect again and bind and subscribe again.
116
+
117
+ ### Conditions
118
+
119
+ Every `condition` is a string in the OpenRoIS subset of CQL2-Text: `=` and `LIKE` comparisons, joined by `AND`, over `component_ref` and `component_type`. An empty string is no filter. The builders quote values for you:
120
+
121
+ | Builder | Writes |
122
+ |---------|--------|
123
+ | `componentRef("reachy_real/head")` | `component_ref = 'reachy_real/head'` |
124
+ | `componentType({ authority: "OMG", code: "Navigation" })` | `component_type = 'urn:x-rois:def:component:OMG::Navigation'` |
125
+ | `like(COMPONENT_REF, "reachy_real/%")` | `component_ref LIKE 'reachy_real/%'` |
126
+ | `allOf(a, b)` | `a AND b` |
127
+
128
+ ### Listening
129
+
130
+ `on(name, listener)` adds a listener and `off(name, listener)` removes it. Listeners of catalog notifications receive the validated params, typed from `RoISNotificationMap`.
131
+
132
+ | Name | Listener receives |
133
+ |------|-------------------|
134
+ | `rois.event.notify_event` | `NotifyEventParams`, for every event of every subscription. Filter by `subscribe_id` or `event_type` |
135
+ | `rois.command.completed` | `CompletedParams`, when a command ends |
136
+ | `rois.system.notify_error` | `NotifyErrorParams`, when the engine reports an error |
137
+ | `rois.system.profile_changed` | `ProfileChangedParams`, when components join or leave |
138
+ | `close` | `(code, reason)` when the connection closes, from either side |
139
+ | `error` | An `Error`, for a message that cannot be used or a listener that throws |
140
+
141
+ A listener that throws, and an `async` listener that rejects, never stop the client: the error goes to the `error` listeners, and the other listeners still run. With no `error` listener, a fault is written to `console.error`. It is never thrown.
142
+
143
+ ### Closing
144
+
145
+ `await using` calls `disconnect()` when the block ends:
146
+
147
+ ```ts
148
+ {
149
+ await using client = await RoISClient.connect("ws://localhost:8765");
150
+ await client.search();
151
+ }
152
+ ```
153
+
154
+ The syntax runs natively in Node.js 24. For Node.js 22, compile it with TypeScript.
155
+
156
+ ## Error Handling
157
+
158
+ ```ts
159
+ import { RoISClient, RoISError } from "@openrois/sdk";
160
+
161
+ try {
162
+ await client.bind("robot_1/navigation");
163
+ } catch (err) {
164
+ if (err instanceof RoISError && err.returnCode === "OUT_OF_RESOURCES") {
165
+ // Another application holds the reservation.
166
+ }
167
+ }
168
+ ```
169
+
170
+ | Error | Raised when | Carries |
171
+ |-------|-------------|---------|
172
+ | `RoISError` | A RoIS operation returns a code other than `OK` | `returnCode`, `method` |
173
+ | `TransportError` | The base of the three below. Raised itself for a call on a closed client | |
174
+ | `ConnectionError` | The WebSocket cannot be opened, or closes while a request waits | `url` |
175
+ | `RequestTimeoutError` | No response within the request timeout | `method`, `requestId` |
176
+ | `RpcError` | The engine returns a JSON-RPC error: a protocol fault, such as an unknown method | `code`, `data` |
177
+ | `ZodError` | Params fail validation before they are sent, or a result does not match the catalog | |
178
+
179
+ ## Node.js and Browsers
180
+
181
+ The package is one ES module build, with no separate CommonJS build. `import` works in Node.js 22.12 or later and in browsers, and `require` works from Node.js 22.12. `moduleResolution` can be `nodenext` or `bundler`. It uses the global `WebSocket`, which both have, so it installs no WebSocket package.
182
+
183
+ Browsers are the target, but this release has run in headless Chromium only. Firefox and Safari have not been run. `wss://` has not been exercised: every run used `ws://`. The gateway does not authenticate connections in the alpha releases, so use it on trusted networks only.
184
+
185
+ `RoISClient.connect()` takes the transport options, with times in milliseconds:
186
+
187
+ ```ts
188
+ const client = await RoISClient.connect("ws://localhost:8765", {
189
+ transport: { requestTimeout: 5_000, connectTimeout: 2_000 },
190
+ });
191
+ ```
192
+
193
+ | Option | Default | Meaning |
194
+ |--------|---------|---------|
195
+ | `requestTimeout` | 30000 | How long a request waits for its response |
196
+ | `connectTimeout` | 10000 | How long the WebSocket has to open |
197
+ | `webSocketFactory` | The global `WebSocket` | Creates the socket for a URL |
198
+
199
+ `webSocketFactory` is for a socket the global `WebSocket` cannot open, for example one with headers through the `ws` package:
200
+
201
+ ```ts
202
+ import WebSocket from "ws";
203
+ import type { WebSocketLike } from "@openrois/sdk/transport";
204
+
205
+ const client = await RoISClient.connect("wss://engine.example.com", {
206
+ transport: {
207
+ webSocketFactory: (url) =>
208
+ new WebSocket(url, { headers: { "x-site": "lab-1" } }) as unknown as WebSocketLike,
209
+ },
210
+ });
211
+ ```
212
+
213
+ ## The Transport
214
+
215
+ `client.transport` is the `WebSocketTransport` under the client, for JSON-RPC methods outside the catalog. Nothing sent through it is validated.
216
+
217
+ ```ts
218
+ const result = await client.transport.send("vendor.custom.method", { level: 3 });
219
+ ```
220
+
221
+ ## Subpath Exports
222
+
223
+ | Import path | Contents |
224
+ |---|---|
225
+ | `@openrois/sdk` | `RoISClient`, its types, the errors, and the condition builders |
226
+ | `@openrois/sdk/transport` | `WebSocketTransport`, `WebSocketLike`, `TransportOptions`, `TransportEvents`, `TransportState`, and the transport errors |
227
+
228
+ ## Tested Versions
229
+
230
+ The wire has no version handshake, so a mismatch shows only when a message carries a field the other side does not know. This release is tested against these versions together, which `testing/conformance/frozen.txt` pins:
231
+
232
+ | `@openrois/sdk` | `@openrois/interfaces` | `openrois-gateway` | `openrois-engine` | `openrois-interfaces` | `openrois-components-core` |
233
+ |---|---|---|---|---|---|
234
+ | 0.1.0-alpha.1 | 0.1.0-alpha.6 | 0.1.0a1 | 0.1.0a2 | 0.1.0a6 | 0.1.0a1 |
235
+
236
+ ## Development
237
+
238
+ ```bash
239
+ npm run build # bundle with tsup
240
+ npm test # vitest
241
+ npm run test:browser # the conformance list in headless Chromium, needs the stack below
242
+ npm run test:consumer # build, pack, and check the tarball from a clean project
243
+ npm run typecheck
244
+ npm run lint
245
+ ```
246
+
247
+ The SDK depends on `@openrois/interfaces` from npm. To test it against the interfaces in the tree, build them and install them over that copy:
248
+
249
+ ```bash
250
+ npm install ../../interfaces/typescript --no-save
251
+ ```
252
+
253
+ `tests/conformance.test.ts` runs the conformance list of `testing/conformance/README.md`, and `tests/gateway.test.ts` runs full client sessions. Both need a live gateway with the mock adapter behind it, such as the Docker Compose stack at the repository root. They run when `OPENROIS_GATEWAY_URL` names the gateway, and are skipped otherwise.
254
+
255
+ With that variable set, every run starts `testing/conformance/scripted_server.py` with `python3`, which needs the `websockets` package. Without it the whole run fails, not only these two files.
256
+
257
+ ```bash
258
+ docker compose up --build -d # from the repository root
259
+ pip install websockets
260
+ OPENROIS_GATEWAY_URL=ws://127.0.0.1:8765 npm test
261
+ npx playwright install --only-shell chromium # once, for the browser run
262
+ OPENROIS_GATEWAY_URL=ws://127.0.0.1:8765 npm run test:browser
263
+ ```
264
+
265
+ With `OPENROIS_SDK_PACKAGE` naming an unpacked tarball inside this folder, these tests import its `dist` in place of `src`, which is how the release workflow runs them.
266
+
267
+ ## License
268
+
269
+ Apache-2.0. See [LICENSE](./LICENSE).