@cuylabs/physical-agent-core 0.1.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 +201 -0
- package/README.md +86 -0
- package/dist/chunk-6VUPCNET.js +502 -0
- package/dist/chunk-6VUPCNET.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/index.d.ts +41 -0
- package/dist/tools/index.js +17 -0
- package/dist/tools/index.js.map +1 -0
- package/docs/README.md +38 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @cuylabs/physical-agent-core
|
|
2
|
+
|
|
3
|
+
Agent-core tools for physical AI sessions.
|
|
4
|
+
|
|
5
|
+
This package binds `@cuylabs/physical-core` sessions to `@cuylabs/agent-core`
|
|
6
|
+
tools. It contains generic status, observe, artifact, stop, and policy-code
|
|
7
|
+
tool factories.
|
|
8
|
+
|
|
9
|
+
The package does not define physical session contracts and does not connect to
|
|
10
|
+
any robotics backend. It turns an existing `PhysicalSession` into a small,
|
|
11
|
+
model-facing `agent-core` tool surface.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @cuylabs/agent-core @cuylabs/physical-core @cuylabs/physical-agent-core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Use
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { createAgent } from "@cuylabs/agent-core";
|
|
23
|
+
import { createPhysicalSessionTools } from "@cuylabs/physical-agent-core";
|
|
24
|
+
|
|
25
|
+
const agent = createAgent({
|
|
26
|
+
model,
|
|
27
|
+
tools: createPhysicalSessionTools(session),
|
|
28
|
+
systemPrompt:
|
|
29
|
+
"You are controlling a physical session. Observe before acting.",
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For sessions that support direct code execution, the generated toolset includes
|
|
34
|
+
`physical_run_policy_code`. For sessions that only expose observation/status or
|
|
35
|
+
external trial control, that tool is omitted.
|
|
36
|
+
|
|
37
|
+
Backend adapters can add extra tools next to the generic set. For example, a
|
|
38
|
+
CaP-X adapter may expose turn history while still using the same generic
|
|
39
|
+
status, observe, artifact, stop, and policy-code contracts. Backend-specific
|
|
40
|
+
helper libraries should normally appear as observation/context for generated
|
|
41
|
+
policy code, not as extra model-facing robot tools.
|
|
42
|
+
|
|
43
|
+
## Generated Tools
|
|
44
|
+
|
|
45
|
+
`createPhysicalSessionTools(session)` can produce:
|
|
46
|
+
|
|
47
|
+
- `physical_status`
|
|
48
|
+
- `physical_observe`
|
|
49
|
+
- `physical_artifacts`
|
|
50
|
+
- `physical_stop`
|
|
51
|
+
- `physical_run_policy_code` when `session.executeCode` exists
|
|
52
|
+
|
|
53
|
+
Use the `prefix` option when composing backend-specific surfaces:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const tools = createPhysicalSessionTools(session, { prefix: "capx" });
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Boundary
|
|
60
|
+
|
|
61
|
+
Use this package only when the host runtime is `@cuylabs/agent-core`. The
|
|
62
|
+
physical session contracts remain in `@cuylabs/physical-core`.
|
|
63
|
+
|
|
64
|
+
This package should not contain backend-specific launchers, service clients,
|
|
65
|
+
simulator mappings, or robot APIs. Those belong in backend packages such as
|
|
66
|
+
`@cuylabs/physical-capx`.
|
|
67
|
+
|
|
68
|
+
## Design Notes
|
|
69
|
+
|
|
70
|
+
- A physical capability is not just a normal tool. It may depend on calibrated
|
|
71
|
+
sensors, timing, world state, hardware readiness, and explicit safety policy.
|
|
72
|
+
- Physical tool outputs include structured metadata so UIs and middleware can
|
|
73
|
+
inspect observations, traces, artifacts, and outcomes.
|
|
74
|
+
- Direct physical execution is marked dangerous by default and uses manual
|
|
75
|
+
replay semantics because repeated execution can move hardware or mutate a
|
|
76
|
+
simulator.
|
|
77
|
+
|
|
78
|
+
## Docs
|
|
79
|
+
|
|
80
|
+
- [docs/README.md](./docs/README.md) for the documentation map
|
|
81
|
+
- [../physical-core/docs/safety.md](../physical-core/docs/safety.md) for the
|
|
82
|
+
core safety model
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
Apache-2.0
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
// src/tools/index.ts
|
|
2
|
+
import { Tool } from "@cuylabs/agent-core/tool";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import {
|
|
5
|
+
describePhysicalState,
|
|
6
|
+
normalizePhysicalSafetyPolicy
|
|
7
|
+
} from "@cuylabs/physical-core";
|
|
8
|
+
function toolName(name, options) {
|
|
9
|
+
return `${options?.prefix ?? "physical"}_${name}`;
|
|
10
|
+
}
|
|
11
|
+
var MAX_OBSERVATION_ITEM_CHARS = 12e3;
|
|
12
|
+
var MAX_OBSERVATION_OUTPUT_CHARS = 6e4;
|
|
13
|
+
var MAX_EXECUTION_OUTPUT_CHARS = 8e3;
|
|
14
|
+
function truncateText(value, maxChars) {
|
|
15
|
+
if (value.length <= maxChars) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
return `${value.slice(0, maxChars)}
|
|
19
|
+
... (${value.length - maxChars} characters omitted from this observation item)`;
|
|
20
|
+
}
|
|
21
|
+
function stringifyObservationData(value) {
|
|
22
|
+
if (typeof value === "string") {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return JSON.stringify(value, null, 2) ?? String(value);
|
|
27
|
+
} catch {
|
|
28
|
+
return String(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function asRecord(value) {
|
|
32
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
33
|
+
}
|
|
34
|
+
function compactRawDepthDiagnostics(value) {
|
|
35
|
+
const rawDepth = asRecord(value);
|
|
36
|
+
if (!rawDepth) {
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
const compact = {};
|
|
40
|
+
for (const [camera, statsValue] of Object.entries(rawDepth)) {
|
|
41
|
+
const stats = asRecord(statsValue);
|
|
42
|
+
if (!stats) {
|
|
43
|
+
compact[camera] = statsValue;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
compact[camera] = {
|
|
47
|
+
shape: stats.shape,
|
|
48
|
+
dtype: stats.dtype,
|
|
49
|
+
min: stats.min,
|
|
50
|
+
max: stats.max,
|
|
51
|
+
finiteMin: stats.finiteMin,
|
|
52
|
+
finiteMax: stats.finiteMax,
|
|
53
|
+
nanCount: stats.nanCount,
|
|
54
|
+
infCount: stats.infCount,
|
|
55
|
+
belowZeroCount: stats.belowZeroCount,
|
|
56
|
+
aboveOneCount: stats.aboveOneCount,
|
|
57
|
+
outOfRangeCount: stats.outOfRangeCount,
|
|
58
|
+
error: stats.error
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return Object.keys(compact).length > 0 ? compact : void 0;
|
|
62
|
+
}
|
|
63
|
+
function formatExecutionOutput(trace) {
|
|
64
|
+
const outcome = trace.outcome;
|
|
65
|
+
const sandboxRc = outcome?.metadata?.sandboxRc;
|
|
66
|
+
const elapsedMs = outcome?.metadata?.elapsedMs;
|
|
67
|
+
const codePath = outcome?.metadata?.codePath;
|
|
68
|
+
const diagnostics = outcome?.metadata?.diagnostics;
|
|
69
|
+
const lines = [
|
|
70
|
+
outcome ? `executionOk=${outcome.success}, taskCompleted=${outcome.taskCompleted ?? "n/a"}, reward=${outcome.reward ?? "n/a"}` : "Execution completed without an outcome."
|
|
71
|
+
];
|
|
72
|
+
if (sandboxRc !== void 0) {
|
|
73
|
+
lines.push(`sandboxRc=${sandboxRc}`);
|
|
74
|
+
}
|
|
75
|
+
if (elapsedMs !== void 0) {
|
|
76
|
+
lines.push(`elapsedMs=${elapsedMs}`);
|
|
77
|
+
}
|
|
78
|
+
if (codePath !== void 0) {
|
|
79
|
+
lines.push(`codePath=${codePath}`);
|
|
80
|
+
}
|
|
81
|
+
if (diagnostics && typeof diagnostics === "object") {
|
|
82
|
+
lines.push(
|
|
83
|
+
`diagnostics:
|
|
84
|
+
${truncateText(
|
|
85
|
+
stringifyObservationData({
|
|
86
|
+
failurePhase: diagnostics.failurePhase,
|
|
87
|
+
exceptionType: diagnostics.exceptionType,
|
|
88
|
+
exceptionRepr: diagnostics.exceptionRepr,
|
|
89
|
+
observationPipeline: diagnostics.observationPipeline,
|
|
90
|
+
depthAssertion: diagnostics.depthAssertion,
|
|
91
|
+
perceptionApiFailure: diagnostics.perceptionApiFailure,
|
|
92
|
+
emptyPointCloud: diagnostics.emptyPointCloud,
|
|
93
|
+
trial: diagnostics.trial,
|
|
94
|
+
envClass: diagnostics.envClass,
|
|
95
|
+
lowLevelEnvClass: diagnostics.lowLevelEnvClass,
|
|
96
|
+
renderCameraNames: diagnostics.render_camera_names,
|
|
97
|
+
simStepCount: diagnostics._sim_step_count,
|
|
98
|
+
rawDepth: compactRawDepthDiagnostics(diagnostics.rawDepth),
|
|
99
|
+
sourceFiles: diagnostics.sourceFiles
|
|
100
|
+
}),
|
|
101
|
+
MAX_EXECUTION_OUTPUT_CHARS
|
|
102
|
+
)}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (outcome?.terminated !== void 0 || outcome?.truncated !== void 0) {
|
|
106
|
+
lines.push(
|
|
107
|
+
`terminated=${outcome.terminated ?? "n/a"}, truncated=${outcome.truncated ?? "n/a"}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (trace.stdout) {
|
|
111
|
+
lines.push(
|
|
112
|
+
`stdout:
|
|
113
|
+
${truncateText(trace.stdout, MAX_EXECUTION_OUTPUT_CHARS)}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (trace.stderr) {
|
|
117
|
+
lines.push(
|
|
118
|
+
`stderr:
|
|
119
|
+
${truncateText(trace.stderr, MAX_EXECUTION_OUTPUT_CHARS)}`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
if (trace.artifacts?.length) {
|
|
123
|
+
lines.push(
|
|
124
|
+
`artifacts:
|
|
125
|
+
${trace.artifacts.map((artifact) => `${artifact.kind}: ${artifact.uri}`).join("\n")}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return lines.join("\n\n");
|
|
129
|
+
}
|
|
130
|
+
function formatImageObservation(item) {
|
|
131
|
+
if (item.kind !== "rgb" && item.kind !== "depth") {
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
const details = [
|
|
135
|
+
item.width && item.height ? `size=${item.width}x${item.height}` : null,
|
|
136
|
+
item.mimeType ? `mime=${item.mimeType}` : null,
|
|
137
|
+
item.frame ? `frame=${item.frame}` : null,
|
|
138
|
+
item.uri ? `uri=${item.uri}` : null,
|
|
139
|
+
item.dataUrl ? "dataUrl=available in tool metadata" : null
|
|
140
|
+
].filter(Boolean);
|
|
141
|
+
return details.length > 0 ? details.join(", ") : "image captured";
|
|
142
|
+
}
|
|
143
|
+
function formatObservationItem(item, index) {
|
|
144
|
+
const header = `## Observation ${index + 1}: ${item.source} (${item.kind})`;
|
|
145
|
+
if (item.kind === "text") {
|
|
146
|
+
return `${header}
|
|
147
|
+
${truncateText(item.text, MAX_OBSERVATION_ITEM_CHARS)}`;
|
|
148
|
+
}
|
|
149
|
+
if (item.kind === "rgb" || item.kind === "depth") {
|
|
150
|
+
return `${header}
|
|
151
|
+
${formatImageObservation(item)}`;
|
|
152
|
+
}
|
|
153
|
+
if (!("data" in item)) {
|
|
154
|
+
return `${header}
|
|
155
|
+
No structured payload was provided.`;
|
|
156
|
+
}
|
|
157
|
+
return `${header}
|
|
158
|
+
${truncateText(
|
|
159
|
+
stringifyObservationData(item.data),
|
|
160
|
+
MAX_OBSERVATION_ITEM_CHARS
|
|
161
|
+
)}`;
|
|
162
|
+
}
|
|
163
|
+
function formatObservationOutput(observation) {
|
|
164
|
+
const summary = observation.summary ?? `${observation.items.length} observation item(s) captured.`;
|
|
165
|
+
if (observation.items.length === 0) {
|
|
166
|
+
return summary;
|
|
167
|
+
}
|
|
168
|
+
const sections = [
|
|
169
|
+
summary,
|
|
170
|
+
...observation.items.map(
|
|
171
|
+
(item, index) => formatObservationItem(item, index)
|
|
172
|
+
)
|
|
173
|
+
];
|
|
174
|
+
const output = sections.join("\n\n");
|
|
175
|
+
return truncateText(output, MAX_OBSERVATION_OUTPUT_CHARS);
|
|
176
|
+
}
|
|
177
|
+
function parseImageData(item) {
|
|
178
|
+
if (item.kind !== "rgb" && item.kind !== "depth") {
|
|
179
|
+
return void 0;
|
|
180
|
+
}
|
|
181
|
+
if (!item.dataUrl) {
|
|
182
|
+
return void 0;
|
|
183
|
+
}
|
|
184
|
+
const match = item.dataUrl.match(/^data:([^;,]+)(?:;[^,]*)?,(.*)$/s);
|
|
185
|
+
if (!match) {
|
|
186
|
+
return void 0;
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
mediaType: item.mimeType ?? match[1] ?? "image/png",
|
|
190
|
+
data: match[2] ?? ""
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function createObservationModelOutput(observation, output) {
|
|
194
|
+
const parts = [{ type: "text", text: output }];
|
|
195
|
+
for (const item of observation.items) {
|
|
196
|
+
const image = parseImageData(item);
|
|
197
|
+
if (!image) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
parts.push({
|
|
201
|
+
type: "file-data",
|
|
202
|
+
data: image.data,
|
|
203
|
+
mediaType: image.mediaType
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return parts.length > 1 ? {
|
|
207
|
+
type: "content",
|
|
208
|
+
value: parts
|
|
209
|
+
} : {
|
|
210
|
+
type: "text",
|
|
211
|
+
value: output
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function createPhysicalStatusTool(session, options) {
|
|
215
|
+
return Tool.define(
|
|
216
|
+
toolName("status", options),
|
|
217
|
+
{
|
|
218
|
+
description: "Read the current physical session state and lifecycle status without moving or changing the environment.",
|
|
219
|
+
parameters: z.object({}),
|
|
220
|
+
capabilities: {
|
|
221
|
+
parallelSafe: true,
|
|
222
|
+
readOnly: true,
|
|
223
|
+
riskLevel: "safe"
|
|
224
|
+
},
|
|
225
|
+
execute: async () => {
|
|
226
|
+
const state = await session.getState();
|
|
227
|
+
return {
|
|
228
|
+
title: "Physical Session Status",
|
|
229
|
+
output: describePhysicalState(state),
|
|
230
|
+
metadata: {
|
|
231
|
+
physical: {
|
|
232
|
+
sessionId: session.id,
|
|
233
|
+
status: state.status,
|
|
234
|
+
state
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
capabilitiesHint: {
|
|
242
|
+
parallelSafe: true,
|
|
243
|
+
readOnly: true,
|
|
244
|
+
riskLevel: "safe"
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
function createPhysicalObserveTool(session, options) {
|
|
250
|
+
return Tool.define(
|
|
251
|
+
toolName("observe", options),
|
|
252
|
+
{
|
|
253
|
+
description: "Capture the latest physical-world observation and session context for the active robot or simulator without moving or changing the environment.",
|
|
254
|
+
parameters: z.object({
|
|
255
|
+
includeImages: z.boolean().optional().describe(
|
|
256
|
+
"Whether image observations should be included when available."
|
|
257
|
+
),
|
|
258
|
+
includeArtifacts: z.boolean().optional().describe(
|
|
259
|
+
"Whether artifact references should be included when available."
|
|
260
|
+
),
|
|
261
|
+
maxItems: z.number().int().positive().optional().describe("Maximum number of observation items to return.")
|
|
262
|
+
}),
|
|
263
|
+
capabilities: {
|
|
264
|
+
parallelSafe: true,
|
|
265
|
+
readOnly: true,
|
|
266
|
+
riskLevel: "safe"
|
|
267
|
+
},
|
|
268
|
+
execute: async (params) => {
|
|
269
|
+
if (!session.observe) {
|
|
270
|
+
return {
|
|
271
|
+
title: "Observation Unsupported",
|
|
272
|
+
output: "This physical session does not expose observations.",
|
|
273
|
+
metadata: {
|
|
274
|
+
physical: {
|
|
275
|
+
sessionId: session.id
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
const observeOptions = {
|
|
281
|
+
includeImages: params.includeImages,
|
|
282
|
+
includeArtifacts: params.includeArtifacts,
|
|
283
|
+
maxItems: params.maxItems
|
|
284
|
+
};
|
|
285
|
+
const observation = await session.observe(observeOptions);
|
|
286
|
+
const output = formatObservationOutput(observation);
|
|
287
|
+
return {
|
|
288
|
+
title: "Physical Observation",
|
|
289
|
+
output,
|
|
290
|
+
metadata: {
|
|
291
|
+
modelOutput: createObservationModelOutput(observation, output),
|
|
292
|
+
physical: {
|
|
293
|
+
sessionId: session.id,
|
|
294
|
+
status: observation.status,
|
|
295
|
+
observation
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
capabilitiesHint: {
|
|
303
|
+
parallelSafe: true,
|
|
304
|
+
readOnly: true,
|
|
305
|
+
riskLevel: "safe"
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
function createPhysicalRunCodeTool(session, options) {
|
|
311
|
+
return Tool.define(
|
|
312
|
+
toolName("run_policy_code", options),
|
|
313
|
+
{
|
|
314
|
+
description: "Execute policy code inside the active physical session after observing the current context. This can move a robot or mutate a simulator.",
|
|
315
|
+
parameters: z.object({
|
|
316
|
+
code: z.string().min(1).describe("Executable policy code."),
|
|
317
|
+
language: z.string().optional().describe("Code language. Defaults to the session runtime language."),
|
|
318
|
+
timeoutMs: z.number().int().positive().optional().describe("Optional execution timeout in milliseconds."),
|
|
319
|
+
dryRun: z.boolean().optional().describe(
|
|
320
|
+
"Validate or stage the code without executing if supported."
|
|
321
|
+
)
|
|
322
|
+
}),
|
|
323
|
+
capabilities: {
|
|
324
|
+
parallelSafe: false,
|
|
325
|
+
readOnly: false,
|
|
326
|
+
destructive: true,
|
|
327
|
+
riskLevel: "dangerous",
|
|
328
|
+
onInterrupt: "cancel"
|
|
329
|
+
},
|
|
330
|
+
replayPolicy: {
|
|
331
|
+
mode: "manual",
|
|
332
|
+
sideEffectLevel: "external",
|
|
333
|
+
reason: "Physical code execution may move hardware or mutate simulator state and must not be replayed automatically."
|
|
334
|
+
},
|
|
335
|
+
execute: async (params) => {
|
|
336
|
+
if (!session.executeCode) {
|
|
337
|
+
return {
|
|
338
|
+
title: "Policy Execution Unsupported",
|
|
339
|
+
output: "This physical session does not expose direct policy-code execution.",
|
|
340
|
+
metadata: {
|
|
341
|
+
physical: {
|
|
342
|
+
sessionId: session.id
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const policy = normalizePhysicalSafetyPolicy({
|
|
348
|
+
riskLevel: "dangerous",
|
|
349
|
+
requiresApproval: true,
|
|
350
|
+
requiresHumanPresence: true
|
|
351
|
+
});
|
|
352
|
+
const trace = await session.executeCode({
|
|
353
|
+
code: params.code,
|
|
354
|
+
language: params.language,
|
|
355
|
+
timeoutMs: params.timeoutMs,
|
|
356
|
+
dryRun: params.dryRun,
|
|
357
|
+
metadata: { safety: policy }
|
|
358
|
+
});
|
|
359
|
+
return {
|
|
360
|
+
title: "Physical Policy Execution",
|
|
361
|
+
output: formatExecutionOutput(trace),
|
|
362
|
+
metadata: {
|
|
363
|
+
physical: {
|
|
364
|
+
sessionId: session.id,
|
|
365
|
+
trace
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
capabilitiesHint: {
|
|
373
|
+
parallelSafe: false,
|
|
374
|
+
readOnly: false,
|
|
375
|
+
destructive: true,
|
|
376
|
+
riskLevel: "dangerous",
|
|
377
|
+
onInterrupt: "cancel"
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
function createPhysicalStopTool(session, options) {
|
|
383
|
+
return Tool.define(
|
|
384
|
+
toolName("stop", options),
|
|
385
|
+
{
|
|
386
|
+
description: "Stop the active physical session as quickly as the backend supports. Use only when requested or when continuing would be unsafe.",
|
|
387
|
+
parameters: z.object({
|
|
388
|
+
reason: z.string().optional().describe("Reason for stopping the session.")
|
|
389
|
+
}),
|
|
390
|
+
capabilities: {
|
|
391
|
+
parallelSafe: false,
|
|
392
|
+
readOnly: false,
|
|
393
|
+
destructive: true,
|
|
394
|
+
riskLevel: "dangerous",
|
|
395
|
+
onInterrupt: "cancel"
|
|
396
|
+
},
|
|
397
|
+
replayPolicy: {
|
|
398
|
+
mode: "manual",
|
|
399
|
+
sideEffectLevel: "external",
|
|
400
|
+
reason: "Stopping a physical session is a control-plane side effect and should not be replayed automatically."
|
|
401
|
+
},
|
|
402
|
+
execute: async ({ reason }) => {
|
|
403
|
+
const state = await session.stop(reason);
|
|
404
|
+
return {
|
|
405
|
+
title: "Physical Session Stopped",
|
|
406
|
+
output: describePhysicalState(state),
|
|
407
|
+
metadata: {
|
|
408
|
+
physical: {
|
|
409
|
+
sessionId: session.id,
|
|
410
|
+
status: state.status,
|
|
411
|
+
state
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
capabilitiesHint: {
|
|
419
|
+
parallelSafe: false,
|
|
420
|
+
readOnly: false,
|
|
421
|
+
destructive: true,
|
|
422
|
+
riskLevel: "dangerous",
|
|
423
|
+
onInterrupt: "cancel"
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
function createPhysicalArtifactsTool(session, options) {
|
|
429
|
+
return Tool.define(
|
|
430
|
+
toolName("artifacts", options),
|
|
431
|
+
{
|
|
432
|
+
description: "List artifacts produced by the active physical session, such as logs, generated code, images, videos, or result directories.",
|
|
433
|
+
parameters: z.object({
|
|
434
|
+
kind: z.enum(["code", "log", "image", "video", "json", "directory", "other"]).optional().describe("Optional artifact kind filter."),
|
|
435
|
+
limit: z.number().int().positive().optional().describe("Maximum number of artifacts to return.")
|
|
436
|
+
}),
|
|
437
|
+
capabilities: {
|
|
438
|
+
parallelSafe: true,
|
|
439
|
+
readOnly: true,
|
|
440
|
+
riskLevel: "safe"
|
|
441
|
+
},
|
|
442
|
+
execute: async (params) => {
|
|
443
|
+
if (!session.listArtifacts) {
|
|
444
|
+
return {
|
|
445
|
+
title: "Artifacts Unsupported",
|
|
446
|
+
output: "This physical session does not expose artifacts.",
|
|
447
|
+
metadata: {
|
|
448
|
+
physical: {
|
|
449
|
+
sessionId: session.id
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
const listOptions = {
|
|
455
|
+
kind: params.kind,
|
|
456
|
+
limit: params.limit
|
|
457
|
+
};
|
|
458
|
+
const artifacts = await session.listArtifacts(listOptions);
|
|
459
|
+
const output = artifacts.length === 0 ? "No physical-session artifacts found." : artifacts.map((artifact) => `${artifact.kind}: ${artifact.uri}`).join("\n");
|
|
460
|
+
return {
|
|
461
|
+
title: "Physical Artifacts",
|
|
462
|
+
output,
|
|
463
|
+
metadata: {
|
|
464
|
+
physical: {
|
|
465
|
+
sessionId: session.id,
|
|
466
|
+
artifacts
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
capabilitiesHint: {
|
|
474
|
+
parallelSafe: true,
|
|
475
|
+
readOnly: true,
|
|
476
|
+
riskLevel: "safe"
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
function createPhysicalSessionTools(session, options) {
|
|
482
|
+
const tools = [
|
|
483
|
+
createPhysicalStatusTool(session, options),
|
|
484
|
+
createPhysicalObserveTool(session, options),
|
|
485
|
+
createPhysicalArtifactsTool(session, options),
|
|
486
|
+
createPhysicalStopTool(session, options)
|
|
487
|
+
];
|
|
488
|
+
if (session.executeCode) {
|
|
489
|
+
tools.splice(2, 0, createPhysicalRunCodeTool(session, options));
|
|
490
|
+
}
|
|
491
|
+
return tools;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export {
|
|
495
|
+
createPhysicalStatusTool,
|
|
496
|
+
createPhysicalObserveTool,
|
|
497
|
+
createPhysicalRunCodeTool,
|
|
498
|
+
createPhysicalStopTool,
|
|
499
|
+
createPhysicalArtifactsTool,
|
|
500
|
+
createPhysicalSessionTools
|
|
501
|
+
};
|
|
502
|
+
//# sourceMappingURL=chunk-6VUPCNET.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tools/index.ts"],"sourcesContent":["import { Tool } from \"@cuylabs/agent-core/tool\";\nimport type { ToolModelOutput } from \"@cuylabs/agent-core/tool\";\nimport { z } from \"zod\";\nimport {\n describePhysicalState,\n normalizePhysicalSafetyPolicy,\n} from \"@cuylabs/physical-core\";\nimport type {\n PhysicalExecutionTrace,\n PhysicalListArtifactsOptions,\n PhysicalObserveOptions,\n PhysicalObservation,\n PhysicalObservationItem,\n PhysicalSession,\n PhysicalToolMetadata,\n} from \"@cuylabs/physical-core\";\n\nexport type PhysicalTool = Tool.Info;\n\ntype ToolModelContentPart = Extract<\n ToolModelOutput,\n { type: \"content\" }\n>[\"value\"][number];\n\nexport interface PhysicalToolOptions {\n /**\n * Prefix used for generated tool ids. Defaults to \"physical\".\n */\n prefix?: string;\n}\n\nfunction toolName(name: string, options?: PhysicalToolOptions): string {\n return `${options?.prefix ?? \"physical\"}_${name}`;\n}\n\nconst MAX_OBSERVATION_ITEM_CHARS = 12_000;\nconst MAX_OBSERVATION_OUTPUT_CHARS = 60_000;\nconst MAX_EXECUTION_OUTPUT_CHARS = 8_000;\n\nfunction truncateText(value: string, maxChars: number): string {\n if (value.length <= maxChars) {\n return value;\n }\n\n return `${value.slice(0, maxChars)}\\n... (${value.length - maxChars} characters omitted from this observation item)`;\n}\n\nfunction stringifyObservationData(value: unknown): string {\n if (typeof value === \"string\") {\n return value;\n }\n\n try {\n return JSON.stringify(value, null, 2) ?? String(value);\n } catch {\n return String(value);\n }\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n return value && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\nfunction compactRawDepthDiagnostics(\n value: unknown,\n): Record<string, unknown> | undefined {\n const rawDepth = asRecord(value);\n if (!rawDepth) {\n return undefined;\n }\n\n const compact: Record<string, unknown> = {};\n for (const [camera, statsValue] of Object.entries(rawDepth)) {\n const stats = asRecord(statsValue);\n if (!stats) {\n compact[camera] = statsValue;\n continue;\n }\n\n compact[camera] = {\n shape: stats.shape,\n dtype: stats.dtype,\n min: stats.min,\n max: stats.max,\n finiteMin: stats.finiteMin,\n finiteMax: stats.finiteMax,\n nanCount: stats.nanCount,\n infCount: stats.infCount,\n belowZeroCount: stats.belowZeroCount,\n aboveOneCount: stats.aboveOneCount,\n outOfRangeCount: stats.outOfRangeCount,\n error: stats.error,\n };\n }\n\n return Object.keys(compact).length > 0 ? compact : undefined;\n}\n\nfunction formatExecutionOutput(trace: PhysicalExecutionTrace): string {\n const outcome = trace.outcome;\n const sandboxRc = outcome?.metadata?.sandboxRc;\n const elapsedMs = outcome?.metadata?.elapsedMs;\n const codePath = outcome?.metadata?.codePath;\n const diagnostics = outcome?.metadata?.diagnostics as\n | Record<string, unknown>\n | undefined;\n const lines = [\n outcome\n ? `executionOk=${outcome.success}, taskCompleted=${outcome.taskCompleted ?? \"n/a\"}, reward=${outcome.reward ?? \"n/a\"}`\n : \"Execution completed without an outcome.\",\n ];\n\n if (sandboxRc !== undefined) {\n lines.push(`sandboxRc=${sandboxRc}`);\n }\n if (elapsedMs !== undefined) {\n lines.push(`elapsedMs=${elapsedMs}`);\n }\n if (codePath !== undefined) {\n lines.push(`codePath=${codePath}`);\n }\n if (diagnostics && typeof diagnostics === \"object\") {\n lines.push(\n `diagnostics:\\n${truncateText(\n stringifyObservationData({\n failurePhase: diagnostics.failurePhase,\n exceptionType: diagnostics.exceptionType,\n exceptionRepr: diagnostics.exceptionRepr,\n observationPipeline: diagnostics.observationPipeline,\n depthAssertion: diagnostics.depthAssertion,\n perceptionApiFailure: diagnostics.perceptionApiFailure,\n emptyPointCloud: diagnostics.emptyPointCloud,\n trial: diagnostics.trial,\n envClass: diagnostics.envClass,\n lowLevelEnvClass: diagnostics.lowLevelEnvClass,\n renderCameraNames: diagnostics.render_camera_names,\n simStepCount: diagnostics._sim_step_count,\n rawDepth: compactRawDepthDiagnostics(diagnostics.rawDepth),\n sourceFiles: diagnostics.sourceFiles,\n }),\n MAX_EXECUTION_OUTPUT_CHARS,\n )}`,\n );\n }\n if (outcome?.terminated !== undefined || outcome?.truncated !== undefined) {\n lines.push(\n `terminated=${outcome.terminated ?? \"n/a\"}, truncated=${outcome.truncated ?? \"n/a\"}`,\n );\n }\n if (trace.stdout) {\n lines.push(\n `stdout:\\n${truncateText(trace.stdout, MAX_EXECUTION_OUTPUT_CHARS)}`,\n );\n }\n if (trace.stderr) {\n lines.push(\n `stderr:\\n${truncateText(trace.stderr, MAX_EXECUTION_OUTPUT_CHARS)}`,\n );\n }\n if (trace.artifacts?.length) {\n lines.push(\n `artifacts:\\n${trace.artifacts\n .map((artifact) => `${artifact.kind}: ${artifact.uri}`)\n .join(\"\\n\")}`,\n );\n }\n\n return lines.join(\"\\n\\n\");\n}\n\nfunction formatImageObservation(item: PhysicalObservationItem): string {\n if (item.kind !== \"rgb\" && item.kind !== \"depth\") {\n return \"\";\n }\n\n const details = [\n item.width && item.height ? `size=${item.width}x${item.height}` : null,\n item.mimeType ? `mime=${item.mimeType}` : null,\n item.frame ? `frame=${item.frame}` : null,\n item.uri ? `uri=${item.uri}` : null,\n item.dataUrl ? \"dataUrl=available in tool metadata\" : null,\n ].filter(Boolean);\n\n return details.length > 0 ? details.join(\", \") : \"image captured\";\n}\n\nfunction formatObservationItem(\n item: PhysicalObservationItem,\n index: number,\n): string {\n const header = `## Observation ${index + 1}: ${item.source} (${item.kind})`;\n\n if (item.kind === \"text\") {\n return `${header}\\n${truncateText(item.text, MAX_OBSERVATION_ITEM_CHARS)}`;\n }\n\n if (item.kind === \"rgb\" || item.kind === \"depth\") {\n return `${header}\\n${formatImageObservation(item)}`;\n }\n\n if (!(\"data\" in item)) {\n return `${header}\\nNo structured payload was provided.`;\n }\n\n return `${header}\\n${truncateText(\n stringifyObservationData(item.data),\n MAX_OBSERVATION_ITEM_CHARS,\n )}`;\n}\n\nfunction formatObservationOutput(observation: PhysicalObservation): string {\n const summary =\n observation.summary ??\n `${observation.items.length} observation item(s) captured.`;\n if (observation.items.length === 0) {\n return summary;\n }\n\n const sections = [\n summary,\n ...observation.items.map((item, index) =>\n formatObservationItem(item, index),\n ),\n ];\n const output = sections.join(\"\\n\\n\");\n return truncateText(output, MAX_OBSERVATION_OUTPUT_CHARS);\n}\n\nfunction parseImageData(\n item: PhysicalObservationItem,\n): { data: string; mediaType: string } | undefined {\n if (item.kind !== \"rgb\" && item.kind !== \"depth\") {\n return undefined;\n }\n\n if (!item.dataUrl) {\n return undefined;\n }\n\n const match = item.dataUrl.match(/^data:([^;,]+)(?:;[^,]*)?,(.*)$/s);\n if (!match) {\n return undefined;\n }\n\n return {\n mediaType: item.mimeType ?? match[1] ?? \"image/png\",\n data: match[2] ?? \"\",\n };\n}\n\nfunction createObservationModelOutput(\n observation: PhysicalObservation,\n output: string,\n): ToolModelOutput {\n const parts: ToolModelContentPart[] = [{ type: \"text\", text: output }];\n\n for (const item of observation.items) {\n const image = parseImageData(item);\n if (!image) {\n continue;\n }\n parts.push({\n type: \"file-data\",\n data: image.data,\n mediaType: image.mediaType,\n });\n }\n\n return parts.length > 1\n ? {\n type: \"content\",\n value: parts,\n }\n : {\n type: \"text\",\n value: output,\n };\n}\n\nexport function createPhysicalStatusTool(\n session: PhysicalSession,\n options?: PhysicalToolOptions,\n) {\n return Tool.define(\n toolName(\"status\", options),\n {\n description:\n \"Read the current physical session state and lifecycle status without moving or changing the environment.\",\n parameters: z.object({}),\n capabilities: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n execute: async () => {\n const state = await session.getState();\n return {\n title: \"Physical Session Status\",\n output: describePhysicalState(state),\n metadata: {\n physical: {\n sessionId: session.id,\n status: state.status,\n state,\n },\n } as PhysicalToolMetadata,\n };\n },\n },\n {\n capabilitiesHint: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n },\n );\n}\n\nexport function createPhysicalObserveTool(\n session: PhysicalSession,\n options?: PhysicalToolOptions,\n) {\n return Tool.define(\n toolName(\"observe\", options),\n {\n description:\n \"Capture the latest physical-world observation and session context for the active robot or simulator without moving or changing the environment.\",\n parameters: z.object({\n includeImages: z\n .boolean()\n .optional()\n .describe(\n \"Whether image observations should be included when available.\",\n ),\n includeArtifacts: z\n .boolean()\n .optional()\n .describe(\n \"Whether artifact references should be included when available.\",\n ),\n maxItems: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Maximum number of observation items to return.\"),\n }),\n capabilities: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n execute: async (params) => {\n if (!session.observe) {\n return {\n title: \"Observation Unsupported\",\n output: \"This physical session does not expose observations.\",\n metadata: {\n physical: {\n sessionId: session.id,\n },\n } as PhysicalToolMetadata,\n };\n }\n\n const observeOptions: PhysicalObserveOptions = {\n includeImages: params.includeImages,\n includeArtifacts: params.includeArtifacts,\n maxItems: params.maxItems,\n };\n const observation = await session.observe(observeOptions);\n const output = formatObservationOutput(observation);\n return {\n title: \"Physical Observation\",\n output,\n metadata: {\n modelOutput: createObservationModelOutput(observation, output),\n physical: {\n sessionId: session.id,\n status: observation.status,\n observation,\n },\n } as PhysicalToolMetadata,\n };\n },\n },\n {\n capabilitiesHint: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n },\n );\n}\n\nexport function createPhysicalRunCodeTool(\n session: PhysicalSession,\n options?: PhysicalToolOptions,\n) {\n return Tool.define(\n toolName(\"run_policy_code\", options),\n {\n description:\n \"Execute policy code inside the active physical session after observing the current context. This can move a robot or mutate a simulator.\",\n parameters: z.object({\n code: z.string().min(1).describe(\"Executable policy code.\"),\n language: z\n .string()\n .optional()\n .describe(\"Code language. Defaults to the session runtime language.\"),\n timeoutMs: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Optional execution timeout in milliseconds.\"),\n dryRun: z\n .boolean()\n .optional()\n .describe(\n \"Validate or stage the code without executing if supported.\",\n ),\n }),\n capabilities: {\n parallelSafe: false,\n readOnly: false,\n destructive: true,\n riskLevel: \"dangerous\",\n onInterrupt: \"cancel\",\n },\n replayPolicy: {\n mode: \"manual\",\n sideEffectLevel: \"external\",\n reason:\n \"Physical code execution may move hardware or mutate simulator state and must not be replayed automatically.\",\n },\n execute: async (params) => {\n if (!session.executeCode) {\n return {\n title: \"Policy Execution Unsupported\",\n output:\n \"This physical session does not expose direct policy-code execution.\",\n metadata: {\n physical: {\n sessionId: session.id,\n },\n } as PhysicalToolMetadata,\n };\n }\n\n const policy = normalizePhysicalSafetyPolicy({\n riskLevel: \"dangerous\",\n requiresApproval: true,\n requiresHumanPresence: true,\n });\n const trace = await session.executeCode({\n code: params.code,\n language: params.language,\n timeoutMs: params.timeoutMs,\n dryRun: params.dryRun,\n metadata: { safety: policy },\n });\n\n return {\n title: \"Physical Policy Execution\",\n output: formatExecutionOutput(trace),\n metadata: {\n physical: {\n sessionId: session.id,\n trace,\n },\n } as PhysicalToolMetadata,\n };\n },\n },\n {\n capabilitiesHint: {\n parallelSafe: false,\n readOnly: false,\n destructive: true,\n riskLevel: \"dangerous\",\n onInterrupt: \"cancel\",\n },\n },\n );\n}\n\nexport function createPhysicalStopTool(\n session: PhysicalSession,\n options?: PhysicalToolOptions,\n) {\n return Tool.define(\n toolName(\"stop\", options),\n {\n description:\n \"Stop the active physical session as quickly as the backend supports. Use only when requested or when continuing would be unsafe.\",\n parameters: z.object({\n reason: z\n .string()\n .optional()\n .describe(\"Reason for stopping the session.\"),\n }),\n capabilities: {\n parallelSafe: false,\n readOnly: false,\n destructive: true,\n riskLevel: \"dangerous\",\n onInterrupt: \"cancel\",\n },\n replayPolicy: {\n mode: \"manual\",\n sideEffectLevel: \"external\",\n reason:\n \"Stopping a physical session is a control-plane side effect and should not be replayed automatically.\",\n },\n execute: async ({ reason }) => {\n const state = await session.stop(reason);\n return {\n title: \"Physical Session Stopped\",\n output: describePhysicalState(state),\n metadata: {\n physical: {\n sessionId: session.id,\n status: state.status,\n state,\n },\n } as PhysicalToolMetadata,\n };\n },\n },\n {\n capabilitiesHint: {\n parallelSafe: false,\n readOnly: false,\n destructive: true,\n riskLevel: \"dangerous\",\n onInterrupt: \"cancel\",\n },\n },\n );\n}\n\nexport function createPhysicalArtifactsTool(\n session: PhysicalSession,\n options?: PhysicalToolOptions,\n) {\n return Tool.define(\n toolName(\"artifacts\", options),\n {\n description:\n \"List artifacts produced by the active physical session, such as logs, generated code, images, videos, or result directories.\",\n parameters: z.object({\n kind: z\n .enum([\"code\", \"log\", \"image\", \"video\", \"json\", \"directory\", \"other\"])\n .optional()\n .describe(\"Optional artifact kind filter.\"),\n limit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Maximum number of artifacts to return.\"),\n }),\n capabilities: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n execute: async (params) => {\n if (!session.listArtifacts) {\n return {\n title: \"Artifacts Unsupported\",\n output: \"This physical session does not expose artifacts.\",\n metadata: {\n physical: {\n sessionId: session.id,\n },\n } as PhysicalToolMetadata,\n };\n }\n\n const listOptions: PhysicalListArtifactsOptions = {\n kind: params.kind,\n limit: params.limit,\n };\n const artifacts = await session.listArtifacts(listOptions);\n const output =\n artifacts.length === 0\n ? \"No physical-session artifacts found.\"\n : artifacts\n .map((artifact) => `${artifact.kind}: ${artifact.uri}`)\n .join(\"\\n\");\n return {\n title: \"Physical Artifacts\",\n output,\n metadata: {\n physical: {\n sessionId: session.id,\n artifacts,\n },\n } as PhysicalToolMetadata,\n };\n },\n },\n {\n capabilitiesHint: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n },\n );\n}\n\nexport function createPhysicalSessionTools(\n session: PhysicalSession,\n options?: PhysicalToolOptions,\n) {\n const tools: Tool.AnyInfo[] = [\n createPhysicalStatusTool(session, options),\n createPhysicalObserveTool(session, options),\n createPhysicalArtifactsTool(session, options),\n createPhysicalStopTool(session, options),\n ];\n\n if (session.executeCode) {\n tools.splice(2, 0, createPhysicalRunCodeTool(session, options));\n }\n\n return tools;\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAErB,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAyBP,SAAS,SAAS,MAAc,SAAuC;AACrE,SAAO,GAAG,SAAS,UAAU,UAAU,IAAI,IAAI;AACjD;AAEA,IAAM,6BAA6B;AACnC,IAAM,+BAA+B;AACrC,IAAM,6BAA6B;AAEnC,SAAS,aAAa,OAAe,UAA0B;AAC7D,MAAI,MAAM,UAAU,UAAU;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,MAAM,MAAM,GAAG,QAAQ,CAAC;AAAA,OAAU,MAAM,SAAS,QAAQ;AACrE;AAEA,SAAS,yBAAyB,OAAwB;AACxD,MAAI,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AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,kBAAkB;AAAA,QAChB,cAAc;AAAA,QACd,UAAU;AAAA,QACV,WAAW;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,2BACd,SACA,SACA;AACA,QAAM,QAAwB;AAAA,IAC5B,yBAAyB,SAAS,OAAO;AAAA,IACzC,0BAA0B,SAAS,OAAO;AAAA,IAC1C,4BAA4B,SAAS,OAAO;AAAA,IAC5C,uBAAuB,SAAS,OAAO;AAAA,EACzC;AAEA,MAAI,QAAQ,aAAa;AACvB,UAAM,OAAO,GAAG,GAAG,0BAA0B,SAAS,OAAO,CAAC;AAAA,EAChE;AAEA,SAAO;AACT;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { PhysicalAdapter, PhysicalArtifact, PhysicalCapability, PhysicalExecutionMode, PhysicalExecutionRequest, PhysicalExecutionTrace, PhysicalFrame, PhysicalImageObservation, PhysicalListArtifactsOptions, PhysicalObservation, PhysicalObservationItem, PhysicalObservationKind, PhysicalObserveOptions, PhysicalOutcome, PhysicalPose, PhysicalQuaternionWxyz, PhysicalRiskLevel, PhysicalSafetyPolicy, PhysicalSession, PhysicalSessionStartOptions, PhysicalSessionState, PhysicalSessionStatus, PhysicalStructuredObservation, PhysicalTaskSpec, PhysicalTextObservation, PhysicalToolMetadata, PhysicalVector3, defaultPhysicalSafetyPolicy, describePhysicalState, isModeAllowed, normalizePhysicalSafetyPolicy } from '@cuylabs/physical-core';
|
|
2
|
+
export { PhysicalTool, PhysicalToolOptions, createPhysicalArtifactsTool, createPhysicalObserveTool, createPhysicalRunCodeTool, createPhysicalSessionTools, createPhysicalStatusTool, createPhysicalStopTool } from './tools/index.js';
|
|
3
|
+
import '@cuylabs/agent-core/tool';
|
|
4
|
+
import 'zod';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPhysicalArtifactsTool,
|
|
3
|
+
createPhysicalObserveTool,
|
|
4
|
+
createPhysicalRunCodeTool,
|
|
5
|
+
createPhysicalSessionTools,
|
|
6
|
+
createPhysicalStatusTool,
|
|
7
|
+
createPhysicalStopTool
|
|
8
|
+
} from "./chunk-6VUPCNET.js";
|
|
9
|
+
|
|
10
|
+
// src/index.ts
|
|
11
|
+
import {
|
|
12
|
+
defaultPhysicalSafetyPolicy,
|
|
13
|
+
describePhysicalState,
|
|
14
|
+
isModeAllowed,
|
|
15
|
+
normalizePhysicalSafetyPolicy
|
|
16
|
+
} from "@cuylabs/physical-core";
|
|
17
|
+
export {
|
|
18
|
+
createPhysicalArtifactsTool,
|
|
19
|
+
createPhysicalObserveTool,
|
|
20
|
+
createPhysicalRunCodeTool,
|
|
21
|
+
createPhysicalSessionTools,
|
|
22
|
+
createPhysicalStatusTool,
|
|
23
|
+
createPhysicalStopTool,
|
|
24
|
+
defaultPhysicalSafetyPolicy,
|
|
25
|
+
describePhysicalState,
|
|
26
|
+
isModeAllowed,
|
|
27
|
+
normalizePhysicalSafetyPolicy
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type {\n PhysicalAdapter,\n PhysicalArtifact,\n PhysicalCapability,\n PhysicalExecutionMode,\n PhysicalExecutionRequest,\n PhysicalExecutionTrace,\n PhysicalFrame,\n PhysicalImageObservation,\n PhysicalListArtifactsOptions,\n PhysicalObservation,\n PhysicalObservationItem,\n PhysicalObservationKind,\n PhysicalObserveOptions,\n PhysicalOutcome,\n PhysicalPose,\n PhysicalQuaternionWxyz,\n PhysicalSafetyPolicy,\n PhysicalSession,\n PhysicalSessionStartOptions,\n PhysicalSessionState,\n PhysicalSessionStatus,\n PhysicalStructuredObservation,\n PhysicalTaskSpec,\n PhysicalTextObservation,\n PhysicalToolMetadata,\n PhysicalVector3,\n PhysicalRiskLevel,\n} from \"@cuylabs/physical-core\";\n\nexport {\n defaultPhysicalSafetyPolicy,\n describePhysicalState,\n isModeAllowed,\n normalizePhysicalSafetyPolicy,\n} from \"@cuylabs/physical-core\";\n\nexport {\n createPhysicalArtifactsTool,\n createPhysicalObserveTool,\n createPhysicalRunCodeTool,\n createPhysicalSessionTools,\n createPhysicalStatusTool,\n createPhysicalStopTool,\n type PhysicalToolOptions,\n} from \"./tools/index.js\";\n\nexport type { PhysicalTool } from \"./tools/index.js\";\n"],"mappings":";;;;;;;;;;AA8BA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PhysicalSession, PhysicalToolMetadata } from '@cuylabs/physical-core';
|
|
2
|
+
import { Tool } from '@cuylabs/agent-core/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
type PhysicalTool = Tool.Info;
|
|
6
|
+
interface PhysicalToolOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Prefix used for generated tool ids. Defaults to "physical".
|
|
9
|
+
*/
|
|
10
|
+
prefix?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function createPhysicalStatusTool(session: PhysicalSession, options?: PhysicalToolOptions): Tool.Info<z.ZodObject<{}, z.core.$strip>, PhysicalToolMetadata>;
|
|
13
|
+
declare function createPhysicalObserveTool(session: PhysicalSession, options?: PhysicalToolOptions): Tool.Info<z.ZodObject<{
|
|
14
|
+
includeImages: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
includeArtifacts: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
maxItems: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
}, z.core.$strip>, PhysicalToolMetadata>;
|
|
18
|
+
declare function createPhysicalRunCodeTool(session: PhysicalSession, options?: PhysicalToolOptions): Tool.Info<z.ZodObject<{
|
|
19
|
+
code: z.ZodString;
|
|
20
|
+
language: z.ZodOptional<z.ZodString>;
|
|
21
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
}, z.core.$strip>, PhysicalToolMetadata>;
|
|
24
|
+
declare function createPhysicalStopTool(session: PhysicalSession, options?: PhysicalToolOptions): Tool.Info<z.ZodObject<{
|
|
25
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>, PhysicalToolMetadata>;
|
|
27
|
+
declare function createPhysicalArtifactsTool(session: PhysicalSession, options?: PhysicalToolOptions): Tool.Info<z.ZodObject<{
|
|
28
|
+
kind: z.ZodOptional<z.ZodEnum<{
|
|
29
|
+
json: "json";
|
|
30
|
+
code: "code";
|
|
31
|
+
log: "log";
|
|
32
|
+
image: "image";
|
|
33
|
+
video: "video";
|
|
34
|
+
directory: "directory";
|
|
35
|
+
other: "other";
|
|
36
|
+
}>>;
|
|
37
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
}, z.core.$strip>, PhysicalToolMetadata>;
|
|
39
|
+
declare function createPhysicalSessionTools(session: PhysicalSession, options?: PhysicalToolOptions): Tool.AnyInfo[];
|
|
40
|
+
|
|
41
|
+
export { type PhysicalTool, type PhysicalToolOptions, createPhysicalArtifactsTool, createPhysicalObserveTool, createPhysicalRunCodeTool, createPhysicalSessionTools, createPhysicalStatusTool, createPhysicalStopTool };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPhysicalArtifactsTool,
|
|
3
|
+
createPhysicalObserveTool,
|
|
4
|
+
createPhysicalRunCodeTool,
|
|
5
|
+
createPhysicalSessionTools,
|
|
6
|
+
createPhysicalStatusTool,
|
|
7
|
+
createPhysicalStopTool
|
|
8
|
+
} from "../chunk-6VUPCNET.js";
|
|
9
|
+
export {
|
|
10
|
+
createPhysicalArtifactsTool,
|
|
11
|
+
createPhysicalObserveTool,
|
|
12
|
+
createPhysicalRunCodeTool,
|
|
13
|
+
createPhysicalSessionTools,
|
|
14
|
+
createPhysicalStatusTool,
|
|
15
|
+
createPhysicalStopTool
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @cuylabs/physical-agent-core Docs
|
|
2
|
+
|
|
3
|
+
`@cuylabs/physical-agent-core` binds `@cuylabs/physical-core` sessions to
|
|
4
|
+
`@cuylabs/agent-core` tools.
|
|
5
|
+
|
|
6
|
+
Use it for generic model-facing tools over a `PhysicalSession`. Keep backend
|
|
7
|
+
runtime clients in backend packages such as `@cuylabs/physical-capx`.
|
|
8
|
+
|
|
9
|
+
## Tool Mapping
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
physical_status -> session.getState()
|
|
13
|
+
physical_observe -> session.observe()
|
|
14
|
+
physical_artifacts -> session.listArtifacts()
|
|
15
|
+
physical_stop -> session.stop()
|
|
16
|
+
physical_run_policy_code -> session.executeCode()
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`physical_run_policy_code` is only created when the session implements
|
|
20
|
+
`executeCode`. That keeps observe-only and externally controlled sessions from
|
|
21
|
+
exposing a mutating tool they cannot safely execute.
|
|
22
|
+
|
|
23
|
+
## Model Output
|
|
24
|
+
|
|
25
|
+
Observation tools return readable text output for transcripts and structured
|
|
26
|
+
metadata for host applications. Image observations with `dataUrl` values are
|
|
27
|
+
also mapped into `agent-core` model-output metadata so image-capable models can
|
|
28
|
+
inspect rendered frames on the next reasoning step.
|
|
29
|
+
|
|
30
|
+
## Safety And Dispatch
|
|
31
|
+
|
|
32
|
+
This package annotates physical tools with conservative capability metadata.
|
|
33
|
+
Host applications should still apply their own approval and scheduling policy,
|
|
34
|
+
especially for hardware sessions and policy-code execution.
|
|
35
|
+
|
|
36
|
+
`@cuylabs/physical-agent-core` does not enforce hardware safety by itself. It
|
|
37
|
+
provides the generic tool surface and metadata that `agent-core` applications
|
|
38
|
+
can use for approval prompts, audit logs, and dispatch control.
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cuylabs/physical-agent-core",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Agent-core tools for physical AI sessions",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./tools": {
|
|
15
|
+
"types": "./dist/tools/index.d.ts",
|
|
16
|
+
"import": "./dist/tools/index.js",
|
|
17
|
+
"default": "./dist/tools/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"docs",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"zod": "^3.25.76 || ^4.1.8",
|
|
27
|
+
"@cuylabs/physical-core": "^0.1.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@cuylabs/agent-core": "^7.2.1",
|
|
31
|
+
"@types/node": "^22.0.0",
|
|
32
|
+
"tsup": "^8.0.0",
|
|
33
|
+
"typescript": "^5.7.0",
|
|
34
|
+
"vitest": "^4.0.18"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@cuylabs/agent-core": "^7.0.0"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"agent",
|
|
41
|
+
"physical-ai",
|
|
42
|
+
"robotics",
|
|
43
|
+
"tools",
|
|
44
|
+
"safety"
|
|
45
|
+
],
|
|
46
|
+
"author": "cuylabs",
|
|
47
|
+
"license": "Apache-2.0",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/cuylabs-ai/physical-ai-ts.git",
|
|
51
|
+
"directory": "packages/physical-agent-core"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=20"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup --config tsup.config.ts",
|
|
61
|
+
"dev": "tsup --config tsup.config.ts --watch",
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"test": "vitest run",
|
|
64
|
+
"test:watch": "vitest",
|
|
65
|
+
"clean": "rm -rf dist"
|
|
66
|
+
}
|
|
67
|
+
}
|