@orchagent/cli 0.3.68 → 0.3.69
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/dist/commands/run.js +27 -23
- package/dist/commands/schedule.js +2 -2
- package/dist/lib/api.js +26 -7
- package/package.json +1 -1
package/dist/commands/run.js
CHANGED
|
@@ -407,7 +407,7 @@ async function buildInjectedPayload(options) {
|
|
|
407
407
|
return { body: JSON.stringify(merged), sourceLabel };
|
|
408
408
|
}
|
|
409
409
|
// ─── Local execution helpers ────────────────────────────────────────────────
|
|
410
|
-
async function downloadAgent(config, org, agent, version) {
|
|
410
|
+
async function downloadAgent(config, org, agent, version, workspaceId) {
|
|
411
411
|
// Try public endpoint first
|
|
412
412
|
try {
|
|
413
413
|
return await (0, api_1.publicRequest)(config, `/public/agents/${org}/${agent}/${version}/download`);
|
|
@@ -421,7 +421,7 @@ async function downloadAgent(config, org, agent, version) {
|
|
|
421
421
|
// Try owner path if authenticated
|
|
422
422
|
if (config.apiKey) {
|
|
423
423
|
try {
|
|
424
|
-
const myAgents = await (0, api_1.listMyAgents)(config);
|
|
424
|
+
const myAgents = await (0, api_1.listMyAgents)(config, workspaceId);
|
|
425
425
|
const matchingAgent = myAgents.find(a => a.name === agent && a.version === version && a.org_slug === org);
|
|
426
426
|
if (matchingAgent) {
|
|
427
427
|
// Owner! Fetch from authenticated endpoint
|
|
@@ -470,12 +470,12 @@ async function downloadAgent(config, org, agent, version) {
|
|
|
470
470
|
if (!config.apiKey) {
|
|
471
471
|
throw new api_1.ApiError(`Agent '${org}/${agent}@${version}' not found`, 404);
|
|
472
472
|
}
|
|
473
|
-
const userOrg = await (0, api_1.getOrg)(config);
|
|
473
|
+
const userOrg = await (0, api_1.getOrg)(config, workspaceId);
|
|
474
474
|
if (userOrg.slug !== org) {
|
|
475
475
|
throw new api_1.ApiError(`Agent '${org}/${agent}@${version}' not found`, 404);
|
|
476
476
|
}
|
|
477
477
|
// Find agent in user's list
|
|
478
|
-
const agents = await (0, api_1.listMyAgents)(config);
|
|
478
|
+
const agents = await (0, api_1.listMyAgents)(config, workspaceId);
|
|
479
479
|
const matching = agents.filter(a => a.name === agent);
|
|
480
480
|
if (matching.length === 0) {
|
|
481
481
|
throw new api_1.ApiError(`Agent '${org}/${agent}@${version}' not found`, 404);
|
|
@@ -1616,7 +1616,9 @@ async function executeCloud(agentRef, file, options) {
|
|
|
1616
1616
|
if (!org) {
|
|
1617
1617
|
throw new errors_1.CliError('Missing org. Use org/agent or set default org.');
|
|
1618
1618
|
}
|
|
1619
|
-
|
|
1619
|
+
// Resolve workspace context for the target org
|
|
1620
|
+
const workspaceId = await (0, api_1.resolveWorkspaceIdForOrg)(resolved, org);
|
|
1621
|
+
const agentMeta = await (0, api_1.getAgentWithFallback)(resolved, org, parsed.agent, parsed.version, workspaceId);
|
|
1620
1622
|
const cloudType = canonicalAgentType(agentMeta.type);
|
|
1621
1623
|
const cloudEngine = resolveExecutionEngine({
|
|
1622
1624
|
type: agentMeta.type,
|
|
@@ -1630,22 +1632,19 @@ async function executeCloud(agentRef, file, options) {
|
|
|
1630
1632
|
const agentRequiredSecrets = agentMeta.required_secrets;
|
|
1631
1633
|
if (agentRequiredSecrets?.length) {
|
|
1632
1634
|
try {
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
const
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
`Secrets are injected as environment variables into the agent sandbox.\n` +
|
|
1647
|
-
`View existing secrets: orch secrets list`);
|
|
1648
|
-
}
|
|
1635
|
+
// Use already-resolved workspaceId (or fall back to config workspace slug)
|
|
1636
|
+
const wsId = workspaceId ?? (configFile.workspace ? (await (0, api_1.resolveWorkspaceIdForOrg)(resolved, configFile.workspace)) : undefined);
|
|
1637
|
+
if (wsId) {
|
|
1638
|
+
const secretsResult = await (0, api_1.request)(resolved, 'GET', `/workspaces/${wsId}/secrets`);
|
|
1639
|
+
const existingNames = new Set(secretsResult.secrets.map((s) => s.name));
|
|
1640
|
+
const missing = agentRequiredSecrets.filter((s) => !existingNames.has(s));
|
|
1641
|
+
if (missing.length > 0) {
|
|
1642
|
+
throw new errors_1.CliError(`Agent requires secrets not found in workspace '${org}':\n` +
|
|
1643
|
+
missing.map((s) => ` - ${s}`).join('\n') + '\n\n' +
|
|
1644
|
+
`Set them before running:\n` +
|
|
1645
|
+
missing.map((s) => ` orch secrets set ${s} <value>`).join('\n') + '\n\n' +
|
|
1646
|
+
`Secrets are injected as environment variables into the agent sandbox.\n` +
|
|
1647
|
+
`View existing secrets: orch secrets list`);
|
|
1649
1648
|
}
|
|
1650
1649
|
}
|
|
1651
1650
|
}
|
|
@@ -1661,7 +1660,7 @@ async function executeCloud(agentRef, file, options) {
|
|
|
1661
1660
|
if ((0, pricing_1.isPaidAgent)(agentMeta)) {
|
|
1662
1661
|
let isOwner = false;
|
|
1663
1662
|
try {
|
|
1664
|
-
const callerOrg = await (0, api_1.getOrg)(resolved);
|
|
1663
|
+
const callerOrg = await (0, api_1.getOrg)(resolved, workspaceId);
|
|
1665
1664
|
const agentOrgId = agentMeta.org_id;
|
|
1666
1665
|
const agentOrgSlug = agentMeta.org_slug;
|
|
1667
1666
|
if (agentOrgId && callerOrg.id === agentOrgId) {
|
|
@@ -1714,6 +1713,9 @@ async function executeCloud(agentRef, file, options) {
|
|
|
1714
1713
|
'X-CLI-Version': package_json_1.default.version,
|
|
1715
1714
|
'X-OrchAgent-Client': 'cli',
|
|
1716
1715
|
};
|
|
1716
|
+
if (workspaceId) {
|
|
1717
|
+
headers['X-Workspace-Id'] = workspaceId;
|
|
1718
|
+
}
|
|
1717
1719
|
if (options.tenant) {
|
|
1718
1720
|
headers['X-OrchAgent-Tenant'] = options.tenant;
|
|
1719
1721
|
}
|
|
@@ -2299,10 +2301,12 @@ async function executeLocal(agentRef, args, options) {
|
|
|
2299
2301
|
if (!org) {
|
|
2300
2302
|
throw new errors_1.CliError('Missing org. Use org/agent format.');
|
|
2301
2303
|
}
|
|
2304
|
+
// Resolve workspace context for the target org
|
|
2305
|
+
const workspaceId = await (0, api_1.resolveWorkspaceIdForOrg)(resolved, org);
|
|
2302
2306
|
// Download agent definition with spinner
|
|
2303
2307
|
const agentData = await (0, spinner_1.withSpinner)(`Downloading ${org}/${parsed.agent}@${parsed.version}...`, async () => {
|
|
2304
2308
|
try {
|
|
2305
|
-
return await downloadAgent(resolved, org, parsed.agent, parsed.version);
|
|
2309
|
+
return await downloadAgent(resolved, org, parsed.agent, parsed.version, workspaceId);
|
|
2306
2310
|
}
|
|
2307
2311
|
catch (err) {
|
|
2308
2312
|
const agentMeta = await (0, api_1.getPublicAgent)(resolved, org, parsed.agent, parsed.version);
|
|
@@ -143,8 +143,8 @@ function registerScheduleCommand(program) {
|
|
|
143
143
|
}
|
|
144
144
|
const workspaceId = await resolveWorkspaceId(config, options.workspace);
|
|
145
145
|
const ref = (0, agent_ref_1.parseAgentRef)(agentArg);
|
|
146
|
-
// Resolve agent to get the ID
|
|
147
|
-
const agent = await (0, api_2.getAgentWithFallback)(config, ref.org, ref.agent, ref.version);
|
|
146
|
+
// Resolve agent to get the ID (pass workspace context for private agents)
|
|
147
|
+
const agent = await (0, api_2.getAgentWithFallback)(config, ref.org, ref.agent, ref.version, workspaceId);
|
|
148
148
|
// Parse input data
|
|
149
149
|
let inputData;
|
|
150
150
|
if (options.input) {
|
package/dist/lib/api.js
CHANGED
|
@@ -51,6 +51,7 @@ exports.downloadCodeBundle = downloadCodeBundle;
|
|
|
51
51
|
exports.uploadCodeBundle = uploadCodeBundle;
|
|
52
52
|
exports.getMyAgent = getMyAgent;
|
|
53
53
|
exports.getAgentWithFallback = getAgentWithFallback;
|
|
54
|
+
exports.resolveWorkspaceIdForOrg = resolveWorkspaceIdForOrg;
|
|
54
55
|
exports.downloadCodeBundleAuthenticated = downloadCodeBundleAuthenticated;
|
|
55
56
|
exports.checkAgentDelete = checkAgentDelete;
|
|
56
57
|
exports.deleteAgent = deleteAgent;
|
|
@@ -290,8 +291,11 @@ async function updateOrg(config, payload) {
|
|
|
290
291
|
async function getPublicAgent(config, org, agent, version) {
|
|
291
292
|
return publicRequest(config, `/public/agents/${org}/${agent}/${version}`);
|
|
292
293
|
}
|
|
293
|
-
async function listMyAgents(config) {
|
|
294
|
-
|
|
294
|
+
async function listMyAgents(config, workspaceId) {
|
|
295
|
+
const headers = {};
|
|
296
|
+
if (workspaceId)
|
|
297
|
+
headers['X-Workspace-Id'] = workspaceId;
|
|
298
|
+
return request(config, 'GET', '/agents', { headers });
|
|
295
299
|
}
|
|
296
300
|
async function createAgent(config, data, workspaceId) {
|
|
297
301
|
const headers = { 'Content-Type': 'application/json' };
|
|
@@ -354,8 +358,8 @@ async function uploadCodeBundle(config, agentId, bundlePath, entrypoint, workspa
|
|
|
354
358
|
/**
|
|
355
359
|
* Get single agent by name/version from authenticated endpoint.
|
|
356
360
|
*/
|
|
357
|
-
async function getMyAgent(config, agentName, version) {
|
|
358
|
-
const agents = await listMyAgents(config);
|
|
361
|
+
async function getMyAgent(config, agentName, version, workspaceId) {
|
|
362
|
+
const agents = await listMyAgents(config, workspaceId);
|
|
359
363
|
const matching = agents.filter(a => a.name === agentName);
|
|
360
364
|
if (matching.length === 0)
|
|
361
365
|
return null;
|
|
@@ -367,7 +371,7 @@ async function getMyAgent(config, agentName, version) {
|
|
|
367
371
|
/**
|
|
368
372
|
* Try public endpoint first, fallback to authenticated for private agents.
|
|
369
373
|
*/
|
|
370
|
-
async function getAgentWithFallback(config, org, agentName, version) {
|
|
374
|
+
async function getAgentWithFallback(config, org, agentName, version, workspaceId) {
|
|
371
375
|
try {
|
|
372
376
|
return await getPublicAgent(config, org, agentName, version);
|
|
373
377
|
}
|
|
@@ -378,16 +382,31 @@ async function getAgentWithFallback(config, org, agentName, version) {
|
|
|
378
382
|
if (!config.apiKey) {
|
|
379
383
|
throw new ApiError(`Agent '${org}/${agentName}@${version}' not found`, 404);
|
|
380
384
|
}
|
|
381
|
-
const userOrg = await getOrg(config);
|
|
385
|
+
const userOrg = await getOrg(config, workspaceId);
|
|
382
386
|
if (userOrg.slug !== org) {
|
|
383
387
|
throw new ApiError(`Agent '${org}/${agentName}@${version}' not found`, 404);
|
|
384
388
|
}
|
|
385
|
-
const myAgent = await getMyAgent(config, agentName, version);
|
|
389
|
+
const myAgent = await getMyAgent(config, agentName, version, workspaceId);
|
|
386
390
|
if (!myAgent) {
|
|
387
391
|
throw new ApiError(`Agent '${org}/${agentName}@${version}' not found`, 404);
|
|
388
392
|
}
|
|
389
393
|
return myAgent;
|
|
390
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* Resolve a workspace ID from an org slug.
|
|
397
|
+
* Returns undefined for personal orgs or if unauthenticated.
|
|
398
|
+
*/
|
|
399
|
+
async function resolveWorkspaceIdForOrg(config, orgSlug) {
|
|
400
|
+
if (!config.apiKey)
|
|
401
|
+
return undefined;
|
|
402
|
+
try {
|
|
403
|
+
const { workspaces } = await request(config, 'GET', '/workspaces');
|
|
404
|
+
return workspaces.find(w => w.slug === orgSlug)?.id;
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
return undefined;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
391
410
|
/**
|
|
392
411
|
* Download a tool bundle for a private agent using authenticated endpoint.
|
|
393
412
|
*/
|
package/package.json
CHANGED