@protoboardai/core 0.0.0-stage → 0.2.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 +202 -0
- package/NOTICE +13 -0
- package/package.json +60 -4
- package/src/access.ts +311 -0
- package/src/account-login.ts +220 -0
- package/src/account.ts +563 -0
- package/src/agent-launcher.ts +257 -0
- package/src/agents.ts +942 -0
- package/src/board-firmware.ts +700 -0
- package/src/board-netlist.ts +721 -0
- package/src/bom-files.ts +31 -0
- package/src/bom-model.ts +572 -0
- package/src/browser.ts +149 -0
- package/src/build-info.ts +171 -0
- package/src/build.ts +149 -0
- package/src/bundle.ts +78 -0
- package/src/capabilities.ts +874 -0
- package/src/cdp.ts +199 -0
- package/src/evals/case.ts +214 -0
- package/src/evals/graders.ts +479 -0
- package/src/evals/hosts.ts +379 -0
- package/src/evals/index.ts +6 -0
- package/src/evals/isolation.ts +259 -0
- package/src/evals/runner.ts +457 -0
- package/src/evals/steps.ts +230 -0
- package/src/extensions-add.ts +83 -0
- package/src/extensions.ts +547 -0
- package/src/firmware-provider.ts +363 -0
- package/src/fx-rates.ts +91 -0
- package/src/index.ts +421 -0
- package/src/init.ts +479 -0
- package/src/inspect.ts +95 -0
- package/src/libraries.ts +345 -0
- package/src/library-client.ts +569 -0
- package/src/library-sort.ts +53 -0
- package/src/load.ts +547 -0
- package/src/operations.ts +233 -0
- package/src/outputs.ts +702 -0
- package/src/part-offers.ts +166 -0
- package/src/part-trust.ts +173 -0
- package/src/parts.ts +983 -0
- package/src/path-setup.ts +170 -0
- package/src/paths.ts +51 -0
- package/src/pbar.ts +164 -0
- package/src/placement.ts +48 -0
- package/src/private-dir.ts +29 -0
- package/src/product.ts +266 -0
- package/src/project-parts.ts +253 -0
- package/src/project.ts +585 -0
- package/src/python.ts +316 -0
- package/src/scope.ts +82 -0
- package/src/skills.ts +88 -0
- package/src/source.ts +272 -0
- package/src/stack-unpack.ts +354 -0
- package/src/stack.ts +718 -0
- package/src/tools.ts +652 -0
- package/src/types.ts +266 -0
- package/src/upgrade.ts +81 -0
- package/src/user-folders.ts +13 -0
- package/src/vendored-layout.ts +178 -0
- package/src/view-ids.ts +31 -0
- package/src/web-urls.ts +74 -0
- package/templates/_agents/common.md +280 -0
- package/templates/drone/files/AGENTS.md.tmpl +96 -0
- package/templates/drone/files/docs/brief.md.tmpl +16 -0
- package/templates/drone/files/parts/evidence/harnesses/sources.json +221 -0
- package/templates/drone/files/parts/local/README.md +9 -0
- package/templates/drone/files/protoboard.config.ts.tmpl +32 -0
- package/templates/drone/files/src/harnesses/dolphinrc-sh8-fc-esc-cable/cad.config.ts +8 -0
- package/templates/drone/files/src/harnesses/dolphinrc-xt60-battery-lead/cad.config.ts +8 -0
- package/templates/drone/files/src/harnesses/harnesses.uhd.ts +146 -0
- package/templates/drone/files/src/harnesses/radiomaster-rp1-crsf-wire/cad.config.ts +8 -0
- package/templates/drone/files/src/harnesses/routes.ts +23 -0
- package/templates/drone/files/src/modules/stack.uhd.ts +58 -0
- package/templates/drone/files/src/system.uhd.ts.tmpl +63 -0
- package/templates/drone/template.json +21 -0
- package/templates/iot/files/AGENTS.md.tmpl +98 -0
- package/templates/iot/files/docs/brief.md.tmpl +17 -0
- package/templates/iot/files/parts/evidence/lipol-lp503450/sources.json +128 -0
- package/templates/iot/files/parts/evidence/lipol-lp503450/sourcing.json +60 -0
- package/templates/iot/files/parts/evidence/lipol-lp503450/verification.json +27 -0
- package/templates/iot/files/parts/local/README.md +9 -0
- package/templates/iot/files/parts/local/_cadkit/common.py +116 -0
- package/templates/iot/files/parts/local/_cadkit/params.json +175 -0
- package/templates/iot/files/parts/local/_cadkit/partkit.py +97 -0
- package/templates/iot/files/parts/local/_cadkit/vendor_step.py +306 -0
- package/templates/iot/files/parts/local/lipol-lp503450/interfaces/lead_neg.glb +0 -0
- package/templates/iot/files/parts/local/lipol-lp503450/interfaces/lead_pos.glb +0 -0
- package/templates/iot/files/parts/local/lipol-lp503450/interfaces/mount_face.glb +0 -0
- package/templates/iot/files/parts/local/lipol-lp503450/lipol-lp503450.glb +0 -0
- package/templates/iot/files/parts/local/lipol-lp503450/lipol-lp503450.manifest.json +58 -0
- package/templates/iot/files/parts/local/lipol-lp503450/lipol-lp503450.py +98 -0
- package/templates/iot/files/parts/local/lipol-lp503450/lipol-lp503450.step +2416 -0
- package/templates/iot/files/parts/local/lipol-lp503450.uhd.ts +478 -0
- package/templates/iot/files/protoboard.config.ts.tmpl +36 -0
- package/templates/iot/files/src/boards/main/circuit.config.ts +65 -0
- package/templates/iot/files/src/boards/main/firmware.config.ts +13 -0
- package/templates/iot/files/src/boards/main/main.uhd.ts +166 -0
- package/templates/iot/files/src/boards/main/pads.uhd.ts +66 -0
- package/templates/iot/files/src/boards/main/tscircuit/board.tsx +18 -0
- package/templates/iot/files/src/boards/main/tscircuit/footprints.json +151 -0
- package/templates/iot/files/src/boards/main/tscircuit/layout.json +192 -0
- package/templates/iot/files/src/enclosures/README.md +14 -0
- package/templates/iot/files/src/harnesses/battery-leads/cad.config.ts +8 -0
- package/templates/iot/files/src/harnesses/harnesses.uhd.ts +59 -0
- package/templates/iot/files/src/harnesses/routes.ts +50 -0
- package/templates/iot/files/src/system.uhd.ts.tmpl +50 -0
- package/templates/iot/template.json +35 -0
- package/templates/wearable/files/AGENTS.md.tmpl +97 -0
- package/templates/wearable/files/docs/brief.md.tmpl +16 -0
- package/templates/wearable/files/parts/evidence/lipol-lp402030/sources.json +78 -0
- package/templates/wearable/files/parts/evidence/lipol-lp402030/sourcing.json +43 -0
- package/templates/wearable/files/parts/evidence/lipol-lp402030/verification.json +29 -0
- package/templates/wearable/files/parts/local/README.md +9 -0
- package/templates/wearable/files/parts/local/cadkit/partkit.py +180 -0
- package/templates/wearable/files/parts/local/lipol-lp402030/interfaces/lead_neg.glb +0 -0
- package/templates/wearable/files/parts/local/lipol-lp402030/interfaces/lead_pos.glb +0 -0
- package/templates/wearable/files/parts/local/lipol-lp402030/interfaces/mount_face.glb +0 -0
- package/templates/wearable/files/parts/local/lipol-lp402030/lipol-lp402030.glb +0 -0
- package/templates/wearable/files/parts/local/lipol-lp402030/lipol-lp402030.manifest.json +66 -0
- package/templates/wearable/files/parts/local/lipol-lp402030/lipol-lp402030.py +97 -0
- package/templates/wearable/files/parts/local/lipol-lp402030/lipol-lp402030.step +2891 -0
- package/templates/wearable/files/parts/local/lipol-lp402030.uhd.ts +456 -0
- package/templates/wearable/files/protoboard.config.ts.tmpl +35 -0
- package/templates/wearable/files/src/boards/main/circuit.config.ts +59 -0
- package/templates/wearable/files/src/boards/main/firmware.config.ts.tmpl +13 -0
- package/templates/wearable/files/src/boards/main/lands.uhd.ts +121 -0
- package/templates/wearable/files/src/boards/main/main.uhd.ts +154 -0
- package/templates/wearable/files/src/boards/main/tscircuit/board.tsx +21 -0
- package/templates/wearable/files/src/boards/main/tscircuit/footprints.json +194 -0
- package/templates/wearable/files/src/enclosures/README.md +13 -0
- package/templates/wearable/files/src/harnesses/battery-leads/cad.config.ts +8 -0
- package/templates/wearable/files/src/harnesses/harnesses.uhd.ts +50 -0
- package/templates/wearable/files/src/harnesses/routes.ts +50 -0
- package/templates/wearable/files/src/system.uhd.ts.tmpl +50 -0
- package/templates/wearable/template.json +36 -0
- package/README.md +0 -3
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 [yyyy] [name of copyright owner]
|
|
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,13 @@
|
|
|
1
|
+
Protoboard Stack: @protoboardai/core
|
|
2
|
+
Copyright 2026 Delta Robotics, Inc.
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Delta Robotics, Inc.
|
|
5
|
+
(https://deltaroboticsinc.com).
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
8
|
+
See the LICENSE file in this package for full terms.
|
|
9
|
+
|
|
10
|
+
"Protoboard", the Protoboard logo and the "0" mark are trademarks of
|
|
11
|
+
Delta Robotics, Inc. The License grants no rights to them (section 6);
|
|
12
|
+
see TRADEMARKS.md in the Protoboard Stack repository
|
|
13
|
+
(https://github.com/Delta-Robotics-Inc/protoboard-stack).
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protoboardai/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Protoboard framework core: project loading, definition registry and origins, resolution, aggregated checks, build",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Delta Robotics, Inc.",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Delta-Robotics-Inc/protoboard-stack.git",
|
|
10
|
+
"directory": "packages/core"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./src/index.ts",
|
|
15
|
+
"./library-client": "./src/library-client.ts",
|
|
16
|
+
"./views": "./src/view-ids.ts",
|
|
17
|
+
"./cdp": "./src/cdp.ts",
|
|
18
|
+
"./browser": "./src/browser.ts",
|
|
19
|
+
"./account": "./src/account.ts",
|
|
20
|
+
"./access": "./src/access.ts",
|
|
21
|
+
"./stack": "./src/stack.ts",
|
|
22
|
+
"./build-info": "./src/build-info.ts",
|
|
23
|
+
"./stack-unpack": "./src/stack-unpack.ts",
|
|
24
|
+
"./pbar": "./src/pbar.ts",
|
|
25
|
+
"./path-setup": "./src/path-setup.ts",
|
|
26
|
+
"./part-trust": "./src/part-trust.ts",
|
|
27
|
+
"./library-sort": "./src/library-sort.ts",
|
|
28
|
+
"./bom": "./src/bom-model.ts",
|
|
29
|
+
"./fx": "./src/fx-rates.ts",
|
|
30
|
+
"./offers": "./src/part-offers.ts",
|
|
31
|
+
"./agents": "./src/agents.ts",
|
|
32
|
+
"./agent-launcher": "./src/agent-launcher.ts",
|
|
33
|
+
"./user-folders": "./src/user-folders.ts",
|
|
34
|
+
"./private-dir": "./src/private-dir.ts"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"src",
|
|
38
|
+
"templates",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"NOTICE"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22"
|
|
45
|
+
},
|
|
46
|
+
"protoboard": {
|
|
47
|
+
"toolchain": {
|
|
48
|
+
"uhd": "0.3.0",
|
|
49
|
+
"typescript": "7.0.2"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@deltarobotics/uhd": "^0.3.0",
|
|
57
|
+
"@protoboardai/cloud": "^0.2.0",
|
|
58
|
+
"jsonc-parser": "^3.3.1",
|
|
59
|
+
"smol-toml": "^1.9.0",
|
|
60
|
+
"tsx": "^4.23.8"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/access.ts
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Protoboard cloud needs a sign-in; local work never does (PB-928 as
|
|
3
|
+
* changed on 2026-10-21: the stack is open source, and only the hosted cloud
|
|
4
|
+
* is a paid service). Creating, modelling, checking, building, the viewer,
|
|
5
|
+
* layout, circuits and releases run with no account. Everything that uses
|
|
6
|
+
* the library does need one, browsing included (the library is not
|
|
7
|
+
* accessible over the CLI when signed out either):
|
|
8
|
+
* searching it and its categories, the project's libraries, fetching library
|
|
9
|
+
* parts, update checks, prices and offers, publishing. The CLI asks `checkAccess` before
|
|
10
|
+
* such a command (packages/cli/src/gate.ts is the table of which ones), and
|
|
11
|
+
* the VS Code extension reads the same answer from `protoboard whoami`.
|
|
12
|
+
*
|
|
13
|
+
* What it is, plainly: a courtesy on the user's machine, so that a cloud
|
|
14
|
+
* command signed out stops at once with one line saying how to sign in,
|
|
15
|
+
* before it changes anything. It is not the protection. The parts service
|
|
16
|
+
* refuses every read of the library without a valid sign-in on its own
|
|
17
|
+
* (protoboard-cloud docs/access.md); a fork that removes this file gets the
|
|
18
|
+
* service's 401 instead of this line.
|
|
19
|
+
*
|
|
20
|
+
* The cases (docs/specs/distribution.md, "Sign-in for the cloud"):
|
|
21
|
+
*
|
|
22
|
+
* - A fresh answer from the service is kept for `ACCESS_RECHECK_HOURS` and
|
|
23
|
+
* used without contacting anything: cloud commands stay fast, and agents run many.
|
|
24
|
+
* - When the service cannot be reached, the last good answer is accepted for
|
|
25
|
+
* `OFFLINE_GRACE_DAYS`; the command itself then says what it could not reach.
|
|
26
|
+
* - A parts service that signs no one in (local development, `PB_CLOUD_AUTH=none`,
|
|
27
|
+
* or a library someone else hosts without accounts) is open.
|
|
28
|
+
* - `PROTOBOARD_CLOUD_TOKEN` (the service token, CI) counts as signed in. It is
|
|
29
|
+
* not sent anywhere by this check; the service judges it when it is used.
|
|
30
|
+
* - An account the service's invite list refuses is not allowed, and is told so.
|
|
31
|
+
*
|
|
32
|
+
* What the check sends, and nothing else: `GET <service>/.well-known/uhd-library`
|
|
33
|
+
* without credentials, `GET <service>/v1/me` with the account's ID token, and,
|
|
34
|
+
* when that token is older than an hour, the refresh to Google's token endpoint
|
|
35
|
+
* that every signed-in command already makes. Nothing about the project: not
|
|
36
|
+
* its name, its path, its files or its parts.
|
|
37
|
+
*
|
|
38
|
+
* No VS Code API here: the CLI calls it, and the extension reads its result
|
|
39
|
+
* from `protoboard whoami --format json` (`access`).
|
|
40
|
+
*/
|
|
41
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
42
|
+
import { ensurePrivateDir } from "./private-dir.js";
|
|
43
|
+
import { join } from "node:path";
|
|
44
|
+
import { AccountError, CredentialStore, accountToken, configDir, fetchProblem, serviceKey } from "./account.js";
|
|
45
|
+
|
|
46
|
+
/** How long a good answer is used without asking the service again. */
|
|
47
|
+
export const ACCESS_RECHECK_HOURS = 12;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* How long the last good answer is accepted while the service cannot be
|
|
51
|
+
* reached. Seven days: a week of travel or bench work without a connection
|
|
52
|
+
* keeps working, and an account taken off the invite list stops within a week
|
|
53
|
+
* even on a machine that never goes online (online, it stops at the next
|
|
54
|
+
* check, at most `ACCESS_RECHECK_HOURS` later).
|
|
55
|
+
*/
|
|
56
|
+
export const OFFLINE_GRACE_DAYS = 7;
|
|
57
|
+
|
|
58
|
+
/** Why access was given. */
|
|
59
|
+
export type AccessVia =
|
|
60
|
+
/** The service accepted the signed-in account just now. */
|
|
61
|
+
| "account"
|
|
62
|
+
/** The service accepted it within the last `ACCESS_RECHECK_HOURS`; nothing was contacted. */
|
|
63
|
+
| "recent"
|
|
64
|
+
/** The service cannot be reached; it accepted the account within the last `OFFLINE_GRACE_DAYS`. */
|
|
65
|
+
| "offline"
|
|
66
|
+
/** The service signs no one in (local development). */
|
|
67
|
+
| "open-service"
|
|
68
|
+
/** `PROTOBOARD_CLOUD_TOKEN` is set (CI). */
|
|
69
|
+
| "service-token";
|
|
70
|
+
|
|
71
|
+
/** Why access was refused. */
|
|
72
|
+
export type AccessRefusal =
|
|
73
|
+
/** Nobody is signed in to the service. */
|
|
74
|
+
| "signed-out"
|
|
75
|
+
/** The sign-in no longer works (revoked, disabled, expired). */
|
|
76
|
+
| "sign-in-invalid"
|
|
77
|
+
/** Signed in, but the service's invite list does not have the account. */
|
|
78
|
+
| "not-invited"
|
|
79
|
+
/** The service cannot be reached and there is no recent good answer. */
|
|
80
|
+
| "unreachable";
|
|
81
|
+
|
|
82
|
+
export interface Access {
|
|
83
|
+
/** Whether this machine may use the service's account features (the cloud) now. */
|
|
84
|
+
allowed: boolean;
|
|
85
|
+
service: string;
|
|
86
|
+
via?: AccessVia;
|
|
87
|
+
reason?: AccessRefusal;
|
|
88
|
+
/** One line for a person: what is wrong and what to run. Set when not allowed. */
|
|
89
|
+
message?: string;
|
|
90
|
+
email?: string;
|
|
91
|
+
/** When the service last accepted the account (ISO). */
|
|
92
|
+
verifiedAt?: string;
|
|
93
|
+
/** With `via: "offline"`: until when the last answer is accepted (ISO). */
|
|
94
|
+
offlineUntil?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The last answer per service. Not a secret: no token, only who and when. */
|
|
98
|
+
interface AccessRecord {
|
|
99
|
+
/** The account it was for; a record of another account is ignored. `open` for a service without sign-in. */
|
|
100
|
+
uid: string;
|
|
101
|
+
email?: string;
|
|
102
|
+
verifiedAt: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const HOUR = 3_600_000;
|
|
106
|
+
const DAY = 24 * HOUR;
|
|
107
|
+
|
|
108
|
+
/** `<config dir>/access.json`: beside the credentials, never in a project. */
|
|
109
|
+
export function accessFile(env: NodeJS.ProcessEnv = process.env, platform: NodeJS.Platform = process.platform): string {
|
|
110
|
+
return join(configDir(env, platform), "access.json");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function readRecords(file: string): Record<string, AccessRecord> {
|
|
114
|
+
if (!existsSync(file)) return {};
|
|
115
|
+
try {
|
|
116
|
+
const all = JSON.parse(readFileSync(file, "utf8")) as Record<string, AccessRecord>;
|
|
117
|
+
return all && typeof all === "object" ? all : {};
|
|
118
|
+
} catch {
|
|
119
|
+
return {};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function writeRecord(file: string, service: string, record: AccessRecord | undefined): void {
|
|
124
|
+
try {
|
|
125
|
+
const all = readRecords(file);
|
|
126
|
+
if (record) all[service] = record;
|
|
127
|
+
else if (service in all) delete all[service];
|
|
128
|
+
else return;
|
|
129
|
+
ensurePrivateDir(join(file, ".."));
|
|
130
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
131
|
+
writeFileSync(tmp, JSON.stringify(all, null, 2) + "\n", { mode: 0o600 });
|
|
132
|
+
chmodSync(tmp, 0o600);
|
|
133
|
+
renameSync(tmp, file);
|
|
134
|
+
} catch {
|
|
135
|
+
// the record only saves a request next time: a folder that cannot be written is not a reason to refuse
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The services this machine is signed in to, the most recently confirmed
|
|
141
|
+
* first: those the credential store can list, and those the service's last
|
|
142
|
+
* answers name (the OS credential stores are asked by name only). What an
|
|
143
|
+
* account command falls back on when a project cannot say which service is
|
|
144
|
+
* its own (`unloadedProjectService`).
|
|
145
|
+
*/
|
|
146
|
+
export function savedServices(options: { env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform; store?: CredentialStore; also?: string[] } = {}): string[] {
|
|
147
|
+
const env = options.env ?? process.env;
|
|
148
|
+
let store: CredentialStore;
|
|
149
|
+
try {
|
|
150
|
+
store = options.store ?? new CredentialStore({ env, ...(options.platform ? { platform: options.platform } : {}) });
|
|
151
|
+
} catch {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
const records = readRecords(accessFile(env, options.platform));
|
|
155
|
+
const named = Object.keys(records).sort((a, b) => Date.parse(records[b]!.verifiedAt) - Date.parse(records[a]!.verifiedAt));
|
|
156
|
+
const candidates = [...new Set([...named, ...store.services(), ...(options.also ?? [])].map(serviceKey))];
|
|
157
|
+
return candidates.filter((s) => {
|
|
158
|
+
try {
|
|
159
|
+
return !!store.get(s);
|
|
160
|
+
} catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Forget the last answer for a service (`protoboard logout`, a new `login`): the next check asks the service. */
|
|
167
|
+
export function forgetAccess(service: string, options: { env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform } = {}): void {
|
|
168
|
+
writeRecord(accessFile(options.env, options.platform), serviceKey(service), undefined);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface AccessOptions {
|
|
172
|
+
env?: NodeJS.ProcessEnv;
|
|
173
|
+
platform?: NodeJS.Platform;
|
|
174
|
+
store?: CredentialStore;
|
|
175
|
+
fetch?: typeof fetch;
|
|
176
|
+
/** Milliseconds since the epoch (tests). */
|
|
177
|
+
now?: number;
|
|
178
|
+
/** Ask the service even when a recent answer is kept (`whoami --check`, the extension after a sign-in). */
|
|
179
|
+
fresh?: boolean;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const SIGN_IN = "sign in with `protoboard login`";
|
|
183
|
+
const LIBRARY = "The Protoboard library";
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The one line a refused cloud command prints. `what` names what needed the
|
|
187
|
+
* cloud ("Adding library parts"); without it the line speaks of the library.
|
|
188
|
+
*/
|
|
189
|
+
export function accessMessage(a: Pick<Access, "reason" | "service" | "email">, detail?: string, what = LIBRARY): string {
|
|
190
|
+
switch (a.reason) {
|
|
191
|
+
case "not-invited":
|
|
192
|
+
return `${what} needs an invited account: ${a.email ?? "this account"} is signed in to ${a.service} but is not on its invite list${detail ? ` (${detail})` : ""}. Ask for an invitation, or ${SIGN_IN} with an invited account. Local work (check, build, the viewer) needs no account.`;
|
|
193
|
+
case "sign-in-invalid":
|
|
194
|
+
return `${what} needs a sign-in: the one kept for ${a.service}${a.email ? ` (${a.email})` : ""} no longer works${detail ? ` (${detail})` : ""}. To sign in again, ${SIGN_IN}.`;
|
|
195
|
+
case "unreachable":
|
|
196
|
+
return `${what} needs ${a.service}, which cannot be reached to check the sign-in${detail ? ` (${detail})` : ""}.`;
|
|
197
|
+
default:
|
|
198
|
+
return `${what} needs a Protoboard account: ${SIGN_IN} (not signed in to ${a.service}).`;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Whether this machine may use the account features (the cloud) of the
|
|
204
|
+
* library at `service`: see the top of this file for the cases. Never throws; a credential store that
|
|
205
|
+
* cannot be read is "signed out" with the reason in the message.
|
|
206
|
+
*/
|
|
207
|
+
export async function checkAccess(service: string, options: AccessOptions = {}): Promise<Access> {
|
|
208
|
+
const env = options.env ?? process.env;
|
|
209
|
+
const key = serviceKey(service);
|
|
210
|
+
const now = options.now ?? Date.now();
|
|
211
|
+
const f = options.fetch ?? fetch;
|
|
212
|
+
const file = accessFile(env, options.platform);
|
|
213
|
+
const refuse = (reason: AccessRefusal, extra: Partial<Access> = {}, detail?: string): Access => ({ allowed: false, service: key, reason, ...extra, message: accessMessage({ reason, service: key, ...(extra.email ? { email: extra.email } : {}) }, detail) });
|
|
214
|
+
|
|
215
|
+
// CI: the service token stands for an account. Nothing is asked; the service judges the token when it is used.
|
|
216
|
+
if (env.PROTOBOARD_CLOUD_TOKEN) return { allowed: true, service: key, via: "service-token" };
|
|
217
|
+
|
|
218
|
+
let store: CredentialStore;
|
|
219
|
+
try {
|
|
220
|
+
store = options.store ?? new CredentialStore({ env, ...(options.platform ? { platform: options.platform } : {}) });
|
|
221
|
+
} catch (e) {
|
|
222
|
+
return refuse("signed-out", {}, (e as Error).message);
|
|
223
|
+
}
|
|
224
|
+
const session = store.get(key);
|
|
225
|
+
const record = readRecords(file)[key];
|
|
226
|
+
const age = record ? now - Date.parse(record.verifiedAt) : Infinity;
|
|
227
|
+
const who = session ? { ...(session.email ? { email: session.email } : {}) } : {};
|
|
228
|
+
// the last answer counts only for the account it was given to (or, signed out, for an open service)
|
|
229
|
+
const mine = !!record && age >= 0 && record.uid === (session ? session.uid : "open");
|
|
230
|
+
|
|
231
|
+
if (mine && !options.fresh && age < ACCESS_RECHECK_HOURS * HOUR) {
|
|
232
|
+
return { allowed: true, service: key, via: session ? "recent" : "open-service", ...who, verifiedAt: record.verifiedAt };
|
|
233
|
+
}
|
|
234
|
+
const offline = (what: string): Access => {
|
|
235
|
+
if (mine && age < OFFLINE_GRACE_DAYS * DAY) {
|
|
236
|
+
return { allowed: true, service: key, via: session ? "offline" : "open-service", ...who, verifiedAt: record.verifiedAt, offlineUntil: new Date(Date.parse(record.verifiedAt) + OFFLINE_GRACE_DAYS * DAY).toISOString() };
|
|
237
|
+
}
|
|
238
|
+
return refuse("unreachable", who, what);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// does the service sign anyone in? (no credentials in this request)
|
|
242
|
+
let needsAccount: boolean;
|
|
243
|
+
try {
|
|
244
|
+
const res = await f(`${key}/.well-known/uhd-library`, { signal: AbortSignal.timeout(10_000) });
|
|
245
|
+
if (!res.ok) return offline(`GET ${key}/.well-known/uhd-library answered ${res.status}`);
|
|
246
|
+
needsAccount = !!((await res.json()) as { account?: unknown }).account;
|
|
247
|
+
} catch (e) {
|
|
248
|
+
return offline(`GET ${key}/.well-known/uhd-library: ${fetchProblem(e)}`);
|
|
249
|
+
}
|
|
250
|
+
const verifiedAt = new Date(now).toISOString();
|
|
251
|
+
if (!needsAccount) {
|
|
252
|
+
writeRecord(file, key, { uid: "open", verifiedAt });
|
|
253
|
+
return { allowed: true, service: key, via: "open-service", verifiedAt };
|
|
254
|
+
}
|
|
255
|
+
if (!session) {
|
|
256
|
+
writeRecord(file, key, undefined);
|
|
257
|
+
return refuse("signed-out");
|
|
258
|
+
}
|
|
259
|
+
let me: { signedIn?: boolean; allowed?: boolean; problem?: string };
|
|
260
|
+
try {
|
|
261
|
+
const token = await accountToken(key, { store, fetch: f, now });
|
|
262
|
+
const res = await f(`${key}/v1/me`, { headers: { authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(10_000) });
|
|
263
|
+
if (res.status >= 500) return offline(`GET ${key}/v1/me answered ${res.status}`);
|
|
264
|
+
me = (await res.json().catch(() => ({}))) as typeof me;
|
|
265
|
+
} catch (e) {
|
|
266
|
+
// Firebase said the sign-in is over: that is an answer. Anything else is "could not ask".
|
|
267
|
+
if (e instanceof AccountError && e.code === "SESSION_EXPIRED") {
|
|
268
|
+
writeRecord(file, key, undefined);
|
|
269
|
+
return refuse("sign-in-invalid", who, e.message.replace(/: run `protoboard login` again$/, ""));
|
|
270
|
+
}
|
|
271
|
+
return offline(e instanceof AccountError ? e.message : `GET ${key}/v1/me: ${fetchProblem(e)}`);
|
|
272
|
+
}
|
|
273
|
+
if (!me.signedIn) {
|
|
274
|
+
writeRecord(file, key, undefined);
|
|
275
|
+
return refuse("sign-in-invalid", who, "the service does not accept it");
|
|
276
|
+
}
|
|
277
|
+
if (me.allowed === false) {
|
|
278
|
+
writeRecord(file, key, undefined);
|
|
279
|
+
return refuse("not-invited", who, me.problem);
|
|
280
|
+
}
|
|
281
|
+
writeRecord(file, key, { uid: session.uid, ...(session.email ? { email: session.email } : {}), verifiedAt });
|
|
282
|
+
return { allowed: true, service: key, via: "account", ...who, verifiedAt };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Thrown by `requireAccess`: the CLI prints `message` as its one line and exits `ACCESS_EXIT_CODE`. */
|
|
286
|
+
export class AccessError extends Error {
|
|
287
|
+
readonly code = "SIGN_IN_REQUIRED";
|
|
288
|
+
constructor(
|
|
289
|
+
readonly access: Access,
|
|
290
|
+
what?: string,
|
|
291
|
+
) {
|
|
292
|
+
const line = access.message ?? accessMessage(access);
|
|
293
|
+
super(what && line.startsWith(LIBRARY) ? what + line.slice(LIBRARY.length) : line);
|
|
294
|
+
this.name = "AccessError";
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** The CLI's exit code for a cloud command refused for want of a sign-in (1 is findings, 2 a failed command). */
|
|
299
|
+
export const ACCESS_EXIT_CODE = 4;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* `checkAccess`, throwing `AccessError` when the service definitely refuses
|
|
303
|
+
* (signed out, a sign-in that no longer works, not invited). A service that
|
|
304
|
+
* cannot be reached is not a refusal here: the command goes on and says
|
|
305
|
+
* itself what it could not reach.
|
|
306
|
+
*/
|
|
307
|
+
export async function requireAccess(service: string, options: AccessOptions & { what?: string } = {}): Promise<Access> {
|
|
308
|
+
const a = await checkAccess(service, options);
|
|
309
|
+
if (!a.allowed && a.reason !== "unreachable") throw new AccessError(a, options.what);
|
|
310
|
+
return a;
|
|
311
|
+
}
|