@orchagent/cli 0.3.68 → 0.3.70

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.
@@ -15,7 +15,12 @@ const errors_1 = require("../lib/errors");
15
15
  async function resolveAgentId(config, ref) {
16
16
  const parts = ref.split('/');
17
17
  const agentName = parts.length >= 2 ? parts[1] : parts[0];
18
- const agents = await (0, api_1.listMyAgents)(config);
18
+ const orgSlug = parts.length >= 2 ? parts[0] : undefined;
19
+ // Resolve workspace context from org slug or config
20
+ const configFile = await (0, config_1.loadConfig)();
21
+ const resolvedOrg = orgSlug ?? configFile.workspace ?? config.defaultOrg;
22
+ const workspaceId = resolvedOrg ? await (0, api_1.resolveWorkspaceIdForOrg)(config, resolvedOrg) : undefined;
23
+ const agents = await (0, api_1.listMyAgents)(config, workspaceId);
19
24
  const matching = agents.filter(a => a.name === agentName);
20
25
  if (matching.length === 0) {
21
26
  throw new errors_1.CliError(`Agent '${ref}' not found. Run 'orchagent agents' to list your agents.`);
@@ -49,7 +49,11 @@ function registerAgentsCommand(program) {
49
49
  .option('--json', 'Output raw JSON')
50
50
  .action(async (options) => {
51
51
  const config = await (0, config_1.getResolvedConfig)();
52
- const agents = await (0, api_1.listMyAgents)(config);
52
+ // Resolve workspace context
53
+ const configFile = await (0, config_1.loadConfig)();
54
+ const orgSlug = configFile.workspace ?? config.defaultOrg;
55
+ const workspaceId = orgSlug ? await (0, api_1.resolveWorkspaceIdForOrg)(config, orgSlug) : undefined;
56
+ const agents = await (0, api_1.listMyAgents)(config, workspaceId);
53
57
  // Apply filter if provided
54
58
  const filteredAgents = options.filter
55
59
  ? agents.filter(a => a.name.toLowerCase().includes(options.filter.toLowerCase()))
@@ -42,9 +42,11 @@ Examples:
42
42
  if (!config.apiKey) {
43
43
  throw new errors_1.CliError('Not logged in. Run `orchagent login` first.');
44
44
  }
45
+ // Resolve workspace context for the target org
46
+ const workspaceId = await (0, api_1.resolveWorkspaceIdForOrg)(config, ref.org);
45
47
  process.stdout.write('Finding agent...\n');
46
48
  // Find the agent by name, filtering by org if provided
47
- const agents = await (0, api_1.listMyAgents)(config);
49
+ const agents = await (0, api_1.listMyAgents)(config, workspaceId);
48
50
  const matching = agents.filter(a => a.name === ref.agent && (!a.org_slug || a.org_slug === ref.org));
49
51
  if (matching.length === 0) {
50
52
  throw new errors_1.CliError(`Agent '${ref.org}/${ref.agent}' not found`);
@@ -49,7 +49,7 @@ async function fetchReadme(url) {
49
49
  return null;
50
50
  }
51
51
  }
52
- async function getAgentInfo(config, org, agent, version) {
52
+ async function getAgentInfo(config, org, agent, version, workspaceId) {
53
53
  // Use public metadata endpoint as primary source — never blocked by download restrictions
54
54
  try {
55
55
  const publicMeta = await (0, api_1.getPublicAgent)(config, org, agent, version);
@@ -78,11 +78,11 @@ async function getAgentInfo(config, org, agent, version) {
78
78
  if (!config.apiKey) {
79
79
  throw new api_1.ApiError(`Agent '${org}/${agent}@${version}' not found`, 404);
80
80
  }
81
- const userOrg = await (0, api_1.getOrg)(config);
81
+ const userOrg = await (0, api_1.getOrg)(config, workspaceId);
82
82
  if (userOrg.slug !== org) {
83
83
  throw new api_1.ApiError(`Agent '${org}/${agent}@${version}' not found`, 404);
84
84
  }
85
- const agents = await (0, api_1.listMyAgents)(config);
85
+ const agents = await (0, api_1.listMyAgents)(config, workspaceId);
86
86
  const matching = agents.filter(a => a.name === agent);
87
87
  if (matching.length === 0) {
88
88
  throw new api_1.ApiError(`Agent '${org}/${agent}@${version}' not found`, 404);
@@ -123,8 +123,10 @@ function registerInfoCommand(program) {
123
123
  .action(async (agentArg, options) => {
124
124
  const config = await (0, config_1.getResolvedConfig)();
125
125
  const { org, agent, version } = (0, agent_ref_1.parseAgentRef)(agentArg);
126
+ // Resolve workspace context for the target org
127
+ const workspaceId = await (0, api_1.resolveWorkspaceIdForOrg)(config, org);
126
128
  // Fetch agent metadata
127
- const agentData = await getAgentInfo(config, org, agent, version);
129
+ const agentData = await getAgentInfo(config, org, agent, version, workspaceId);
128
130
  if (options.json) {
129
131
  // Don't expose internal routing URLs in JSON output
130
132
  const output = { ...agentData };
@@ -29,7 +29,7 @@ function parseAgentRef(value) {
29
29
  }
30
30
  throw new errors_1.CliError('Invalid agent reference. Use org/agent or agent format.');
31
31
  }
32
- async function downloadAgentWithFallback(config, org, name, version) {
32
+ async function downloadAgentWithFallback(config, org, name, version, workspaceId) {
33
33
  // Fetch public metadata first to check if paid
34
34
  let publicMeta;
35
35
  try {
@@ -48,12 +48,12 @@ async function downloadAgentWithFallback(config, org, name, version) {
48
48
  if (publicMeta && (0, pricing_1.isPaidAgent)(publicMeta)) {
49
49
  // Paid agent - check if owner
50
50
  if (config.apiKey) {
51
- const callerOrg = await (0, api_1.getOrg)(config);
51
+ const callerOrg = await (0, api_1.getOrg)(config, workspaceId);
52
52
  const isOwner = (publicMeta.org_id && callerOrg.id === publicMeta.org_id) ||
53
53
  (publicMeta.org_slug && callerOrg.slug === publicMeta.org_slug);
54
54
  if (isOwner) {
55
55
  // Owner - fetch from authenticated endpoint with full prompt
56
- const myAgents = await (0, api_1.listMyAgents)(config);
56
+ const myAgents = await (0, api_1.listMyAgents)(config, workspaceId);
57
57
  const matching = myAgents.filter(a => a.name === name);
58
58
  if (matching.length > 0) {
59
59
  let targetAgent;
@@ -90,12 +90,12 @@ async function downloadAgentWithFallback(config, org, name, version) {
90
90
  if (publicMeta && publicMeta.allow_local_download === false) {
91
91
  // Check if owner (can bypass)
92
92
  if (config.apiKey) {
93
- const callerOrg = await (0, api_1.getOrg)(config);
93
+ const callerOrg = await (0, api_1.getOrg)(config, workspaceId);
94
94
  const isOwner = (publicMeta.org_id && callerOrg.id === publicMeta.org_id) ||
95
95
  (publicMeta.org_slug && callerOrg.slug === publicMeta.org_slug);
96
96
  if (isOwner) {
97
97
  // Owner - fetch from authenticated endpoint
98
- const myAgents = await (0, api_1.listMyAgents)(config);
98
+ const myAgents = await (0, api_1.listMyAgents)(config, workspaceId);
99
99
  const matching = myAgents.filter(a => a.name === name);
100
100
  if (matching.length > 0) {
101
101
  let targetAgent;
@@ -128,11 +128,11 @@ async function downloadAgentWithFallback(config, org, name, version) {
128
128
  if (!config.apiKey) {
129
129
  throw new api_1.ApiError(`Agent '${org}/${name}@${version}' not found`, 404);
130
130
  }
131
- const userOrg = await (0, api_1.getOrg)(config);
131
+ const userOrg = await (0, api_1.getOrg)(config, workspaceId);
132
132
  if (userOrg.slug !== org) {
133
133
  throw new api_1.ApiError(`Agent '${org}/${name}@${version}' not found`, 404);
134
134
  }
135
- const agents = await (0, api_1.listMyAgents)(config);
135
+ const agents = await (0, api_1.listMyAgents)(config, workspaceId);
136
136
  const matching = agents.filter(a => a.name === name);
137
137
  if (matching.length === 0) {
138
138
  throw new api_1.ApiError(`Agent '${org}/${name}@${version}' not found`, 404);
@@ -232,11 +232,13 @@ Note: Paid agents cannot be installed locally - they run on server only.
232
232
  throw new errors_1.CliError(errMsg);
233
233
  }
234
234
  result.scope = scope;
235
+ // Resolve workspace context for the target org
236
+ const workspaceId = await (0, api_1.resolveWorkspaceIdForOrg)(resolved, org);
235
237
  // Download agent
236
238
  log(`Fetching ${org}/${parsed.name}@${parsed.version}...\n`);
237
239
  let agent;
238
240
  try {
239
- agent = await downloadAgentWithFallback(resolved, org, parsed.name, parsed.version);
241
+ agent = await downloadAgentWithFallback(resolved, org, parsed.name, parsed.version, workspaceId);
240
242
  }
241
243
  catch (err) {
242
244
  if (jsonMode) {
@@ -58,7 +58,7 @@ function commandForEntrypoint(entrypoint) {
58
58
  return `python ${entrypoint}`;
59
59
  }
60
60
  // ─── Agent Resolution ───────────────────────────────────────────────────────
61
- async function resolveAgent(config, org, agent, version) {
61
+ async function resolveAgent(config, org, agent, version, workspaceId) {
62
62
  // 1. Try public download endpoint
63
63
  try {
64
64
  const data = await (0, api_1.publicRequest)(config, `/public/agents/${org}/${agent}/${version}/download`);
@@ -96,7 +96,7 @@ async function resolveAgent(config, org, agent, version) {
96
96
  if (errorCode === 'PAID_AGENT_SERVER_ONLY' || errorCode === 'DOWNLOAD_DISABLED') {
97
97
  // Try authenticated owner path
98
98
  if (config.apiKey) {
99
- const ownerData = await tryOwnerFallback(config, org, agent, version);
99
+ const ownerData = await tryOwnerFallback(config, org, agent, version, workspaceId);
100
100
  if (ownerData)
101
101
  return { ...ownerData, source: 'owner_authenticated' };
102
102
  }
@@ -117,19 +117,19 @@ async function resolveAgent(config, org, agent, version) {
117
117
  if (!config.apiKey) {
118
118
  throw new api_1.ApiError(`Agent '${org}/${agent}@${version}' not found`, 404);
119
119
  }
120
- const userOrg = await (0, api_1.getOrg)(config);
120
+ const userOrg = await (0, api_1.getOrg)(config, workspaceId);
121
121
  if (userOrg.slug !== org) {
122
122
  throw new api_1.ApiError(`Agent '${org}/${agent}@${version}' not found`, 404);
123
123
  }
124
- const data = await resolveFromMyAgents(config, agent, version, org);
124
+ const data = await resolveFromMyAgents(config, agent, version, org, workspaceId);
125
125
  if (!data) {
126
126
  throw new api_1.ApiError(`Agent '${org}/${agent}@${version}' not found`, 404);
127
127
  }
128
128
  return { ...data, source: 'private_authenticated' };
129
129
  }
130
- async function tryOwnerFallback(config, org, agent, version) {
130
+ async function tryOwnerFallback(config, org, agent, version, workspaceId) {
131
131
  try {
132
- const myAgents = await (0, api_1.listMyAgents)(config);
132
+ const myAgents = await (0, api_1.listMyAgents)(config, workspaceId);
133
133
  let match;
134
134
  if (version === 'latest') {
135
135
  match = myAgents
@@ -148,8 +148,8 @@ async function tryOwnerFallback(config, org, agent, version) {
148
148
  return null;
149
149
  }
150
150
  }
151
- async function resolveFromMyAgents(config, agent, version, org) {
152
- const agents = await (0, api_1.listMyAgents)(config);
151
+ async function resolveFromMyAgents(config, agent, version, org, workspaceId) {
152
+ const agents = await (0, api_1.listMyAgents)(config, workspaceId);
153
153
  const matching = agents.filter(a => a.name === agent && a.org_slug === org);
154
154
  if (matching.length === 0)
155
155
  return null;
@@ -361,9 +361,11 @@ Examples:
361
361
  throw new errors_1.CliError('Missing org. Use org/agent[@version] format, or set a default org with:\n' +
362
362
  ' orch config set default-org <org>');
363
363
  }
364
+ // Resolve workspace context for the target org
365
+ const workspaceId = await (0, api_1.resolveWorkspaceIdForOrg)(config, org);
364
366
  write(`Resolving ${org}/${parsed.agent}@${parsed.version}...\n`);
365
367
  // Resolve agent data
366
- const data = await resolveAgent(config, org, parsed.agent, parsed.version);
368
+ const data = await resolveAgent(config, org, parsed.agent, parsed.version, workspaceId);
367
369
  // Reject skills
368
370
  if (canonicalType(data.type) === 'skill') {
369
371
  throw new errors_1.CliError("This is a skill. Use 'orch skill install <ref>' instead.");
@@ -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
- const agentMeta = await (0, api_1.getAgentWithFallback)(resolved, org, parsed.agent, parsed.version);
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
- const wsSlug = configFile.workspace;
1634
- if (wsSlug) {
1635
- const { workspaces } = await (0, api_1.request)(resolved, 'GET', '/workspaces');
1636
- const ws = workspaces.find((w) => w.slug === wsSlug);
1637
- if (ws) {
1638
- const secretsResult = await (0, api_1.request)(resolved, 'GET', `/workspaces/${ws.id}/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 '${wsSlug}':\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`);
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) {
@@ -88,7 +88,7 @@ function parseSkillRef(value) {
88
88
  }
89
89
  throw new errors_1.CliError('Invalid skill reference. Use org/skill or skill format.');
90
90
  }
91
- async function downloadSkillWithFallback(config, org, skill, version) {
91
+ async function downloadSkillWithFallback(config, org, skill, version, workspaceId) {
92
92
  // Fetch metadata first to check if paid
93
93
  let skillMeta;
94
94
  try {
@@ -114,12 +114,12 @@ async function downloadSkillWithFallback(config, org, skill, version) {
114
114
  if (skillMeta && (0, pricing_1.isPaidAgent)(skillMeta)) {
115
115
  // Paid skill - check ownership
116
116
  if (config.apiKey) {
117
- const callerOrg = await (0, api_1.getOrg)(config);
117
+ const callerOrg = await (0, api_1.getOrg)(config, workspaceId);
118
118
  const isOwner = (skillMeta.org_id && callerOrg.id === skillMeta.org_id) ||
119
119
  (skillMeta.org_slug && callerOrg.slug === skillMeta.org_slug);
120
120
  if (isOwner) {
121
121
  // Owner - fetch from authenticated endpoint with full content
122
- const myAgents = await (0, api_1.listMyAgents)(config);
122
+ const myAgents = await (0, api_1.listMyAgents)(config, workspaceId);
123
123
  const matching = myAgents.filter(a => a.name === skill && a.type === 'skill');
124
124
  if (matching.length > 0) {
125
125
  let targetAgent;
@@ -162,12 +162,12 @@ async function downloadSkillWithFallback(config, org, skill, version) {
162
162
  // Check if download is disabled (server-only skill)
163
163
  if (skillMeta && skillMeta.allow_local_download === false) {
164
164
  if (config.apiKey) {
165
- const callerOrg = await (0, api_1.getOrg)(config);
165
+ const callerOrg = await (0, api_1.getOrg)(config, workspaceId);
166
166
  const isOwner = (skillMeta.org_id && callerOrg.id === skillMeta.org_id) ||
167
167
  (skillMeta.org_slug && callerOrg.slug === skillMeta.org_slug);
168
168
  if (isOwner) {
169
169
  // Owner - fetch from authenticated endpoint
170
- const myAgents = await (0, api_1.listMyAgents)(config);
170
+ const myAgents = await (0, api_1.listMyAgents)(config, workspaceId);
171
171
  const matching = myAgents.filter(a => a.name === skill && a.type === 'skill');
172
172
  if (matching.length > 0) {
173
173
  let targetAgent;
@@ -221,12 +221,12 @@ async function downloadSkillWithFallback(config, org, skill, version) {
221
221
  if (!config.apiKey) {
222
222
  throw new api_1.ApiError(`Skill '${org}/${skill}@${version}' not found`, 404);
223
223
  }
224
- const userOrg = await (0, api_1.getOrg)(config);
224
+ const userOrg = await (0, api_1.getOrg)(config, workspaceId);
225
225
  if (userOrg.slug !== org) {
226
226
  throw new api_1.ApiError(`Skill '${org}/${skill}@${version}' not found`, 404);
227
227
  }
228
228
  // Find skill in user's list
229
- const agents = await (0, api_1.listMyAgents)(config);
229
+ const agents = await (0, api_1.listMyAgents)(config, workspaceId);
230
230
  const matching = agents.filter(a => a.name === skill && a.type === 'skill');
231
231
  if (matching.length === 0) {
232
232
  throw new api_1.ApiError(`Skill '${org}/${skill}@${version}' not found`, 404);
@@ -420,10 +420,12 @@ Instructions and guidance for AI agents...
420
420
  }
421
421
  result.skill = `${org}/${parsed.skill}`;
422
422
  result.version = parsed.version;
423
+ // Resolve workspace context for the target org
424
+ const workspaceId = await (0, api_1.resolveWorkspaceIdForOrg)(resolved, org);
423
425
  // Download skill (tries public first, falls back to authenticated for private)
424
426
  let skillData;
425
427
  try {
426
- skillData = await downloadSkillWithFallback(resolved, org, parsed.skill, parsed.version);
428
+ skillData = await downloadSkillWithFallback(resolved, org, parsed.skill, parsed.version, workspaceId);
427
429
  }
428
430
  catch (err) {
429
431
  if (jsonMode) {
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
- return request(config, 'GET', '/agents');
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orchagent/cli",
3
- "version": "0.3.68",
3
+ "version": "0.3.70",
4
4
  "description": "Command-line interface for orchagent — deploy and run AI agents for your team",
5
5
  "license": "MIT",
6
6
  "author": "orchagent <hello@orchagent.io>",