@cargo-ai/cli 1.0.13 → 1.0.14
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/README.md +23 -2
- package/build/api.d.ts +5 -1
- package/build/api.d.ts.map +1 -1
- package/build/api.js +6 -7
- package/build/commands/{auth.d.ts → auth/index.d.ts} +2 -2
- package/build/commands/auth/index.d.ts.map +1 -0
- package/build/commands/auth/index.js +131 -0
- package/build/commands/auth/oauth.d.ts +7 -0
- package/build/commands/auth/oauth.d.ts.map +1 -0
- package/build/commands/auth/oauth.js +140 -0
- package/build/commands/auth/workspace.d.ts +10 -0
- package/build/commands/auth/workspace.d.ts.map +1 -0
- package/build/commands/auth/workspace.js +120 -0
- package/build/commands/billing/subscription.d.ts.map +1 -1
- package/build/commands/billing/subscription.js +55 -17
- package/build/commands/orchestration/index.d.ts.map +1 -1
- package/build/commands/orchestration/index.js +2 -0
- package/build/commands/orchestration/query.d.ts +4 -0
- package/build/commands/orchestration/query.d.ts.map +1 -0
- package/build/commands/orchestration/query.js +23 -0
- package/build/commands/orchestration/run.d.ts.map +1 -1
- package/build/commands/orchestration/run.js +6 -1
- package/build/commands/runHandler.d.ts +32 -1
- package/build/commands/runHandler.d.ts.map +1 -1
- package/build/commands/runHandler.js +191 -24
- package/build/commands/storage/index.d.ts.map +1 -1
- package/build/commands/storage/index.js +2 -0
- package/build/commands/storage/query.d.ts +4 -0
- package/build/commands/storage/query.d.ts.map +1 -0
- package/build/commands/storage/query.js +23 -0
- package/build/commands/workspaceManagement/file.d.ts.map +1 -0
- package/build/commands/workspaceManagement/folder.d.ts.map +1 -0
- package/build/commands/workspaceManagement/index.d.ts +4 -0
- package/build/commands/workspaceManagement/index.d.ts.map +1 -0
- package/build/commands/workspaceManagement/index.js +19 -0
- package/build/commands/workspaceManagement/report.d.ts +4 -0
- package/build/commands/workspaceManagement/report.d.ts.map +1 -0
- package/build/commands/workspaceManagement/report.js +17 -0
- package/build/commands/workspaceManagement/role.d.ts.map +1 -0
- package/build/commands/workspaceManagement/token.d.ts.map +1 -0
- package/build/commands/{workspace → workspaceManagement}/token.js +3 -2
- package/build/commands/workspaceManagement/user.d.ts.map +1 -0
- package/build/commands/{workspace → workspaceManagement}/user.js +30 -22
- package/build/commands/workspaceManagement/workspaces.d.ts.map +1 -0
- package/build/commands/{workspace → workspaceManagement}/workspaces.js +36 -7
- package/build/config.d.ts +3 -1
- package/build/config.d.ts.map +1 -1
- package/build/config.js +19 -17
- package/build/index.js +24 -10
- package/build/oauthConfig.d.ts +13 -0
- package/build/oauthConfig.d.ts.map +1 -0
- package/build/oauthConfig.js +17 -0
- package/package.json +2 -2
- package/build/commands/auth.d.ts.map +0 -1
- package/build/commands/auth.js +0 -104
- package/build/commands/workspace/file.d.ts.map +0 -1
- package/build/commands/workspace/folder.d.ts.map +0 -1
- package/build/commands/workspace/index.d.ts +0 -4
- package/build/commands/workspace/index.d.ts.map +0 -1
- package/build/commands/workspace/index.js +0 -17
- package/build/commands/workspace/role.d.ts.map +0 -1
- package/build/commands/workspace/token.d.ts.map +0 -1
- package/build/commands/workspace/user.d.ts.map +0 -1
- package/build/commands/workspace/workspaces.d.ts.map +0 -1
- /package/build/commands/{workspace → workspaceManagement}/file.d.ts +0 -0
- /package/build/commands/{workspace → workspaceManagement}/file.js +0 -0
- /package/build/commands/{workspace → workspaceManagement}/folder.d.ts +0 -0
- /package/build/commands/{workspace → workspaceManagement}/folder.js +0 -0
- /package/build/commands/{workspace → workspaceManagement}/role.d.ts +0 -0
- /package/build/commands/{workspace → workspaceManagement}/role.js +0 -0
- /package/build/commands/{workspace → workspaceManagement}/token.d.ts +0 -0
- /package/build/commands/{workspace → workspaceManagement}/user.d.ts +0 -0
- /package/build/commands/{workspace → workspaceManagement}/workspaces.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../../../src/commands/workspaceManagement/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CAiLN"}
|
|
@@ -5,8 +5,13 @@ export function registerWorkspacesCommands(parent, getApi) {
|
|
|
5
5
|
.description("Workspace list and management");
|
|
6
6
|
workspaces
|
|
7
7
|
.command("list")
|
|
8
|
-
.description("List all workspaces")
|
|
9
|
-
.option("--refresh", "
|
|
8
|
+
.description("List all workspaces accessible to the current user")
|
|
9
|
+
.option("--refresh", "Bypass any token cache and re-fetch from the server (useful after permission changes)")
|
|
10
|
+
.addHelpText("after", `
|
|
11
|
+
Examples:
|
|
12
|
+
$ cargo-ai workspaceManagement workspaces list
|
|
13
|
+
$ cargo-ai workspaceManagement workspaces list --refresh
|
|
14
|
+
$ cargo-ai workspaceManagement workspaces list | jq -r '.workspaces[].uuid'`)
|
|
10
15
|
.action(async (opts) => {
|
|
11
16
|
const api = getApi();
|
|
12
17
|
const result = await handleApiCall(() => api.workspaceManagement.workspace.all({
|
|
@@ -14,12 +19,28 @@ export function registerWorkspacesCommands(parent, getApi) {
|
|
|
14
19
|
}));
|
|
15
20
|
outputJson(result);
|
|
16
21
|
});
|
|
22
|
+
workspaces
|
|
23
|
+
.command("get-current")
|
|
24
|
+
.description("Get the workspace currently selected via credentials or CARGO_WORKSPACE_UUID")
|
|
25
|
+
.addHelpText("after", `
|
|
26
|
+
Examples:
|
|
27
|
+
$ cargo-ai workspaceManagement workspaces get-current
|
|
28
|
+
$ cargo-ai workspaceManagement workspaces get-current | jq -r .workspace.name`)
|
|
29
|
+
.action(async () => {
|
|
30
|
+
const api = getApi();
|
|
31
|
+
const result = await handleApiCall(() => api.workspaceManagement.workspace.getCurrent());
|
|
32
|
+
outputJson(result);
|
|
33
|
+
});
|
|
17
34
|
workspaces
|
|
18
35
|
.command("create")
|
|
19
|
-
.description("Create a workspace")
|
|
20
|
-
.requiredOption("--name <name>", "Workspace name")
|
|
21
|
-
.option("--logo-base64 <data>", "Logo as base64 string")
|
|
22
|
-
.option("--metadata <json>", '
|
|
36
|
+
.description("Create a new workspace")
|
|
37
|
+
.requiredOption("--name <name>", "Workspace display name")
|
|
38
|
+
.option("--logo-base64 <data>", "Logo image encoded as a base64 data string")
|
|
39
|
+
.option("--metadata <json>", 'Workspace metadata as a JSON object, e.g. {"mainGoal":["enrich"]}')
|
|
40
|
+
.addHelpText("after", `
|
|
41
|
+
Examples:
|
|
42
|
+
$ cargo-ai workspaceManagement workspaces create --name "Acme GTM"
|
|
43
|
+
$ cargo-ai workspaceManagement workspaces create --name "Acme GTM" --metadata '{"mainGoal":["enrich"]}'`)
|
|
23
44
|
.action(async (opts) => {
|
|
24
45
|
const api = getApi();
|
|
25
46
|
const result = await handleApiCall(() => api.workspaceManagement.workspace.create({
|
|
@@ -33,7 +54,15 @@ export function registerWorkspacesCommands(parent, getApi) {
|
|
|
33
54
|
});
|
|
34
55
|
workspaces
|
|
35
56
|
.command("update")
|
|
36
|
-
.description("Update
|
|
57
|
+
.description("Update properties of the currently selected workspace")
|
|
58
|
+
.addHelpText("after", `
|
|
59
|
+
Examples:
|
|
60
|
+
$ cargo-ai workspaceManagement workspaces update --name "New name"
|
|
61
|
+
$ cargo-ai workspaceManagement workspaces update --allowed-email-domains acme.com,example.org
|
|
62
|
+
$ cargo-ai workspaceManagement workspaces update --openai-api-key null # remove the key
|
|
63
|
+
$ cargo-ai workspaceManagement workspaces update --metadata '{"mainGoal":["enrich","prioritize"]}'
|
|
64
|
+
|
|
65
|
+
Pass the literal string "null" to remove a nullable value.`)
|
|
37
66
|
.option("--name <name>", "Workspace name")
|
|
38
67
|
.option("--allowed-email-domains <list>", "Allowed email domains (comma-separated)")
|
|
39
68
|
.option("--logo-base64 <data>", "Logo as base64 string (use 'null' to remove)")
|
package/build/config.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
export type ConfigSource = "environment" | "credentials-file" | "none";
|
|
1
2
|
export type Config = {
|
|
3
|
+
accessToken: string | undefined;
|
|
2
4
|
baseUrl: string;
|
|
3
|
-
accessToken: string;
|
|
4
5
|
workspaceUuid: string | undefined;
|
|
6
|
+
source: ConfigSource;
|
|
5
7
|
};
|
|
6
8
|
export declare function getConfig(): Config;
|
|
7
9
|
//# sourceMappingURL=config.d.ts.map
|
package/build/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,MAAM,GAAG;IACnB,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,kBAAkB,GAAG,MAAM,CAAC;AAEvE,MAAM,MAAM,MAAM,GAAG;IACnB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAIF,wBAAgB,SAAS,IAAI,MAAM,CA4BlC"}
|
package/build/config.js
CHANGED
|
@@ -2,27 +2,29 @@ import { loadCredentials } from "./credentials.js";
|
|
|
2
2
|
const DEFAULT_BASE_URL = "https://api.getcargo.io";
|
|
3
3
|
export function getConfig() {
|
|
4
4
|
const credentials = loadCredentials();
|
|
5
|
-
const accessToken = getAccessToken(credentials);
|
|
6
|
-
if (accessToken === undefined) {
|
|
7
|
-
console.error(JSON.stringify({
|
|
8
|
-
error: 'Not authenticated. Run "cargo-ai login --token <token>" or set CARGO_API_TOKEN.',
|
|
9
|
-
}));
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
const baseUrl = getBaseUrl(credentials);
|
|
13
|
-
const workspaceUuid = getWorkspaceUuid(credentials);
|
|
14
|
-
return { baseUrl, accessToken, workspaceUuid };
|
|
15
|
-
}
|
|
16
|
-
const getAccessToken = (credentials) => {
|
|
17
5
|
const envToken = process.env["CARGO_API_TOKEN"];
|
|
6
|
+
let accessToken;
|
|
7
|
+
let source;
|
|
18
8
|
if (envToken !== undefined) {
|
|
19
|
-
|
|
9
|
+
accessToken = envToken;
|
|
10
|
+
source = "environment";
|
|
20
11
|
}
|
|
21
|
-
if (credentials !== undefined
|
|
22
|
-
|
|
12
|
+
else if (credentials !== undefined &&
|
|
13
|
+
credentials.accessToken !== undefined) {
|
|
14
|
+
accessToken = credentials.accessToken;
|
|
15
|
+
source = "credentials-file";
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
else {
|
|
18
|
+
accessToken = undefined;
|
|
19
|
+
source = "none";
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
accessToken,
|
|
23
|
+
baseUrl: getBaseUrl(credentials),
|
|
24
|
+
workspaceUuid: getWorkspaceUuid(credentials),
|
|
25
|
+
source,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
26
28
|
const getBaseUrl = (credentials) => {
|
|
27
29
|
const envUrl = process.env["CARGO_BASE_URL"];
|
|
28
30
|
if (envUrl !== undefined) {
|
package/build/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { createApi } from "./api.js";
|
|
5
5
|
import { registerAiCommands } from "./commands/ai/index.js";
|
|
6
|
-
import { registerAuthCommands } from "./commands/auth.js";
|
|
6
|
+
import { registerAuthCommands } from "./commands/auth/index.js";
|
|
7
7
|
import { registerBillingCommands } from "./commands/billing/index.js";
|
|
8
8
|
import { registerConnectionCommands } from "./commands/connection/index.js";
|
|
9
9
|
import { registerContextCommands } from "./commands/context/index.js";
|
|
@@ -11,11 +11,13 @@ import { registerExpressionCommands } from "./commands/expression/index.js";
|
|
|
11
11
|
import { registerInitCommand } from "./commands/init.js";
|
|
12
12
|
import { registerOrchestrationCommands } from "./commands/orchestration/index.js";
|
|
13
13
|
import { registerRevenueOrganizationCommands } from "./commands/revenueOrganization/index.js";
|
|
14
|
+
import { ExitCodes, failWith } from "./commands/runHandler.js";
|
|
14
15
|
import { registerSegmentationCommands } from "./commands/segmentation/index.js";
|
|
15
16
|
import { registerStorageCommands } from "./commands/storage/index.js";
|
|
16
17
|
import { registerSystemOfRecordIntegrationCommands } from "./commands/systemOfRecordIntegration/index.js";
|
|
17
18
|
import { registerUserManagementCommands } from "./commands/userManagement/index.js";
|
|
18
|
-
import {
|
|
19
|
+
import { registerWorkspaceManagementCommands } from "./commands/workspaceManagement/index.js";
|
|
20
|
+
import { getConfig } from "./config.js";
|
|
19
21
|
const require = createRequire(import.meta.url);
|
|
20
22
|
const { version } = require("../package.json");
|
|
21
23
|
const program = new Command();
|
|
@@ -25,19 +27,34 @@ program
|
|
|
25
27
|
.version(version)
|
|
26
28
|
.addHelpText("after", `
|
|
27
29
|
Authentication:
|
|
28
|
-
|
|
30
|
+
With API token: cargo-ai login --token <your-token>
|
|
31
|
+
Browser sign-in: cargo-ai login --oauth
|
|
29
32
|
Use env variables: CARGO_API_TOKEN, CARGO_WORKSPACE_UUID, CARGO_BASE_URL
|
|
30
33
|
Check status: cargo-ai whoami
|
|
31
34
|
|
|
32
|
-
All commands output JSON to stdout.
|
|
35
|
+
All commands output JSON to stdout. Status messages, prompts, and errors go to stderr.
|
|
36
|
+
|
|
37
|
+
Exit codes:
|
|
38
|
+
0 Success
|
|
39
|
+
1 Generic error
|
|
40
|
+
2 Invalid usage (missing/conflicting flags)
|
|
41
|
+
3 Not authenticated (run \`cargo-ai login\`)
|
|
42
|
+
4 Permission denied
|
|
43
|
+
5 Not found
|
|
33
44
|
|
|
34
45
|
Run "cargo-ai <command> --help" for details on a specific command group.
|
|
35
46
|
Run "cargo-ai <command> <subcommand> --help" for details on a subcommand.`);
|
|
36
|
-
const getApi = () =>
|
|
47
|
+
const getApi = () => {
|
|
48
|
+
const { baseUrl, accessToken, workspaceUuid } = getConfig();
|
|
49
|
+
if (accessToken === undefined) {
|
|
50
|
+
failWith("Not authenticated. Run 'cargo-ai login --token <token>' or 'cargo-ai login --oauth'.", { code: ExitCodes.NotAuthenticated });
|
|
51
|
+
}
|
|
52
|
+
return createApi({ baseUrl, accessToken, workspaceUuid });
|
|
53
|
+
};
|
|
37
54
|
registerAuthCommands(program, getApi);
|
|
38
55
|
registerInitCommand(program, getApi);
|
|
39
56
|
registerOrchestrationCommands(program, getApi);
|
|
40
|
-
|
|
57
|
+
registerWorkspaceManagementCommands(program, getApi);
|
|
41
58
|
registerStorageCommands(program, getApi);
|
|
42
59
|
registerConnectionCommands(program, getApi);
|
|
43
60
|
registerContextCommands(program, getApi);
|
|
@@ -49,8 +66,5 @@ registerSystemOfRecordIntegrationCommands(program, getApi);
|
|
|
49
66
|
registerUserManagementCommands(program, getApi);
|
|
50
67
|
registerAiCommands(program, getApi);
|
|
51
68
|
program.parseAsync().catch((err) => {
|
|
52
|
-
|
|
53
|
-
error: err instanceof Error ? err.message : String(err),
|
|
54
|
-
}));
|
|
55
|
-
process.exit(1);
|
|
69
|
+
failWith(err instanceof Error ? err.message : String(err));
|
|
56
70
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type OAuthConfig = {
|
|
2
|
+
domain: string;
|
|
3
|
+
clientId: string;
|
|
4
|
+
audience: string;
|
|
5
|
+
scope: string;
|
|
6
|
+
};
|
|
7
|
+
export type OAuthConfigOverrides = {
|
|
8
|
+
domain?: string;
|
|
9
|
+
clientId?: string;
|
|
10
|
+
audience?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function getOAuthConfig(overrides: OAuthConfigOverrides): OAuthConfig;
|
|
13
|
+
//# sourceMappingURL=oauthConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauthConfig.d.ts","sourceRoot":"","sources":["../src/oauthConfig.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAOF,wBAAgB,cAAc,CAAC,SAAS,EAAE,oBAAoB,GAAG,WAAW,CAO3E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const DEFAULT_DOMAIN = "auth.getcargo.io";
|
|
2
|
+
const DEFAULT_AUDIENCE = "https://api.getcargo.io";
|
|
3
|
+
const DEFAULT_SCOPE = "openid profile email offline_access";
|
|
4
|
+
const DEFAULT_CLIENT_ID = "oUc99KlLSMAYUAPgxTUyqazef0sxR93b";
|
|
5
|
+
export function getOAuthConfig(overrides) {
|
|
6
|
+
return {
|
|
7
|
+
domain: pickString(overrides.domain, DEFAULT_DOMAIN),
|
|
8
|
+
audience: pickString(overrides.audience, DEFAULT_AUDIENCE),
|
|
9
|
+
clientId: pickString(overrides.clientId, DEFAULT_CLIENT_ID),
|
|
10
|
+
scope: DEFAULT_SCOPE,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const pickString = (override, fallback) => {
|
|
14
|
+
if (override !== undefined && override.length > 0)
|
|
15
|
+
return override;
|
|
16
|
+
return fallback;
|
|
17
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cargo-ai/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Command-line interface for the Cargo API",
|
|
6
6
|
"engines": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"commander": "^12.1.0",
|
|
32
|
-
"@cargo-ai/api": "^1.0.
|
|
32
|
+
"@cargo-ai/api": "^1.0.22"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@cargo-ai/eslint-config": "*",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAWrC,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CAuIN"}
|
package/build/commands/auth.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { clearCredentials, getCredentialsPath, loadCredentials, saveCredentials, } from "../credentials.js";
|
|
2
|
-
import { handleApiCall, outputJson } from "./runHandler.js";
|
|
3
|
-
const DEFAULT_BASE_URL = "https://api.getcargo.io";
|
|
4
|
-
export function registerAuthCommands(program, getApi) {
|
|
5
|
-
program
|
|
6
|
-
.command("login")
|
|
7
|
-
.description("Save API credentials for future use")
|
|
8
|
-
.requiredOption("--token <token>", "Cargo API token (string)")
|
|
9
|
-
.option("--workspace-uuid <uuid>", "Default workspace UUID (string, UUID v4)")
|
|
10
|
-
.option("--base-url <url>", `API base URL (string, default: ${DEFAULT_BASE_URL})`)
|
|
11
|
-
.addHelpText("after", `
|
|
12
|
-
Examples:
|
|
13
|
-
$ cargo-ai login --token sk_live_abc123
|
|
14
|
-
$ cargo-ai login --token sk_live_abc123 --workspace-uuid 550e8400-e29b-41d4-a716-446655440000
|
|
15
|
-
$ cargo-ai login --token sk_live_abc123 --base-url https://api.custom.io
|
|
16
|
-
|
|
17
|
-
Credentials are stored in ~/.config/cargo-ai/credentials.json.
|
|
18
|
-
Environment variables (CARGO_API_TOKEN, CARGO_WORKSPACE_UUID, CARGO_BASE_URL) take precedence over saved credentials.`)
|
|
19
|
-
.action((opts) => {
|
|
20
|
-
saveCredentials({
|
|
21
|
-
accessToken: opts.token,
|
|
22
|
-
workspaceUuid: opts.workspaceUuid,
|
|
23
|
-
baseUrl: opts.baseUrl,
|
|
24
|
-
});
|
|
25
|
-
outputJson({
|
|
26
|
-
ok: true,
|
|
27
|
-
credentialsFile: getCredentialsPath(),
|
|
28
|
-
baseUrl: opts.baseUrl !== undefined ? opts.baseUrl : DEFAULT_BASE_URL,
|
|
29
|
-
workspaceUuid: opts.workspaceUuid !== undefined ? opts.workspaceUuid : null,
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
program
|
|
33
|
-
.command("logout")
|
|
34
|
-
.description("Remove saved API credentials")
|
|
35
|
-
.action(() => {
|
|
36
|
-
const removed = clearCredentials();
|
|
37
|
-
outputJson({
|
|
38
|
-
ok: true,
|
|
39
|
-
removed,
|
|
40
|
-
credentialsFile: getCredentialsPath(),
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
program
|
|
44
|
-
.command("whoami")
|
|
45
|
-
.description("Show current user and workspace")
|
|
46
|
-
.addHelpText("after", `
|
|
47
|
-
Returns JSON with: user (uuid, email, name), workspace (uuid, name),
|
|
48
|
-
authentication source ("environment" or "credentials-file"), and base URL.`)
|
|
49
|
-
.action(async () => {
|
|
50
|
-
const envToken = process.env["CARGO_API_TOKEN"];
|
|
51
|
-
const envBaseUrl = process.env["CARGO_BASE_URL"];
|
|
52
|
-
const envWorkspace = process.env["CARGO_WORKSPACE_UUID"];
|
|
53
|
-
const creds = loadCredentials();
|
|
54
|
-
const hasToken = envToken !== undefined ||
|
|
55
|
-
(creds !== undefined && creds.accessToken !== undefined);
|
|
56
|
-
const baseUrl = envBaseUrl !== undefined
|
|
57
|
-
? envBaseUrl
|
|
58
|
-
: creds !== undefined && creds.baseUrl !== undefined
|
|
59
|
-
? creds.baseUrl
|
|
60
|
-
: DEFAULT_BASE_URL;
|
|
61
|
-
const workspaceUuid = envWorkspace !== undefined
|
|
62
|
-
? envWorkspace
|
|
63
|
-
: creds !== undefined
|
|
64
|
-
? creds.workspaceUuid
|
|
65
|
-
: undefined;
|
|
66
|
-
if (hasToken === false) {
|
|
67
|
-
outputJson({
|
|
68
|
-
user: null,
|
|
69
|
-
workspace: null,
|
|
70
|
-
source: "none",
|
|
71
|
-
baseUrl,
|
|
72
|
-
credentialsFile: getCredentialsPath(),
|
|
73
|
-
warnings: [
|
|
74
|
-
'Not authenticated. Run "cargo-ai login --token <token>" or set CARGO_API_TOKEN.',
|
|
75
|
-
],
|
|
76
|
-
});
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const source = envToken !== undefined ? "environment" : "credentials-file";
|
|
80
|
-
const api = getApi();
|
|
81
|
-
const { user } = await handleApiCall(() => api.userManagement.user.getCurrent());
|
|
82
|
-
const { workspaces } = await handleApiCall(() => api.workspaceManagement.workspace.all({ refresh: false }));
|
|
83
|
-
const matchedWorkspace = workspaceUuid !== undefined
|
|
84
|
-
? workspaces.find((workspace) => {
|
|
85
|
-
return workspace.uuid === workspaceUuid;
|
|
86
|
-
})
|
|
87
|
-
: workspaces[0];
|
|
88
|
-
const workspace = matchedWorkspace !== undefined
|
|
89
|
-
? { uuid: matchedWorkspace.uuid, name: matchedWorkspace.name }
|
|
90
|
-
: null;
|
|
91
|
-
outputJson({
|
|
92
|
-
user: {
|
|
93
|
-
uuid: user.uuid,
|
|
94
|
-
email: user.email,
|
|
95
|
-
firstName: user.firstName,
|
|
96
|
-
lastName: user.lastName,
|
|
97
|
-
},
|
|
98
|
-
workspace,
|
|
99
|
-
source,
|
|
100
|
-
baseUrl,
|
|
101
|
-
credentialsFile: getCredentialsPath(),
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/file.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,IAAI,CA+C7E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"folder.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/folder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CA6FN"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAQxC,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CAWN"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { registerFileCommands } from "./file.js";
|
|
2
|
-
import { registerFolderCommands } from "./folder.js";
|
|
3
|
-
import { registerRoleCommands } from "./role.js";
|
|
4
|
-
import { registerTokenCommands } from "./token.js";
|
|
5
|
-
import { registerUserCommands } from "./user.js";
|
|
6
|
-
import { registerWorkspacesCommands } from "./workspaces.js";
|
|
7
|
-
export function registerWorkspaceCommands(parent, getApi) {
|
|
8
|
-
const workspace = parent
|
|
9
|
-
.command("workspace")
|
|
10
|
-
.description("Workspaces, users, tokens, roles, folders");
|
|
11
|
-
registerWorkspacesCommands(workspace, getApi);
|
|
12
|
-
registerUserCommands(workspace, getApi);
|
|
13
|
-
registerTokenCommands(workspace, getApi);
|
|
14
|
-
registerRoleCommands(workspace, getApi);
|
|
15
|
-
registerFolderCommands(workspace, getApi);
|
|
16
|
-
registerFileCommands(workspace, getApi);
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"role.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/role.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,IAAI,CAa7E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CAoCN"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAIxC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,IAAI,CA0L7E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../../../src/commands/workspace/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGxC,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GAAG,GAChB,IAAI,CA0HN"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|