@orchagent/cli 0.3.56 → 0.3.57

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.
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerForkCommand = registerForkCommand;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const config_1 = require("../lib/config");
9
+ const api_1 = require("../lib/api");
10
+ const agent_ref_1 = require("../lib/agent-ref");
11
+ const errors_1 = require("../lib/errors");
12
+ const analytics_1 = require("../lib/analytics");
13
+ const output_1 = require("../lib/output");
14
+ function getWorkspaceAuthError(err) {
15
+ if (!(err instanceof api_1.ApiError) || (err.status !== 401 && err.status !== 403)) {
16
+ return null;
17
+ }
18
+ const message = err.message.toLowerCase();
19
+ if (message.includes('workspace targeting') ||
20
+ message.includes('specified workspace') ||
21
+ message.includes('user authentication') ||
22
+ message.includes('clerk')) {
23
+ return new errors_1.CliError('Forking into a specific workspace requires a user session key. Run `orch login` (browser sign-in, without `--key`) and retry.');
24
+ }
25
+ return null;
26
+ }
27
+ async function resolveWorkspace(config, workspaceSlug) {
28
+ const response = await (0, api_1.request)(config, 'GET', '/workspaces');
29
+ const workspace = response.workspaces.find((w) => w.slug === workspaceSlug);
30
+ if (!workspace) {
31
+ throw new errors_1.CliError(`Workspace '${workspaceSlug}' not found. Run \`orchagent workspace list\` to see available workspaces.`);
32
+ }
33
+ return workspace;
34
+ }
35
+ function registerForkCommand(program) {
36
+ program
37
+ .command('fork <agent>')
38
+ .description('Fork a public agent into your workspace')
39
+ .option('--name <new-name>', 'Rename the forked agent')
40
+ .option('-w, --workspace <workspace-slug>', 'Target workspace slug')
41
+ .option('--json', 'Output raw JSON')
42
+ .addHelpText('after', `
43
+ Examples:
44
+ orch fork orchagent/my-discord-agent
45
+ orch fork orchagent/my-discord-agent --workspace acme-corp
46
+ orch fork orchagent/my-discord-agent --name customer-support-bot
47
+ orch fork orchagent/my-discord-agent@v2 --json
48
+ `)
49
+ .action(async (agentRef, options) => {
50
+ const write = (message) => {
51
+ if (!options.json)
52
+ process.stdout.write(message);
53
+ };
54
+ const config = await (0, config_1.getResolvedConfig)();
55
+ if (!config.apiKey) {
56
+ throw new errors_1.CliError('Not logged in. Run `orchagent login` first.');
57
+ }
58
+ const { org, agent, version } = (0, agent_ref_1.parseAgentRef)(agentRef);
59
+ write('Resolving source agent...\n');
60
+ const source = await (0, api_1.getPublicAgent)(config, org, agent, version);
61
+ if (!source.id) {
62
+ throw new errors_1.CliError(`Could not resolve source agent ID for '${org}/${agent}@${version}'.`);
63
+ }
64
+ let targetWorkspace = null;
65
+ if (options.workspace) {
66
+ write('Resolving target workspace...\n');
67
+ targetWorkspace = await resolveWorkspace(config, options.workspace);
68
+ }
69
+ write('Forking agent...\n');
70
+ const payload = {};
71
+ if (targetWorkspace)
72
+ payload.workspace_id = targetWorkspace.id;
73
+ const requestedName = options.name?.trim();
74
+ if (requestedName)
75
+ payload.new_name = requestedName;
76
+ let result;
77
+ try {
78
+ result = await (0, api_1.forkAgent)(config, source.id, payload);
79
+ }
80
+ catch (err) {
81
+ const authErr = getWorkspaceAuthError(err);
82
+ if (authErr)
83
+ throw authErr;
84
+ throw err;
85
+ }
86
+ await (0, analytics_1.track)('cli_fork', {
87
+ source_org: org,
88
+ source_agent: agent,
89
+ source_version: version,
90
+ target_workspace: targetWorkspace?.slug ?? null,
91
+ });
92
+ if (options.json) {
93
+ (0, output_1.printJson)(result);
94
+ return;
95
+ }
96
+ const forked = result.agent;
97
+ const targetOrgSlug = forked.org_slug ?? targetWorkspace?.slug ?? 'current-workspace';
98
+ write(`\n${chalk_1.default.green('\u2713')} Forked ${org}/${agent}@${version}\n`);
99
+ write(` New agent: ${targetOrgSlug}/${forked.name}@${forked.version}\n`);
100
+ if (targetWorkspace) {
101
+ write(` Workspace: ${targetWorkspace.name} (${targetWorkspace.slug})\n`);
102
+ }
103
+ if (result.service_key) {
104
+ write(`\nService key (save this - shown only once):\n`);
105
+ write(` ${result.service_key}\n`);
106
+ }
107
+ });
108
+ }
@@ -12,6 +12,7 @@ const run_1 = require("./run");
12
12
  const info_1 = require("./info");
13
13
  const skill_1 = require("./skill");
14
14
  const delete_1 = require("./delete");
15
+ const fork_1 = require("./fork");
15
16
  const github_1 = require("./github");
16
17
  const doctor_1 = require("./doctor");
17
18
  const status_1 = require("./status");
@@ -43,6 +44,7 @@ function registerCommands(program) {
43
44
  (0, keys_1.registerKeysCommand)(program);
44
45
  (0, skill_1.registerSkillCommand)(program);
45
46
  (0, delete_1.registerDeleteCommand)(program);
47
+ (0, fork_1.registerForkCommand)(program);
46
48
  (0, github_1.registerGitHubCommand)(program);
47
49
  (0, doctor_1.registerDoctorCommand)(program);
48
50
  (0, status_1.registerStatusCommand)(program);
package/dist/index.js CHANGED
@@ -61,6 +61,7 @@ program
61
61
  Quick Reference:
62
62
  run Run an agent (cloud by default, --local for local execution)
63
63
  info Show agent details and input/output schemas
64
+ fork Fork a public template into your workspace
64
65
 
65
66
  Installation:
66
67
  npm install -g @orchagent/cli Install globally (then use: orch)
package/dist/lib/api.js CHANGED
@@ -54,6 +54,7 @@ exports.getAgentWithFallback = getAgentWithFallback;
54
54
  exports.downloadCodeBundleAuthenticated = downloadCodeBundleAuthenticated;
55
55
  exports.checkAgentDelete = checkAgentDelete;
56
56
  exports.deleteAgent = deleteAgent;
57
+ exports.forkAgent = forkAgent;
57
58
  exports.checkAgentTransfer = checkAgentTransfer;
58
59
  exports.transferAgent = transferAgent;
59
60
  exports.previewAgentVersion = previewAgentVersion;
@@ -368,6 +369,15 @@ async function deleteAgent(config, agentId, confirmationName) {
368
369
  const params = confirmationName ? `?confirmation_name=${encodeURIComponent(confirmationName)}` : '';
369
370
  return request(config, 'DELETE', `/agents/${agentId}${params}`);
370
371
  }
372
+ /**
373
+ * Fork a public agent into the caller's workspace (or an explicit workspace_id).
374
+ */
375
+ async function forkAgent(config, sourceAgentId, data = {}) {
376
+ return request(config, 'POST', `/agents/${sourceAgentId}/fork`, {
377
+ body: JSON.stringify(data),
378
+ headers: { 'Content-Type': 'application/json' },
379
+ });
380
+ }
371
381
  /**
372
382
  * Check if an agent can be transferred to another workspace.
373
383
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orchagent/cli",
3
- "version": "0.3.56",
3
+ "version": "0.3.57",
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>",