@cuylabs/physical-capx-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 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,132 @@
1
+ # @cuylabs/physical-capx-agent-core
2
+
3
+ Agent-core CaP-X agent adapter.
4
+
5
+ This package composes `@cuylabs/physical-capx`,
6
+ `@cuylabs/physical-agent-core`, and `@cuylabs/agent-core`. It provides CaP-X
7
+ tool creation, packaged CaP-X model guidance, and `createCapxAgent(...)`.
8
+
9
+ Use this package when the host harness is `@cuylabs/agent-core`. Use
10
+ `@cuylabs/physical-capx` directly when a TypeScript host only needs a
11
+ backend-neutral `CapxSession`.
12
+
13
+ ```text
14
+ agent-core model loop
15
+ -> @cuylabs/physical-capx-agent-core tools
16
+ -> @cuylabs/physical-capx CapxSession
17
+ -> capx-agent-runtime HTTP server
18
+ -> CaP-X Python runtime, selected YAML config, simulator or robot
19
+ ```
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm install @cuylabs/agent-core @cuylabs/physical-core @cuylabs/physical-agent-core @cuylabs/physical-capx @cuylabs/physical-capx-agent-core
25
+ ```
26
+
27
+ ## Use
28
+
29
+ ```typescript
30
+ import { createCapxAgent } from "@cuylabs/physical-capx-agent-core";
31
+
32
+ const { agent, session } = await createCapxAgent({
33
+ model,
34
+ startSession: true,
35
+ toolExecutionMode: "plan",
36
+ sessionOptions: {
37
+ mode: "runtime",
38
+ runtimeServerUrl: "http://127.0.0.1:8210",
39
+ physicalMode: "simulation",
40
+ enablePolicyCodeExecution: true,
41
+ },
42
+ });
43
+ ```
44
+
45
+ The package also exposes a migration-friendly `./session` entrypoint:
46
+
47
+ ```typescript
48
+ import {
49
+ createCapxPhysicalTools,
50
+ createCapxSession,
51
+ } from "@cuylabs/physical-capx-agent-core/session";
52
+ ```
53
+
54
+ ## Runtime Loop
55
+
56
+ The external agent owns reasoning and code generation. CaP-X owns robotics
57
+ execution.
58
+
59
+ ```text
60
+ start CapxSession
61
+ -> capx_observe returns task prompt, state, frame, and codeContext
62
+ -> agent writes one Python policy-code step
63
+ -> capx_run_policy_code submits that code to the live runtime session
64
+ -> agent observes the result, reward, artifacts, and next frame
65
+ -> host or agent continues, reports completion, resets, or stops
66
+ ```
67
+
68
+ `capx_run_policy_code` is the tool that performs physical work. It can mutate a
69
+ simulator or move hardware, so it should stay approval-gated and dispatched by
70
+ the host harness.
71
+
72
+ ## Tools
73
+
74
+ This package generates the `agent-core` tools below. They are the
75
+ TypeScript-facing tool surface for a `CapxSession`; internally they call the
76
+ `capx-agent-runtime` HTTP API through `@cuylabs/physical-capx`.
77
+
78
+ - `capx_status`
79
+ - `capx_observe`
80
+ - `capx_artifacts`
81
+ - `capx_stop`
82
+ - `capx_run_policy_code` when `enablePolicyCodeExecution: true`
83
+ - `capx_turn_history`
84
+
85
+ The raw runtime server exposes HTTP endpoints such as `/sessions`,
86
+ `/sessions/{id}/observe`, `/sessions/{id}/execute-code`,
87
+ `/sessions/{id}/artifacts`, and `/sessions/{id}/turns`. Its optional MCP
88
+ wrapper has its own MCP-native tool names. The list above is the smaller
89
+ `agent-core` default surface.
90
+
91
+ The default model-facing surface is intentionally small. It gives the agent
92
+ enough context to write better Code-as-Policies Python without exposing every
93
+ runtime operation as a separate robot-action tool.
94
+
95
+ ## CaP-X Skills
96
+
97
+ There are two different skill concepts:
98
+
99
+ - `agent-core` skills are `SKILL.md` instruction packs that teach the model how
100
+ to use the CaP-X tools.
101
+ - CaP-X skills are Python helper functions in the runtime skill library.
102
+
103
+ The default agent tool surface exposes CaP-X skill-library information through
104
+ `capx_observe` as policy-code context. Programmatic clients can still use
105
+ `CapxLiveRuntime` from `@cuylabs/physical-capx` to inspect, extract, or inject
106
+ runtime skills deliberately with host approval.
107
+
108
+ ## Boundary
109
+
110
+ Use this package only when the host runtime is `@cuylabs/agent-core`. The
111
+ agent-agnostic CaP-X session adapter remains in `@cuylabs/physical-capx`.
112
+
113
+ The runtime server owns the robotics side: CaP-X checkout, selected YAML
114
+ config, simulator or robot dependencies, CUDA/perception services, model
115
+ assets, output directory, skill-library path, and execution of submitted Python
116
+ programs.
117
+
118
+ This TypeScript package owns only the `agent-core` side: tool creation,
119
+ approval-aware policy-code execution, packaged model guidance, and
120
+ `createCapxAgent(...)`.
121
+
122
+ ## Docs
123
+
124
+ - [docs/README.md](./docs/README.md)
125
+ - [docs/agent-core-integration.md](./docs/agent-core-integration.md)
126
+ - [../physical-capx/docs/how-it-works.md](../physical-capx/docs/how-it-works.md)
127
+ for the runtime/session adapter
128
+ - [examples/README.md](./examples/README.md)
129
+
130
+ ## License
131
+
132
+ Apache-2.0
@@ -0,0 +1,59 @@
1
+ import { Agent, createAgent } from '@cuylabs/agent-core';
2
+ import { PhysicalSessionStartOptions } from '@cuylabs/physical-core';
3
+ import { CapxSession, CapxSessionOptions } from '@cuylabs/physical-capx';
4
+ import { createCapxPhysicalTools } from './tools.js';
5
+ import '@cuylabs/agent-core/tool';
6
+ import '@cuylabs/physical-agent-core';
7
+
8
+ type AgentConstructionConfig = Parameters<typeof createAgent>[0];
9
+ declare const capxAgentSkillRoot: string;
10
+ declare const defaultCapxAgentSystemPrompt: string;
11
+ declare const defaultCapxAgentApproval: NonNullable<AgentConstructionConfig["approval"]>;
12
+ interface CreateCapxAgentOptions extends Omit<AgentConstructionConfig, "name" | "systemPrompt" | "tools"> {
13
+ /**
14
+ * Existing CaP-X session. Use this when another owner creates the session.
15
+ */
16
+ session?: CapxSession;
17
+ /**
18
+ * Options used to create a CaP-X session. Required when session is omitted.
19
+ */
20
+ sessionOptions?: CapxSessionOptions;
21
+ /**
22
+ * Start the CaP-X session before returning. Defaults to false because
23
+ * creating a live runtime session is an external side effect.
24
+ */
25
+ startSession?: boolean;
26
+ /**
27
+ * Optional task metadata for session.start().
28
+ */
29
+ startOptions?: PhysicalSessionStartOptions;
30
+ /**
31
+ * Prefix for generated CaP-X tools. Defaults to "capx".
32
+ */
33
+ toolPrefix?: string;
34
+ /**
35
+ * Extra app-specific tools to expose alongside the CaP-X tools.
36
+ */
37
+ tools?: AgentConstructionConfig["tools"];
38
+ /**
39
+ * Agent name. Defaults to "capx-physical-agent".
40
+ */
41
+ name?: string;
42
+ /**
43
+ * System prompt. Defaults to a CaP-X supervision prompt.
44
+ */
45
+ systemPrompt?: string;
46
+ /**
47
+ * Include the packaged agent-core skill that teaches the agent how to use
48
+ * CaP-X runtime tools. Defaults to true.
49
+ */
50
+ includeDefaultSkill?: boolean;
51
+ }
52
+ interface CapxAgent {
53
+ agent: Agent;
54
+ session: CapxSession;
55
+ tools: ReturnType<typeof createCapxPhysicalTools>;
56
+ }
57
+ declare function createCapxAgent(options: CreateCapxAgentOptions): Promise<CapxAgent>;
58
+
59
+ export { type CapxAgent, type CreateCapxAgentOptions, capxAgentSkillRoot, createCapxAgent, defaultCapxAgentApproval, defaultCapxAgentSystemPrompt };
package/dist/agent.js ADDED
@@ -0,0 +1,14 @@
1
+ import {
2
+ capxAgentSkillRoot,
3
+ createCapxAgent,
4
+ defaultCapxAgentApproval,
5
+ defaultCapxAgentSystemPrompt
6
+ } from "./chunk-U6REPGPH.js";
7
+ import "./chunk-57TF3E2Q.js";
8
+ export {
9
+ capxAgentSkillRoot,
10
+ createCapxAgent,
11
+ defaultCapxAgentApproval,
12
+ defaultCapxAgentSystemPrompt
13
+ };
14
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,61 @@
1
+ // src/tools.ts
2
+ import { Tool } from "@cuylabs/agent-core/tool";
3
+ import {
4
+ createPhysicalSessionTools
5
+ } from "@cuylabs/physical-agent-core";
6
+ import { CapxSession } from "@cuylabs/physical-capx";
7
+ import { z } from "zod";
8
+ function createCapxPhysicalTools(session, options = {}) {
9
+ const tools = createPhysicalSessionTools(session, {
10
+ prefix: "capx",
11
+ ...options
12
+ });
13
+ if (session instanceof CapxSession && session.options.policyExecutionMode === "live-runtime") {
14
+ tools.push(createCapxTurnHistoryTool(session, options));
15
+ }
16
+ return tools;
17
+ }
18
+ function capxToolName(name, options) {
19
+ return `${options?.prefix ?? "capx"}_${name}`;
20
+ }
21
+ function createCapxTurnHistoryTool(session, options) {
22
+ return Tool.define(
23
+ capxToolName("turn_history", options),
24
+ {
25
+ description: "List policy-code turns executed through the live CaP-X runtime session.",
26
+ parameters: z.object({}),
27
+ capabilities: {
28
+ parallelSafe: true,
29
+ readOnly: true,
30
+ riskLevel: "safe"
31
+ },
32
+ execute: async () => {
33
+ const turns = await session.getRuntimeTurnHistory();
34
+ return {
35
+ title: "CaP-X Turn History",
36
+ output: turns.length === 0 ? "No CaP-X runtime turns have executed yet." : `${turns.length} CaP-X runtime turn(s).`,
37
+ metadata: {
38
+ physical: {
39
+ sessionId: session.id
40
+ },
41
+ capx: {
42
+ turns
43
+ }
44
+ }
45
+ };
46
+ }
47
+ },
48
+ {
49
+ capabilitiesHint: {
50
+ parallelSafe: true,
51
+ readOnly: true,
52
+ riskLevel: "safe"
53
+ }
54
+ }
55
+ );
56
+ }
57
+
58
+ export {
59
+ createCapxPhysicalTools
60
+ };
61
+ //# sourceMappingURL=chunk-57TF3E2Q.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tools.ts"],"sourcesContent":["import { Tool } from \"@cuylabs/agent-core/tool\";\nimport {\n createPhysicalSessionTools,\n type PhysicalToolOptions,\n} from \"@cuylabs/physical-agent-core\";\nimport type { PhysicalSession } from \"@cuylabs/physical-core\";\nimport { CapxSession } from \"@cuylabs/physical-capx\";\nimport { z } from \"zod\";\n\nexport function createCapxPhysicalTools(\n session: PhysicalSession | CapxSession,\n options: PhysicalToolOptions = {},\n) {\n const tools = createPhysicalSessionTools(session, {\n prefix: \"capx\",\n ...options,\n });\n if (\n session instanceof CapxSession &&\n session.options.policyExecutionMode === \"live-runtime\"\n ) {\n tools.push(createCapxTurnHistoryTool(session, options));\n }\n return tools;\n}\n\nfunction capxToolName(name: string, options?: PhysicalToolOptions): string {\n return `${options?.prefix ?? \"capx\"}_${name}`;\n}\n\nfunction createCapxTurnHistoryTool(\n session: CapxSession,\n options?: PhysicalToolOptions,\n) {\n return Tool.define(\n capxToolName(\"turn_history\", options),\n {\n description:\n \"List policy-code turns executed through the live CaP-X runtime session.\",\n parameters: z.object({}),\n capabilities: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n execute: async () => {\n const turns = await session.getRuntimeTurnHistory();\n return {\n title: \"CaP-X Turn History\",\n output:\n turns.length === 0\n ? \"No CaP-X runtime turns have executed yet.\"\n : `${turns.length} CaP-X runtime turn(s).`,\n metadata: {\n physical: {\n sessionId: session.id,\n },\n capx: {\n turns,\n },\n },\n };\n },\n },\n {\n capabilitiesHint: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n },\n );\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,OAEK;AAEP,SAAS,mBAAmB;AAC5B,SAAS,SAAS;AAEX,SAAS,wBACd,SACA,UAA+B,CAAC,GAChC;AACA,QAAM,QAAQ,2BAA2B,SAAS;AAAA,IAChD,QAAQ;AAAA,IACR,GAAG;AAAA,EACL,CAAC;AACD,MACE,mBAAmB,eACnB,QAAQ,QAAQ,wBAAwB,gBACxC;AACA,UAAM,KAAK,0BAA0B,SAAS,OAAO,CAAC;AAAA,EACxD;AACA,SAAO;AACT;AAEA,SAAS,aAAa,MAAc,SAAuC;AACzE,SAAO,GAAG,SAAS,UAAU,MAAM,IAAI,IAAI;AAC7C;AAEA,SAAS,0BACP,SACA,SACA;AACA,SAAO,KAAK;AAAA,IACV,aAAa,gBAAgB,OAAO;AAAA,IACpC;AAAA,MACE,aACE;AAAA,MACF,YAAY,EAAE,OAAO,CAAC,CAAC;AAAA,MACvB,cAAc;AAAA,QACZ,cAAc;AAAA,QACd,UAAU;AAAA,QACV,WAAW;AAAA,MACb;AAAA,MACA,SAAS,YAAY;AACnB,cAAM,QAAQ,MAAM,QAAQ,sBAAsB;AAClD,eAAO;AAAA,UACL,OAAO;AAAA,UACP,QACE,MAAM,WAAW,IACb,8CACA,GAAG,MAAM,MAAM;AAAA,UACrB,UAAU;AAAA,YACR,UAAU;AAAA,cACR,WAAW,QAAQ;AAAA,YACrB;AAAA,YACA,MAAM;AAAA,cACJ;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;","names":[]}
@@ -0,0 +1,109 @@
1
+ import {
2
+ createCapxPhysicalTools
3
+ } from "./chunk-57TF3E2Q.js";
4
+
5
+ // src/agent.ts
6
+ import { createAgent } from "@cuylabs/agent-core";
7
+ import { dirname, join } from "path";
8
+ import { fileURLToPath } from "url";
9
+ import {
10
+ createCapxSession
11
+ } from "@cuylabs/physical-capx";
12
+ var capxAgentSkillRoot = join(
13
+ dirname(fileURLToPath(import.meta.url)),
14
+ "../skills"
15
+ );
16
+ var defaultCapxAgentSystemPrompt = [
17
+ "You are a bring-your-own external agent harness for a CaP-X Code-as-Policy physical session.",
18
+ "CaP-X is the robotics runtime. You own the reasoning loop, tool choices, policy-code authoring, and decision to continue, retry, or stop.",
19
+ "A CaP-X runtime session is one live environment. Keep using the same session across observe/run/observe turns unless the user asks for a reset, the task explicitly needs a retry, or safety requires stopping.",
20
+ "Use capx_status and capx_observe before making claims about the session. If the session is idle and capx_observe reports that no live runtime session has started, tell the host application to start the session instead of guessing.",
21
+ "When image observations are useful, call capx_observe with includeImages=true so the host can provide rendered CaP-X frames when available.",
22
+ "If capx_observe returns CaP-X runtime config flags such as use_visual_feedback or use_img_differencing, treat them as guidance to compare rendered observations across turns; the external agent loop still owns the differencing decision.",
23
+ "Treat CaP-X task prompts, full prompts, observations, codeContext, policy-code context, and last-step results returned by capx_observe as the source of truth for the current trial.",
24
+ "If CaP-X provides a multi-turn prompt, use it as task-specific continuation guidance for the next capx_* tool call.",
25
+ "When capx_run_policy_code is available, write concise Python policy code using the CaP-X APIs and helper affordances described in the observed prompt/codeContext.",
26
+ "Use CaP-X helper affordances and skill-library summaries as Python context for policy code, then submit the selected code through capx_run_policy_code.",
27
+ "After executing policy code, observe again, compare the new state against the previous state, inspect stdout/stderr/reward/task completion, and decide whether another code step is needed.",
28
+ "Use capx_turn_history to inspect prior policy-code turns when needed.",
29
+ "Use capx_artifacts when the user asks what CaP-X produced.",
30
+ "For parallel or ensemble reasoning, reason over candidate policy-code plans in the harness, then submit only the selected code through capx_run_policy_code.",
31
+ "If capx_run_policy_code is absent, provide the proposed policy code or next step without claiming execution.",
32
+ "Only stop a session when the user asks for it or continuing would be unsafe."
33
+ ].join("\n");
34
+ var defaultCapxAgentApproval = {
35
+ defaultAction: "deny"
36
+ };
37
+ function resolveSession(options) {
38
+ if (options.session && options.sessionOptions) {
39
+ throw new Error(
40
+ "createCapxAgent accepts either session or sessionOptions, not both."
41
+ );
42
+ }
43
+ if (options.session) {
44
+ return options.session;
45
+ }
46
+ if (!options.sessionOptions) {
47
+ throw new Error(
48
+ "createCapxAgent requires either an existing session or sessionOptions."
49
+ );
50
+ }
51
+ return createCapxSession(options.sessionOptions);
52
+ }
53
+ function withDefaultCapxSkill(prompt, includeDefaultSkill) {
54
+ if (!includeDefaultSkill) {
55
+ return prompt;
56
+ }
57
+ const roots = prompt?.skills?.roots ?? [];
58
+ return {
59
+ ...prompt,
60
+ skills: {
61
+ ...prompt?.skills,
62
+ roots: roots.includes(capxAgentSkillRoot) ? roots : [...roots, capxAgentSkillRoot]
63
+ }
64
+ };
65
+ }
66
+ async function createCapxAgent(options) {
67
+ const {
68
+ session: _session,
69
+ sessionOptions: _sessionOptions,
70
+ startSession = false,
71
+ startOptions,
72
+ toolPrefix = "capx",
73
+ tools = [],
74
+ name = "capx-physical-agent",
75
+ systemPrompt = defaultCapxAgentSystemPrompt,
76
+ includeDefaultSkill = true,
77
+ approval,
78
+ prompt,
79
+ toolExecutionMode,
80
+ ...agentOptions
81
+ } = options;
82
+ const session = resolveSession(options);
83
+ if (startSession) {
84
+ await session.start(startOptions);
85
+ }
86
+ const capxTools = createCapxPhysicalTools(session, { prefix: toolPrefix });
87
+ const agent = createAgent({
88
+ ...agentOptions,
89
+ name,
90
+ systemPrompt,
91
+ tools: [...capxTools, ...tools],
92
+ prompt: withDefaultCapxSkill(prompt, includeDefaultSkill),
93
+ toolExecutionMode: toolExecutionMode ?? "plan",
94
+ approval: approval ?? { ...defaultCapxAgentApproval }
95
+ });
96
+ return {
97
+ agent,
98
+ session,
99
+ tools: capxTools
100
+ };
101
+ }
102
+
103
+ export {
104
+ capxAgentSkillRoot,
105
+ defaultCapxAgentSystemPrompt,
106
+ defaultCapxAgentApproval,
107
+ createCapxAgent
108
+ };
109
+ //# sourceMappingURL=chunk-U6REPGPH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/agent.ts"],"sourcesContent":["import { createAgent, type Agent } from \"@cuylabs/agent-core\";\nimport type { PhysicalSessionStartOptions } from \"@cuylabs/physical-core\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n CapxSession,\n createCapxSession,\n type CapxSessionOptions,\n} from \"@cuylabs/physical-capx\";\nimport { createCapxPhysicalTools } from \"./tools.js\";\n\ntype AgentConstructionConfig = Parameters<typeof createAgent>[0];\n\nexport const capxAgentSkillRoot = join(\n dirname(fileURLToPath(import.meta.url)),\n \"../skills\",\n);\n\nexport const defaultCapxAgentSystemPrompt = [\n \"You are a bring-your-own external agent harness for a CaP-X Code-as-Policy physical session.\",\n \"CaP-X is the robotics runtime. You own the reasoning loop, tool choices, policy-code authoring, and decision to continue, retry, or stop.\",\n \"A CaP-X runtime session is one live environment. Keep using the same session across observe/run/observe turns unless the user asks for a reset, the task explicitly needs a retry, or safety requires stopping.\",\n \"Use capx_status and capx_observe before making claims about the session. If the session is idle and capx_observe reports that no live runtime session has started, tell the host application to start the session instead of guessing.\",\n \"When image observations are useful, call capx_observe with includeImages=true so the host can provide rendered CaP-X frames when available.\",\n \"If capx_observe returns CaP-X runtime config flags such as use_visual_feedback or use_img_differencing, treat them as guidance to compare rendered observations across turns; the external agent loop still owns the differencing decision.\",\n \"Treat CaP-X task prompts, full prompts, observations, codeContext, policy-code context, and last-step results returned by capx_observe as the source of truth for the current trial.\",\n \"If CaP-X provides a multi-turn prompt, use it as task-specific continuation guidance for the next capx_* tool call.\",\n \"When capx_run_policy_code is available, write concise Python policy code using the CaP-X APIs and helper affordances described in the observed prompt/codeContext.\",\n \"Use CaP-X helper affordances and skill-library summaries as Python context for policy code, then submit the selected code through capx_run_policy_code.\",\n \"After executing policy code, observe again, compare the new state against the previous state, inspect stdout/stderr/reward/task completion, and decide whether another code step is needed.\",\n \"Use capx_turn_history to inspect prior policy-code turns when needed.\",\n \"Use capx_artifacts when the user asks what CaP-X produced.\",\n \"For parallel or ensemble reasoning, reason over candidate policy-code plans in the harness, then submit only the selected code through capx_run_policy_code.\",\n \"If capx_run_policy_code is absent, provide the proposed policy code or next step without claiming execution.\",\n \"Only stop a session when the user asks for it or continuing would be unsafe.\",\n].join(\"\\n\");\n\nexport const defaultCapxAgentApproval: NonNullable<\n AgentConstructionConfig[\"approval\"]\n> = {\n defaultAction: \"deny\",\n};\n\nexport interface CreateCapxAgentOptions extends Omit<\n AgentConstructionConfig,\n \"name\" | \"systemPrompt\" | \"tools\"\n> {\n /**\n * Existing CaP-X session. Use this when another owner creates the session.\n */\n session?: CapxSession;\n /**\n * Options used to create a CaP-X session. Required when session is omitted.\n */\n sessionOptions?: CapxSessionOptions;\n /**\n * Start the CaP-X session before returning. Defaults to false because\n * creating a live runtime session is an external side effect.\n */\n startSession?: boolean;\n /**\n * Optional task metadata for session.start().\n */\n startOptions?: PhysicalSessionStartOptions;\n /**\n * Prefix for generated CaP-X tools. Defaults to \"capx\".\n */\n toolPrefix?: string;\n /**\n * Extra app-specific tools to expose alongside the CaP-X tools.\n */\n tools?: AgentConstructionConfig[\"tools\"];\n /**\n * Agent name. Defaults to \"capx-physical-agent\".\n */\n name?: string;\n /**\n * System prompt. Defaults to a CaP-X supervision prompt.\n */\n systemPrompt?: string;\n /**\n * Include the packaged agent-core skill that teaches the agent how to use\n * CaP-X runtime tools. Defaults to true.\n */\n includeDefaultSkill?: boolean;\n}\n\nexport interface CapxAgent {\n agent: Agent;\n session: CapxSession;\n tools: ReturnType<typeof createCapxPhysicalTools>;\n}\n\nfunction resolveSession(options: CreateCapxAgentOptions): CapxSession {\n if (options.session && options.sessionOptions) {\n throw new Error(\n \"createCapxAgent accepts either session or sessionOptions, not both.\",\n );\n }\n if (options.session) {\n return options.session;\n }\n if (!options.sessionOptions) {\n throw new Error(\n \"createCapxAgent requires either an existing session or sessionOptions.\",\n );\n }\n return createCapxSession(options.sessionOptions);\n}\n\nfunction withDefaultCapxSkill(\n prompt: AgentConstructionConfig[\"prompt\"],\n includeDefaultSkill: boolean,\n): AgentConstructionConfig[\"prompt\"] {\n if (!includeDefaultSkill) {\n return prompt;\n }\n\n const roots = prompt?.skills?.roots ?? [];\n return {\n ...prompt,\n skills: {\n ...prompt?.skills,\n roots: roots.includes(capxAgentSkillRoot)\n ? roots\n : [...roots, capxAgentSkillRoot],\n },\n };\n}\n\nexport async function createCapxAgent(\n options: CreateCapxAgentOptions,\n): Promise<CapxAgent> {\n const {\n session: _session,\n sessionOptions: _sessionOptions,\n startSession = false,\n startOptions,\n toolPrefix = \"capx\",\n tools = [],\n name = \"capx-physical-agent\",\n systemPrompt = defaultCapxAgentSystemPrompt,\n includeDefaultSkill = true,\n approval,\n prompt,\n toolExecutionMode,\n ...agentOptions\n } = options;\n const session = resolveSession(options);\n\n if (startSession) {\n await session.start(startOptions);\n }\n\n const capxTools = createCapxPhysicalTools(session, { prefix: toolPrefix });\n const agent = createAgent({\n ...agentOptions,\n name,\n systemPrompt,\n tools: [...capxTools, ...tools],\n prompt: withDefaultCapxSkill(prompt, includeDefaultSkill),\n toolExecutionMode: toolExecutionMode ?? \"plan\",\n approval: approval ?? { ...defaultCapxAgentApproval },\n });\n\n return {\n agent,\n session,\n tools: capxTools,\n };\n}\n"],"mappings":";;;;;AAAA,SAAS,mBAA+B;AAExC,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAC9B;AAAA,EAEE;AAAA,OAEK;AAKA,IAAM,qBAAqB;AAAA,EAChC,QAAQ,cAAc,YAAY,GAAG,CAAC;AAAA,EACtC;AACF;AAEO,IAAM,+BAA+B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EAAE,KAAK,IAAI;AAEJ,IAAM,2BAET;AAAA,EACF,eAAe;AACjB;AAoDA,SAAS,eAAe,SAA8C;AACpE,MAAI,QAAQ,WAAW,QAAQ,gBAAgB;AAC7C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,MAAI,QAAQ,SAAS;AACnB,WAAO,QAAQ;AAAA,EACjB;AACA,MAAI,CAAC,QAAQ,gBAAgB;AAC3B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,kBAAkB,QAAQ,cAAc;AACjD;AAEA,SAAS,qBACP,QACA,qBACmC;AACnC,MAAI,CAAC,qBAAqB;AACxB,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,QAAQ,QAAQ,SAAS,CAAC;AACxC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ;AAAA,MACN,GAAG,QAAQ;AAAA,MACX,OAAO,MAAM,SAAS,kBAAkB,IACpC,QACA,CAAC,GAAG,OAAO,kBAAkB;AAAA,IACnC;AAAA,EACF;AACF;AAEA,eAAsB,gBACpB,SACoB;AACpB,QAAM;AAAA,IACJ,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf;AAAA,IACA,aAAa;AAAA,IACb,QAAQ,CAAC;AAAA,IACT,OAAO;AAAA,IACP,eAAe;AAAA,IACf,sBAAsB;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,UAAU,eAAe,OAAO;AAEtC,MAAI,cAAc;AAChB,UAAM,QAAQ,MAAM,YAAY;AAAA,EAClC;AAEA,QAAM,YAAY,wBAAwB,SAAS,EAAE,QAAQ,WAAW,CAAC;AACzE,QAAM,QAAQ,YAAY;AAAA,IACxB,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,OAAO,CAAC,GAAG,WAAW,GAAG,KAAK;AAAA,IAC9B,QAAQ,qBAAqB,QAAQ,mBAAmB;AAAA,IACxD,mBAAmB,qBAAqB;AAAA,IACxC,UAAU,YAAY,EAAE,GAAG,yBAAyB;AAAA,EACtD,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,7 @@
1
+ export { CapxAgent, CreateCapxAgentOptions, capxAgentSkillRoot, createCapxAgent, defaultCapxAgentApproval, defaultCapxAgentSystemPrompt } from './agent.js';
2
+ export { CapxArtifactDiscoveryOptions, CapxLiveRuntime, CapxPolicyExecutionMode, CapxRunMode, CapxSession, CapxSessionOptions, RuntimeCodeAffordance, RuntimeCodeContext, RuntimeExecutionResult, RuntimeFrame, RuntimeObservation, RuntimeSkillExtraction, RuntimeSkillInjection, RuntimeSkillLibrary, RuntimeTurn, createCapxSession, discoverCapxArtifacts } from '@cuylabs/physical-capx';
3
+ export { createCapxPhysicalTools } from './tools.js';
4
+ import '@cuylabs/agent-core';
5
+ import '@cuylabs/physical-core';
6
+ import '@cuylabs/agent-core/tool';
7
+ import '@cuylabs/physical-agent-core';
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ import {
2
+ capxAgentSkillRoot,
3
+ createCapxAgent,
4
+ defaultCapxAgentApproval,
5
+ defaultCapxAgentSystemPrompt
6
+ } from "./chunk-U6REPGPH.js";
7
+ import {
8
+ createCapxPhysicalTools
9
+ } from "./chunk-57TF3E2Q.js";
10
+
11
+ // src/index.ts
12
+ import {
13
+ discoverCapxArtifacts,
14
+ CapxLiveRuntime,
15
+ CapxSession,
16
+ createCapxSession
17
+ } from "@cuylabs/physical-capx";
18
+ export {
19
+ CapxLiveRuntime,
20
+ CapxSession,
21
+ capxAgentSkillRoot,
22
+ createCapxAgent,
23
+ createCapxPhysicalTools,
24
+ createCapxSession,
25
+ defaultCapxAgentApproval,
26
+ defaultCapxAgentSystemPrompt,
27
+ discoverCapxArtifacts
28
+ };
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n capxAgentSkillRoot,\n createCapxAgent,\n defaultCapxAgentApproval,\n defaultCapxAgentSystemPrompt,\n type CapxAgent,\n type CreateCapxAgentOptions,\n} from \"./agent.js\";\nexport {\n discoverCapxArtifacts,\n CapxLiveRuntime,\n CapxSession,\n createCapxSession,\n type RuntimeCodeAffordance,\n type RuntimeCodeContext,\n type RuntimeExecutionResult,\n type RuntimeFrame,\n type RuntimeObservation,\n type RuntimeSkillExtraction,\n type RuntimeSkillInjection,\n type RuntimeSkillLibrary,\n type RuntimeTurn,\n} from \"@cuylabs/physical-capx\";\nexport { createCapxPhysicalTools } from \"./tools.js\";\nexport type {\n CapxArtifactDiscoveryOptions,\n CapxPolicyExecutionMode,\n CapxRunMode,\n CapxSessionOptions,\n} from \"@cuylabs/physical-capx\";\n"],"mappings":";;;;;;;;;;;AAQA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAUK;","names":[]}
@@ -0,0 +1,5 @@
1
+ export { CapxSession, CapxSessionOptions, createCapxSession } from '@cuylabs/physical-capx';
2
+ export { createCapxPhysicalTools } from './tools.js';
3
+ import '@cuylabs/agent-core/tool';
4
+ import '@cuylabs/physical-agent-core';
5
+ import '@cuylabs/physical-core';