@agentuity/cli 0.0.6
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/AGENTS.md +139 -0
- package/README.md +239 -0
- package/bin/cli.ts +71 -0
- package/dist/api.d.ts +25 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/auth.d.ts +7 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/banner.d.ts +2 -0
- package/dist/banner.d.ts.map +1 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cmd/auth/api.d.ts +9 -0
- package/dist/cmd/auth/api.d.ts.map +1 -0
- package/dist/cmd/auth/index.d.ts +2 -0
- package/dist/cmd/auth/index.d.ts.map +1 -0
- package/dist/cmd/auth/login.d.ts +3 -0
- package/dist/cmd/auth/login.d.ts.map +1 -0
- package/dist/cmd/auth/logout.d.ts +3 -0
- package/dist/cmd/auth/logout.d.ts.map +1 -0
- package/dist/cmd/bundle/ast.d.ts +2 -0
- package/dist/cmd/bundle/ast.d.ts.map +1 -0
- package/dist/cmd/bundle/bundler.d.ts +6 -0
- package/dist/cmd/bundle/bundler.d.ts.map +1 -0
- package/dist/cmd/bundle/file.d.ts +2 -0
- package/dist/cmd/bundle/file.d.ts.map +1 -0
- package/dist/cmd/bundle/index.d.ts +2 -0
- package/dist/cmd/bundle/index.d.ts.map +1 -0
- package/dist/cmd/bundle/plugin.d.ts +4 -0
- package/dist/cmd/bundle/plugin.d.ts.map +1 -0
- package/dist/cmd/dev/index.d.ts +2 -0
- package/dist/cmd/dev/index.d.ts.map +1 -0
- package/dist/cmd/example/create-user.d.ts +2 -0
- package/dist/cmd/example/create-user.d.ts.map +1 -0
- package/dist/cmd/example/create.d.ts +2 -0
- package/dist/cmd/example/create.d.ts.map +1 -0
- package/dist/cmd/example/deploy.d.ts +2 -0
- package/dist/cmd/example/deploy.d.ts.map +1 -0
- package/dist/cmd/example/index.d.ts +2 -0
- package/dist/cmd/example/index.d.ts.map +1 -0
- package/dist/cmd/example/list.d.ts +2 -0
- package/dist/cmd/example/list.d.ts.map +1 -0
- package/dist/cmd/example/run-command.d.ts +2 -0
- package/dist/cmd/example/run-command.d.ts.map +1 -0
- package/dist/cmd/example/sound.d.ts +3 -0
- package/dist/cmd/example/sound.d.ts.map +1 -0
- package/dist/cmd/example/spinner.d.ts +2 -0
- package/dist/cmd/example/spinner.d.ts.map +1 -0
- package/dist/cmd/example/steps.d.ts +2 -0
- package/dist/cmd/example/steps.d.ts.map +1 -0
- package/dist/cmd/example/version.d.ts +2 -0
- package/dist/cmd/example/version.d.ts.map +1 -0
- package/dist/cmd/index.d.ts +3 -0
- package/dist/cmd/index.d.ts.map +1 -0
- package/dist/cmd/profile/create.d.ts +2 -0
- package/dist/cmd/profile/create.d.ts.map +1 -0
- package/dist/cmd/profile/delete.d.ts +2 -0
- package/dist/cmd/profile/delete.d.ts.map +1 -0
- package/dist/cmd/profile/index.d.ts +2 -0
- package/dist/cmd/profile/index.d.ts.map +1 -0
- package/dist/cmd/profile/list.d.ts +3 -0
- package/dist/cmd/profile/list.d.ts.map +1 -0
- package/dist/cmd/profile/show.d.ts +2 -0
- package/dist/cmd/profile/show.d.ts.map +1 -0
- package/dist/cmd/profile/use.d.ts +2 -0
- package/dist/cmd/profile/use.d.ts.map +1 -0
- package/dist/cmd/project/create.d.ts +2 -0
- package/dist/cmd/project/create.d.ts.map +1 -0
- package/dist/cmd/project/delete.d.ts +2 -0
- package/dist/cmd/project/delete.d.ts.map +1 -0
- package/dist/cmd/project/index.d.ts +2 -0
- package/dist/cmd/project/index.d.ts.map +1 -0
- package/dist/cmd/project/list.d.ts +2 -0
- package/dist/cmd/project/list.d.ts.map +1 -0
- package/dist/cmd/project/show.d.ts +2 -0
- package/dist/cmd/project/show.d.ts.map +1 -0
- package/dist/cmd/version/index.d.ts +2 -0
- package/dist/cmd/version/index.d.ts.map +1 -0
- package/dist/command-prefix.d.ts +11 -0
- package/dist/command-prefix.d.ts.map +1 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/legacy-check.d.ts +6 -0
- package/dist/legacy-check.d.ts.map +1 -0
- package/dist/logger.d.ts +24 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/schema-parser.d.ts +24 -0
- package/dist/schema-parser.d.ts.map +1 -0
- package/dist/sound.d.ts +2 -0
- package/dist/sound.d.ts.map +1 -0
- package/dist/steps.d.ts +59 -0
- package/dist/steps.d.ts.map +1 -0
- package/dist/terminal.d.ts +3 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/tui.d.ts +156 -0
- package/dist/tui.d.ts.map +1 -0
- package/dist/types.d.ts +164 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +46 -0
- package/src/api-errors.md +115 -0
- package/src/api.ts +186 -0
- package/src/auth.ts +91 -0
- package/src/banner.ts +23 -0
- package/src/cli.ts +198 -0
- package/src/cmd/auth/README.md +95 -0
- package/src/cmd/auth/api.ts +71 -0
- package/src/cmd/auth/index.ts +9 -0
- package/src/cmd/auth/login.ts +76 -0
- package/src/cmd/auth/logout.ts +14 -0
- package/src/cmd/bundle/ast.ts +228 -0
- package/src/cmd/bundle/bundler.ts +88 -0
- package/src/cmd/bundle/file.ts +16 -0
- package/src/cmd/bundle/index.ts +38 -0
- package/src/cmd/bundle/plugin.ts +259 -0
- package/src/cmd/dev/index.ts +83 -0
- package/src/cmd/example/create-user.ts +38 -0
- package/src/cmd/example/create.ts +31 -0
- package/src/cmd/example/deploy.ts +36 -0
- package/src/cmd/example/index.ts +27 -0
- package/src/cmd/example/list.ts +32 -0
- package/src/cmd/example/run-command.ts +45 -0
- package/src/cmd/example/sound.ts +14 -0
- package/src/cmd/example/spinner.ts +44 -0
- package/src/cmd/example/steps.ts +66 -0
- package/src/cmd/example/version.ts +13 -0
- package/src/cmd/index.ts +46 -0
- package/src/cmd/profile/README.md +80 -0
- package/src/cmd/profile/create.ts +57 -0
- package/src/cmd/profile/delete.ts +52 -0
- package/src/cmd/profile/index.ts +12 -0
- package/src/cmd/profile/list.ts +27 -0
- package/src/cmd/profile/show.ts +54 -0
- package/src/cmd/profile/use.ts +30 -0
- package/src/cmd/project/create.ts +247 -0
- package/src/cmd/project/delete.ts +13 -0
- package/src/cmd/project/index.ts +11 -0
- package/src/cmd/project/list.ts +13 -0
- package/src/cmd/project/show.ts +12 -0
- package/src/cmd/version/index.ts +16 -0
- package/src/command-prefix.ts +43 -0
- package/src/config.ts +304 -0
- package/src/index.ts +40 -0
- package/src/legacy-check.ts +127 -0
- package/src/logger.ts +235 -0
- package/src/runtime.ts +22 -0
- package/src/schema-parser.ts +213 -0
- package/src/sound.ts +25 -0
- package/src/steps.ts +245 -0
- package/src/terminal.ts +151 -0
- package/src/tui.md +254 -0
- package/src/tui.ts +838 -0
- package/src/types.ts +243 -0
- package/src/version.ts +29 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { Logger } from './logger';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
import { z as zod } from 'zod';
|
|
4
|
+
export declare const ConfigSchema: z.ZodObject<{
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
auth: z.ZodOptional<z.ZodObject<{
|
|
7
|
+
api_key: z.ZodOptional<z.ZodString>;
|
|
8
|
+
user_id: z.ZodOptional<z.ZodString>;
|
|
9
|
+
expires: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
}, z.core.$strip>>;
|
|
11
|
+
devmode: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
hostname: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>>;
|
|
14
|
+
overrides: z.ZodOptional<z.ZodObject<{
|
|
15
|
+
api_url: z.ZodOptional<z.ZodString>;
|
|
16
|
+
app_url: z.ZodOptional<z.ZodString>;
|
|
17
|
+
transport_url: z.ZodOptional<z.ZodString>;
|
|
18
|
+
websocket_url: z.ZodOptional<z.ZodString>;
|
|
19
|
+
skip_version_check: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
}, z.core.$strip>>;
|
|
21
|
+
preferences: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
last_update_check: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
last_legacy_warning: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
orgId: z.ZodOptional<z.ZodString>;
|
|
25
|
+
project_dir: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type Config = zod.infer<typeof ConfigSchema>;
|
|
29
|
+
export type LogLevel = 'debug' | 'trace' | 'info' | 'warn' | 'error';
|
|
30
|
+
export interface Profile {
|
|
31
|
+
name: string;
|
|
32
|
+
filename: string;
|
|
33
|
+
selected: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface AuthData {
|
|
36
|
+
apiKey: string;
|
|
37
|
+
userId: string;
|
|
38
|
+
expires: Date;
|
|
39
|
+
}
|
|
40
|
+
export interface GlobalOptions {
|
|
41
|
+
config?: string;
|
|
42
|
+
logLevel: LogLevel;
|
|
43
|
+
logTimestamp?: boolean;
|
|
44
|
+
logPrefix?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface CommandSchemas {
|
|
47
|
+
args?: z.ZodType;
|
|
48
|
+
options?: z.ZodType;
|
|
49
|
+
}
|
|
50
|
+
export type CommandContext<RequiresAuth extends boolean = false, ArgsSchema extends z.ZodType | undefined = undefined, OptionsSchema extends z.ZodType | undefined = undefined> = RequiresAuth extends true ? ArgsSchema extends z.ZodType ? OptionsSchema extends z.ZodType ? {
|
|
51
|
+
config: Config | null;
|
|
52
|
+
logger: Logger;
|
|
53
|
+
options: GlobalOptions;
|
|
54
|
+
auth: AuthData;
|
|
55
|
+
args: z.infer<ArgsSchema>;
|
|
56
|
+
opts: z.infer<OptionsSchema>;
|
|
57
|
+
} : {
|
|
58
|
+
config: Config | null;
|
|
59
|
+
logger: Logger;
|
|
60
|
+
options: GlobalOptions;
|
|
61
|
+
auth: AuthData;
|
|
62
|
+
args: z.infer<ArgsSchema>;
|
|
63
|
+
} : OptionsSchema extends z.ZodType ? {
|
|
64
|
+
config: Config | null;
|
|
65
|
+
logger: Logger;
|
|
66
|
+
options: GlobalOptions;
|
|
67
|
+
auth: AuthData;
|
|
68
|
+
opts: z.infer<OptionsSchema>;
|
|
69
|
+
} : {
|
|
70
|
+
config: Config | null;
|
|
71
|
+
logger: Logger;
|
|
72
|
+
options: GlobalOptions;
|
|
73
|
+
auth: AuthData;
|
|
74
|
+
} : ArgsSchema extends z.ZodType ? OptionsSchema extends z.ZodType ? {
|
|
75
|
+
config: Config | null;
|
|
76
|
+
logger: Logger;
|
|
77
|
+
options: GlobalOptions;
|
|
78
|
+
args: z.infer<ArgsSchema>;
|
|
79
|
+
opts: z.infer<OptionsSchema>;
|
|
80
|
+
} : {
|
|
81
|
+
config: Config | null;
|
|
82
|
+
logger: Logger;
|
|
83
|
+
options: GlobalOptions;
|
|
84
|
+
args: z.infer<ArgsSchema>;
|
|
85
|
+
} : OptionsSchema extends z.ZodType ? {
|
|
86
|
+
config: Config | null;
|
|
87
|
+
logger: Logger;
|
|
88
|
+
options: GlobalOptions;
|
|
89
|
+
opts: z.infer<OptionsSchema>;
|
|
90
|
+
} : {
|
|
91
|
+
config: Config | null;
|
|
92
|
+
logger: Logger;
|
|
93
|
+
options: GlobalOptions;
|
|
94
|
+
};
|
|
95
|
+
export declare function createSubcommand<TRequiresAuth extends boolean, TArgsSchema extends z.ZodType | undefined, TOptionsSchema extends z.ZodType | undefined>(definition: {
|
|
96
|
+
name: string;
|
|
97
|
+
description: string;
|
|
98
|
+
aliases?: string[];
|
|
99
|
+
toplevel?: boolean;
|
|
100
|
+
requiresAuth?: TRequiresAuth;
|
|
101
|
+
schema?: TArgsSchema extends z.ZodType ? TOptionsSchema extends z.ZodType ? {
|
|
102
|
+
args: TArgsSchema;
|
|
103
|
+
options: TOptionsSchema;
|
|
104
|
+
} : {
|
|
105
|
+
args: TArgsSchema;
|
|
106
|
+
} : TOptionsSchema extends z.ZodType ? {
|
|
107
|
+
options: TOptionsSchema;
|
|
108
|
+
} : never;
|
|
109
|
+
handler(ctx: CommandContext<TRequiresAuth extends true ? true : false, TArgsSchema, TOptionsSchema>): void | Promise<void>;
|
|
110
|
+
}): SubcommandDefinition;
|
|
111
|
+
export declare function createCommand<TRequiresAuth extends boolean, TArgsSchema extends z.ZodType | undefined, TOptionsSchema extends z.ZodType | undefined>(definition: {
|
|
112
|
+
name: string;
|
|
113
|
+
description: string;
|
|
114
|
+
aliases?: string[];
|
|
115
|
+
hidden?: boolean;
|
|
116
|
+
requiresAuth?: TRequiresAuth;
|
|
117
|
+
schema?: TArgsSchema extends z.ZodType ? TOptionsSchema extends z.ZodType ? {
|
|
118
|
+
args: TArgsSchema;
|
|
119
|
+
options: TOptionsSchema;
|
|
120
|
+
} : {
|
|
121
|
+
args: TArgsSchema;
|
|
122
|
+
} : TOptionsSchema extends z.ZodType ? {
|
|
123
|
+
options: TOptionsSchema;
|
|
124
|
+
} : never;
|
|
125
|
+
handler?(ctx: CommandContext<TRequiresAuth extends true ? true : false, TArgsSchema, TOptionsSchema>): void | Promise<void>;
|
|
126
|
+
subcommands?: SubcommandDefinition[];
|
|
127
|
+
}): CommandDefinition;
|
|
128
|
+
export type SubcommandDefinition = {
|
|
129
|
+
name: string;
|
|
130
|
+
description: string;
|
|
131
|
+
aliases?: string[];
|
|
132
|
+
toplevel?: boolean;
|
|
133
|
+
requiresAuth: true;
|
|
134
|
+
schema?: CommandSchemas;
|
|
135
|
+
handler(ctx: CommandContext): void | Promise<void>;
|
|
136
|
+
} | {
|
|
137
|
+
name: string;
|
|
138
|
+
description: string;
|
|
139
|
+
aliases?: string[];
|
|
140
|
+
toplevel?: boolean;
|
|
141
|
+
requiresAuth?: false;
|
|
142
|
+
schema?: CommandSchemas;
|
|
143
|
+
handler(ctx: CommandContext): void | Promise<void>;
|
|
144
|
+
};
|
|
145
|
+
export type CommandDefinition = {
|
|
146
|
+
name: string;
|
|
147
|
+
description: string;
|
|
148
|
+
aliases?: string[];
|
|
149
|
+
hidden?: boolean;
|
|
150
|
+
requiresAuth: true;
|
|
151
|
+
schema?: CommandSchemas;
|
|
152
|
+
handler?(ctx: CommandContext): void | Promise<void>;
|
|
153
|
+
subcommands?: SubcommandDefinition[];
|
|
154
|
+
} | {
|
|
155
|
+
name: string;
|
|
156
|
+
description: string;
|
|
157
|
+
aliases?: string[];
|
|
158
|
+
hidden?: boolean;
|
|
159
|
+
requiresAuth?: false;
|
|
160
|
+
schema?: CommandSchemas;
|
|
161
|
+
handler?(ctx: CommandContext): void | Promise<void>;
|
|
162
|
+
subcommands?: SubcommandDefinition[];
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAC;AAC9B,OAAO,EAAE,CAAC,IAAI,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;iBAmDvB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAEpD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAErE,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IAC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C;IACnB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,OAAO,CAAC,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,WAAW,CAAC,EAAE,oBAAoB,EAAE,CAAC;CACpC,GACD;IACA,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,OAAO,CAAC,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,WAAW,CAAC,EAAE,oBAAoB,EAAE,CAAC;CACpC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized version and package information
|
|
3
|
+
* Loads package.json once and caches it
|
|
4
|
+
*/
|
|
5
|
+
import pkg from '../package.json';
|
|
6
|
+
export declare function getPackage(): typeof pkg;
|
|
7
|
+
export declare function getVersion(): string;
|
|
8
|
+
export declare function getPackageName(): string;
|
|
9
|
+
export declare function getRevision(): string;
|
|
10
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,GAAG,MAAM,iBAAiB,CAAuB;AAKxD,wBAAgB,UAAU,IAAI,OAAO,GAAG,CAKvC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,WAAW,IAAI,MAAM,CAGpC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentuity/cli",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"agentuity": "./bin/cli.ts"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./src/index.ts",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"AGENTS.md",
|
|
18
|
+
"README.md",
|
|
19
|
+
"src",
|
|
20
|
+
"dist",
|
|
21
|
+
"bin"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"build": "bunx tsc --build --emitDeclarationOnly --force",
|
|
26
|
+
"typecheck": "bunx tsc --noEmit",
|
|
27
|
+
"test": "bun scripts/test-create-integration.ts",
|
|
28
|
+
"prepublishOnly": "bun run clean && bun run build",
|
|
29
|
+
"setup-dev-template": "bun scripts/setup-dev-template.ts",
|
|
30
|
+
"simulate-create": "bun scripts/simulate-bun-create.ts"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@agentuity/core": "0.0.6",
|
|
34
|
+
"acorn-loose": "^8.5.2",
|
|
35
|
+
"astring": "^1.9.0",
|
|
36
|
+
"commander": "^14.0.2",
|
|
37
|
+
"enquirer": "^2.4.1",
|
|
38
|
+
"zod": "^4.1.12"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"typescript": "^5.9.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# API Error Handling
|
|
2
|
+
|
|
3
|
+
The `APIClient` class automatically handles various error conditions returned by the Agentuity API.
|
|
4
|
+
|
|
5
|
+
## Error Response Format
|
|
6
|
+
|
|
7
|
+
API errors follow this standard format:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"success": false,
|
|
12
|
+
"code": "ERROR_CODE",
|
|
13
|
+
"message": "Human-readable error message",
|
|
14
|
+
"details": {}
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Development Mode / Version Check Bypass
|
|
19
|
+
|
|
20
|
+
For local development and testing, version checks can be bypassed using multiple methods (in priority order):
|
|
21
|
+
|
|
22
|
+
### 1. CLI Flag (Highest Priority, Hidden)
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
agentuity --skip-version-check auth login
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Environment Variable
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
export AGENTUITY_SKIP_VERSION_CHECK=1
|
|
32
|
+
agentuity auth login
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. Profile/Config Override
|
|
36
|
+
|
|
37
|
+
Add to your profile YAML file (e.g., `~/.config/agentuity/dev.yaml`):
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
name: 'dev'
|
|
41
|
+
overrides:
|
|
42
|
+
api_url: https://api.agentuity.io
|
|
43
|
+
app_url: https://app.agentuity.io
|
|
44
|
+
skip_version_check: true
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 4. Automatic Detection (Lowest Priority)
|
|
48
|
+
|
|
49
|
+
Version checks are automatically skipped when:
|
|
50
|
+
|
|
51
|
+
- Version is `"dev"` in package.json
|
|
52
|
+
- Version starts with `"0.0."` (pre-release versions)
|
|
53
|
+
|
|
54
|
+
**Important:** Skipping the version check only prevents the CLI from showing the upgrade error. If the API server enforces version requirements server-side (returns 409 status), the request will still fail. This is intended behavior to ensure API compatibility.
|
|
55
|
+
|
|
56
|
+
## Handled Error Codes
|
|
57
|
+
|
|
58
|
+
### UPGRADE_REQUIRED
|
|
59
|
+
|
|
60
|
+
When the CLI version is outdated or incompatible with the API, the server returns:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"success": false,
|
|
65
|
+
"code": "UPGRADE_REQUIRED",
|
|
66
|
+
"message": "Please upgrade to the latest version of the CLI. Instructions at https://agentuity.dev/CLI/installation"
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Behavior:**
|
|
71
|
+
|
|
72
|
+
- Throws `UpgradeRequiredError` (extends `Error`)
|
|
73
|
+
- Commands should catch this and display a helpful upgrade message
|
|
74
|
+
- Exits with code 1
|
|
75
|
+
|
|
76
|
+
**Example handling:**
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { UpgradeRequiredError } from '@agentuity/cli';
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
await apiCall();
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof UpgradeRequiredError) {
|
|
85
|
+
logger.error('⚠ CLI Upgrade Required');
|
|
86
|
+
logger.error(error.message);
|
|
87
|
+
logger.error('Visit: https://agentuity.dev/CLI/installation');
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Generic Error Handling
|
|
95
|
+
|
|
96
|
+
For other API errors:
|
|
97
|
+
|
|
98
|
+
1. If the response includes a `message` field, it's thrown as `Error(message)`
|
|
99
|
+
2. Otherwise, throws `Error("API error: {status} {statusText}")`
|
|
100
|
+
|
|
101
|
+
## Debug Mode
|
|
102
|
+
|
|
103
|
+
Set `DEBUG=1` environment variable to see detailed error information:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
DEBUG=1 agentuity auth login
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
This will print:
|
|
110
|
+
|
|
111
|
+
- Request URL
|
|
112
|
+
- HTTP method
|
|
113
|
+
- Status code and text
|
|
114
|
+
- Request headers
|
|
115
|
+
- Response body
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client for Agentuity Platform
|
|
3
|
+
*
|
|
4
|
+
* Handles HTTP requests to the API with automatic error parsing and User-Agent headers.
|
|
5
|
+
*
|
|
6
|
+
* Error handling:
|
|
7
|
+
* - UPGRADE_REQUIRED (409): Throws UpgradeRequiredError
|
|
8
|
+
* - Other errors: Throws Error with API message or status text
|
|
9
|
+
*
|
|
10
|
+
* See api-errors.md for full documentation.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { Config } from './types';
|
|
14
|
+
import { getVersion, getRevision } from './version';
|
|
15
|
+
|
|
16
|
+
interface APIErrorResponse {
|
|
17
|
+
success: boolean;
|
|
18
|
+
code?: string;
|
|
19
|
+
message: string;
|
|
20
|
+
details?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getUserAgent(config?: Config | null): string {
|
|
24
|
+
// If we're skipping version check, send "dev" to signal the server to skip too
|
|
25
|
+
let version = getVersion();
|
|
26
|
+
if (shouldSkipVersionCheck(config)) {
|
|
27
|
+
version = 'dev';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const revision = getRevision();
|
|
31
|
+
return `Agentuity CLI/${version} (${revision})`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function shouldSkipVersionCheck(config?: Config | null): boolean {
|
|
35
|
+
// Priority order:
|
|
36
|
+
// 1. CLI flag (set via env var in cli.ts)
|
|
37
|
+
// 2. Environment variable
|
|
38
|
+
// 3. Config override
|
|
39
|
+
// 4. Auto-detection (dev/0.0.x versions)
|
|
40
|
+
|
|
41
|
+
// Skip if environment variable is set (includes CLI flag)
|
|
42
|
+
if (
|
|
43
|
+
process.env.AGENTUITY_SKIP_VERSION_CHECK === '1' ||
|
|
44
|
+
process.env.AGENTUITY_SKIP_VERSION_CHECK === 'true'
|
|
45
|
+
) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Check config overrides
|
|
50
|
+
const overrides = config?.overrides as { skip_version_check?: boolean } | undefined;
|
|
51
|
+
if (overrides?.skip_version_check === true) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Skip if version is 'dev' or starts with '0.0.' (pre-release/local development)
|
|
56
|
+
const version = getVersion();
|
|
57
|
+
if (version === 'dev' || version.startsWith('0.0.')) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class UpgradeRequiredError extends Error {
|
|
65
|
+
constructor(message: string) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = 'UpgradeRequiredError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class APIClient {
|
|
72
|
+
constructor(
|
|
73
|
+
private baseUrl: string,
|
|
74
|
+
private apiKey?: string,
|
|
75
|
+
private config?: Config | null
|
|
76
|
+
) {}
|
|
77
|
+
|
|
78
|
+
async request<T>(method: string, endpoint: string, body?: unknown): Promise<T> {
|
|
79
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
80
|
+
const headers: Record<string, string> = {
|
|
81
|
+
'Content-Type': 'application/json',
|
|
82
|
+
'User-Agent': getUserAgent(this.config),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
if (this.apiKey) {
|
|
86
|
+
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const response = await fetch(url, {
|
|
90
|
+
method,
|
|
91
|
+
headers,
|
|
92
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if (!response.ok) {
|
|
96
|
+
const responseBody = await response.text();
|
|
97
|
+
|
|
98
|
+
// Try to parse error response
|
|
99
|
+
let errorData: APIErrorResponse | null = null;
|
|
100
|
+
try {
|
|
101
|
+
errorData = JSON.parse(responseBody) as APIErrorResponse;
|
|
102
|
+
} catch {
|
|
103
|
+
// Not JSON, ignore
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (process.env.DEBUG) {
|
|
107
|
+
// Sanitize headers to avoid leaking API keys
|
|
108
|
+
const sanitizedHeaders = { ...headers };
|
|
109
|
+
for (const key in sanitizedHeaders) {
|
|
110
|
+
if (key.toLowerCase() === 'authorization') {
|
|
111
|
+
sanitizedHeaders[key] = 'REDACTED';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
console.error('API Error Details:');
|
|
116
|
+
console.error(' URL:', url);
|
|
117
|
+
console.error(' Method:', method);
|
|
118
|
+
console.error(' Status:', response.status, response.statusText);
|
|
119
|
+
console.error(' Headers:', JSON.stringify(sanitizedHeaders, null, 2));
|
|
120
|
+
console.error(' Response:', responseBody);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Check for UPGRADE_REQUIRED error
|
|
124
|
+
if (errorData?.code === 'UPGRADE_REQUIRED') {
|
|
125
|
+
// Skip version check in development
|
|
126
|
+
if (shouldSkipVersionCheck(this.config)) {
|
|
127
|
+
if (process.env.DEBUG) {
|
|
128
|
+
console.error(
|
|
129
|
+
'[DEBUG] Skipping version check (flag/env/config override or dev mode)'
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
// Continue as if there was no error - the server should still process the request
|
|
133
|
+
// but we'll throw a different error since we can't continue with a 409
|
|
134
|
+
throw new Error('Version check skipped, but request failed. Try upgrading the CLI.');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
throw new UpgradeRequiredError(
|
|
138
|
+
errorData.message || 'Please upgrade to the latest version of the CLI'
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Throw with message from API if available
|
|
143
|
+
if (errorData?.message) {
|
|
144
|
+
throw new Error(errorData.message);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
throw new Error(`API error: ${response.status} ${response.statusText}`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Successful response; handle empty bodies (e.g., 204 No Content)
|
|
151
|
+
if (response.status === 204) {
|
|
152
|
+
return undefined as T;
|
|
153
|
+
}
|
|
154
|
+
const contentLength = response.headers.get('content-length');
|
|
155
|
+
if (contentLength === '0') {
|
|
156
|
+
return undefined as T;
|
|
157
|
+
}
|
|
158
|
+
return response.json() as Promise<T>;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function getAPIBaseURL(config?: Config | null): string {
|
|
163
|
+
if (process.env.AGENTUITY_API_URL) {
|
|
164
|
+
return process.env.AGENTUITY_API_URL;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const overrides = config?.overrides as { api_url?: string } | undefined;
|
|
168
|
+
if (overrides?.api_url) {
|
|
169
|
+
return overrides.api_url;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return 'https://api.agentuity.com';
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function getAppBaseURL(config?: Config | null): string {
|
|
176
|
+
if (process.env.AGENTUITY_APP_URL) {
|
|
177
|
+
return process.env.AGENTUITY_APP_URL;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const overrides = config?.overrides as { app_url?: string } | undefined;
|
|
181
|
+
if (overrides?.app_url) {
|
|
182
|
+
return overrides.app_url;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return 'https://app.agentuity.com';
|
|
186
|
+
}
|
package/src/auth.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { getDefaultConfigDir, getAuth } from './config';
|
|
3
|
+
import { getCommand } from './command-prefix';
|
|
4
|
+
import type { CommandContext, AuthData } from './types';
|
|
5
|
+
import * as tui from './tui';
|
|
6
|
+
|
|
7
|
+
export function isTTY(): boolean {
|
|
8
|
+
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function hasLoggedInBefore(): boolean {
|
|
12
|
+
const configDir = getDefaultConfigDir();
|
|
13
|
+
return existsSync(configDir);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function isAuthenticated(): Promise<boolean> {
|
|
17
|
+
const auth = await getAuth();
|
|
18
|
+
if (!auth) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return auth.expires > new Date();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function requireAuth(ctx: CommandContext<false>): Promise<AuthData> {
|
|
25
|
+
const { logger } = ctx;
|
|
26
|
+
const auth = await getAuth();
|
|
27
|
+
|
|
28
|
+
if (auth && auth.expires > new Date()) {
|
|
29
|
+
return auth;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const loginCmd = getCommand('auth login');
|
|
33
|
+
const hasConfig = hasLoggedInBefore();
|
|
34
|
+
|
|
35
|
+
if (!isTTY()) {
|
|
36
|
+
if (hasConfig) {
|
|
37
|
+
logger.fatal(
|
|
38
|
+
`You are not currently logged in or your session has expired.\n` +
|
|
39
|
+
`Use "${loginCmd}" to login to Agentuity`
|
|
40
|
+
);
|
|
41
|
+
} else {
|
|
42
|
+
logger.fatal(
|
|
43
|
+
`Authentication required.\n` + `Use "${loginCmd}" to create an account or login`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Interactive mode - prompt user to login
|
|
49
|
+
tui.newline();
|
|
50
|
+
tui.warning(
|
|
51
|
+
hasConfig
|
|
52
|
+
? 'You are not currently logged in or your session has expired.'
|
|
53
|
+
: 'Authentication required to continue.'
|
|
54
|
+
);
|
|
55
|
+
tui.newline();
|
|
56
|
+
|
|
57
|
+
const shouldLogin = await tui.confirm(
|
|
58
|
+
hasConfig ? 'Would you like to login now?' : 'Would you like to create an account or login?',
|
|
59
|
+
true
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (!shouldLogin) {
|
|
63
|
+
logger.fatal(`Authentication required. Run "${loginCmd}" when you're ready to continue.`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Import and run login flow
|
|
67
|
+
const { loginCommand } = await import('./cmd/auth/login');
|
|
68
|
+
await loginCommand.handler(ctx);
|
|
69
|
+
|
|
70
|
+
// After login completes, verify we have auth
|
|
71
|
+
const newAuth = await getAuth();
|
|
72
|
+
if (!newAuth || newAuth.expires <= new Date()) {
|
|
73
|
+
return logger.fatal('Login was not completed successfully.');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return newAuth;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function withAuth<TArgs extends unknown[]>(
|
|
80
|
+
ctx: CommandContext<false>,
|
|
81
|
+
handler: (ctx: CommandContext<true>, ...args: TArgs) => Promise<void> | void
|
|
82
|
+
): (...args: TArgs) => Promise<void> {
|
|
83
|
+
return async (...args: TArgs) => {
|
|
84
|
+
const auth = await requireAuth(ctx);
|
|
85
|
+
const authenticatedCtx: CommandContext<true> = {
|
|
86
|
+
...ctx,
|
|
87
|
+
auth,
|
|
88
|
+
};
|
|
89
|
+
return handler(authenticatedCtx, ...args);
|
|
90
|
+
};
|
|
91
|
+
}
|
package/src/banner.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function showBanner(version: string): void {
|
|
2
|
+
const CYAN = Bun.color('cyan', 'ansi-16m');
|
|
3
|
+
const RESET = '\x1b[0m';
|
|
4
|
+
|
|
5
|
+
const width = 52; // Content width between pipes
|
|
6
|
+
const versionLabel = ' Version: '; // Include leading space
|
|
7
|
+
const versionPadding = width - versionLabel.length - 1; // Subtract 1 for the space before closing pipe
|
|
8
|
+
|
|
9
|
+
const lines = [
|
|
10
|
+
'╭────────────────────────────────────────────────────╮',
|
|
11
|
+
'│ ⨺ Agentuity Build, manage and deploy AI agents │',
|
|
12
|
+
'│ │',
|
|
13
|
+
`│${versionLabel}${version.padEnd(versionPadding)} │`,
|
|
14
|
+
'│ Docs: https://agentuity.dev │',
|
|
15
|
+
'│ Community: https://discord.gg/agentuity │',
|
|
16
|
+
'│ Dashboard: https://app.agentuity.com │',
|
|
17
|
+
'╰────────────────────────────────────────────────────╯',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
console.log('');
|
|
21
|
+
lines.forEach((line) => console.log(CYAN + line + RESET));
|
|
22
|
+
console.log('');
|
|
23
|
+
}
|