@agentuity/cli 0.0.110 → 0.0.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +19 -4
- package/dist/cli.js.map +1 -1
- package/dist/cmd/build/vite/agent-discovery.d.ts +1 -1
- package/dist/cmd/build/vite/agent-discovery.d.ts.map +1 -1
- package/dist/cmd/build/vite/agent-discovery.js +3 -3
- package/dist/cmd/build/vite/agent-discovery.js.map +1 -1
- package/dist/cmd/build/vite/index.js +1 -1
- package/dist/cmd/build/vite/index.js.map +1 -1
- package/dist/cmd/build/vite/metadata-generator.js +1 -1
- package/dist/cmd/build/vite/metadata-generator.js.map +1 -1
- package/dist/cmd/build/vite/registry-generator.d.ts +1 -1
- package/dist/cmd/build/vite/registry-generator.d.ts.map +1 -1
- package/dist/cmd/build/vite/registry-generator.js +70 -23
- package/dist/cmd/build/vite/registry-generator.js.map +1 -1
- package/dist/cmd/build/vite/route-discovery.d.ts +6 -0
- package/dist/cmd/build/vite/route-discovery.d.ts.map +1 -1
- package/dist/cmd/build/vite/route-discovery.js +19 -0
- package/dist/cmd/build/vite/route-discovery.js.map +1 -1
- package/dist/cmd/build/vite/vite-builder.js +1 -1
- package/dist/cmd/build/vite/vite-builder.js.map +1 -1
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deploy.js +63 -1
- package/dist/cmd/cloud/deploy.js.map +1 -1
- package/dist/cmd/cloud/sandbox/create.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/create.js +18 -0
- package/dist/cmd/cloud/sandbox/create.js.map +1 -1
- package/dist/cmd/cloud/sandbox/delete.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/delete.js +2 -6
- package/dist/cmd/cloud/sandbox/delete.js.map +1 -1
- package/dist/cmd/cloud/sandbox/download.d.ts +3 -0
- package/dist/cmd/cloud/sandbox/download.d.ts.map +1 -0
- package/dist/cmd/cloud/sandbox/download.js +89 -0
- package/dist/cmd/cloud/sandbox/download.js.map +1 -0
- package/dist/cmd/cloud/sandbox/env.d.ts +3 -0
- package/dist/cmd/cloud/sandbox/env.d.ts.map +1 -0
- package/dist/cmd/cloud/sandbox/env.js +90 -0
- package/dist/cmd/cloud/sandbox/env.js.map +1 -0
- package/dist/cmd/cloud/sandbox/get.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/get.js +5 -0
- package/dist/cmd/cloud/sandbox/get.js.map +1 -1
- package/dist/cmd/cloud/sandbox/index.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/index.js +14 -0
- package/dist/cmd/cloud/sandbox/index.js.map +1 -1
- package/dist/cmd/cloud/sandbox/ls.d.ts +3 -0
- package/dist/cmd/cloud/sandbox/ls.d.ts.map +1 -0
- package/dist/cmd/cloud/sandbox/ls.js +119 -0
- package/dist/cmd/cloud/sandbox/ls.js.map +1 -0
- package/dist/cmd/cloud/sandbox/mkdir.d.ts +3 -0
- package/dist/cmd/cloud/sandbox/mkdir.d.ts.map +1 -0
- package/dist/cmd/cloud/sandbox/mkdir.js +59 -0
- package/dist/cmd/cloud/sandbox/mkdir.js.map +1 -0
- package/dist/cmd/cloud/sandbox/rm.d.ts +3 -0
- package/dist/cmd/cloud/sandbox/rm.d.ts.map +1 -0
- package/dist/cmd/cloud/sandbox/rm.js +45 -0
- package/dist/cmd/cloud/sandbox/rm.js.map +1 -0
- package/dist/cmd/cloud/sandbox/rmdir.d.ts +3 -0
- package/dist/cmd/cloud/sandbox/rmdir.d.ts.map +1 -0
- package/dist/cmd/cloud/sandbox/rmdir.js +59 -0
- package/dist/cmd/cloud/sandbox/rmdir.js.map +1 -0
- package/dist/cmd/cloud/sandbox/snapshot/create.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/snapshot/create.js +0 -2
- package/dist/cmd/cloud/sandbox/snapshot/create.js.map +1 -1
- package/dist/cmd/cloud/sandbox/snapshot/get.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/snapshot/get.js +0 -2
- package/dist/cmd/cloud/sandbox/snapshot/get.js.map +1 -1
- package/dist/cmd/cloud/sandbox/snapshot/list.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/snapshot/list.js +0 -3
- package/dist/cmd/cloud/sandbox/snapshot/list.js.map +1 -1
- package/dist/cmd/cloud/sandbox/upload.d.ts +3 -0
- package/dist/cmd/cloud/sandbox/upload.d.ts.map +1 -0
- package/dist/cmd/cloud/sandbox/upload.js +77 -0
- package/dist/cmd/cloud/sandbox/upload.js.map +1 -0
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/dev/index.js +17 -8
- package/dist/cmd/dev/index.js.map +1 -1
- package/dist/cmd/dev/sync.d.ts.map +1 -1
- package/dist/cmd/dev/sync.js +8 -14
- package/dist/cmd/dev/sync.js.map +1 -1
- package/dist/cmd/git/account/add.d.ts +17 -0
- package/dist/cmd/git/account/add.d.ts.map +1 -0
- package/dist/cmd/git/account/add.js +244 -0
- package/dist/cmd/git/account/add.js.map +1 -0
- package/dist/cmd/git/account/index.d.ts +3 -0
- package/dist/cmd/git/account/index.d.ts.map +1 -0
- package/dist/cmd/git/account/index.js +11 -0
- package/dist/cmd/git/account/index.js.map +1 -0
- package/dist/cmd/git/account/list.d.ts +2 -0
- package/dist/cmd/git/account/list.d.ts.map +1 -0
- package/dist/cmd/git/account/list.js +111 -0
- package/dist/cmd/git/account/list.js.map +1 -0
- package/dist/cmd/git/account/remove.d.ts +2 -0
- package/dist/cmd/git/account/remove.d.ts.map +1 -0
- package/dist/cmd/git/account/remove.js +171 -0
- package/dist/cmd/git/account/remove.js.map +1 -0
- package/dist/cmd/git/index.d.ts +3 -0
- package/dist/cmd/git/index.d.ts.map +1 -0
- package/dist/cmd/git/index.js +19 -0
- package/dist/cmd/git/index.js.map +1 -0
- package/dist/cmd/git/link.d.ts +32 -0
- package/dist/cmd/git/link.d.ts.map +1 -0
- package/dist/cmd/git/link.js +357 -0
- package/dist/cmd/git/link.js.map +1 -0
- package/dist/cmd/git/list.d.ts +2 -0
- package/dist/cmd/git/list.d.ts.map +1 -0
- package/dist/cmd/git/list.js +137 -0
- package/dist/cmd/git/list.js.map +1 -0
- package/dist/cmd/git/status.d.ts +2 -0
- package/dist/cmd/git/status.d.ts.map +1 -0
- package/dist/cmd/git/status.js +119 -0
- package/dist/cmd/git/status.js.map +1 -0
- package/dist/cmd/git/unlink.d.ts +2 -0
- package/dist/cmd/git/unlink.d.ts.map +1 -0
- package/dist/cmd/git/unlink.js +98 -0
- package/dist/cmd/git/unlink.js.map +1 -0
- package/dist/cmd/index.d.ts.map +1 -1
- package/dist/cmd/index.js +2 -0
- package/dist/cmd/index.js.map +1 -1
- package/dist/cmd/integration/api.d.ts +61 -0
- package/dist/cmd/integration/api.d.ts.map +1 -0
- package/dist/cmd/integration/api.js +176 -0
- package/dist/cmd/integration/api.js.map +1 -0
- package/dist/cmd/integration/github/connect.d.ts +2 -0
- package/dist/cmd/integration/github/connect.d.ts.map +1 -0
- package/dist/cmd/integration/github/connect.js +197 -0
- package/dist/cmd/integration/github/connect.js.map +1 -0
- package/dist/cmd/integration/github/disconnect.d.ts +2 -0
- package/dist/cmd/integration/github/disconnect.d.ts.map +1 -0
- package/dist/cmd/integration/github/disconnect.js +121 -0
- package/dist/cmd/integration/github/disconnect.js.map +1 -0
- package/dist/cmd/integration/github/index.d.ts +2 -0
- package/dist/cmd/integration/github/index.d.ts.map +1 -0
- package/dist/cmd/integration/github/index.js +21 -0
- package/dist/cmd/integration/github/index.js.map +1 -0
- package/dist/cmd/integration/index.d.ts +2 -0
- package/dist/cmd/integration/index.d.ts.map +1 -0
- package/dist/cmd/integration/index.js +16 -0
- package/dist/cmd/integration/index.js.map +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +24 -0
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -0
- package/dist/errors.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/package.json +6 -6
- package/src/cli.ts +20 -4
- package/src/cmd/build/vite/agent-discovery.ts +4 -4
- package/src/cmd/build/vite/index.ts +1 -1
- package/src/cmd/build/vite/metadata-generator.ts +1 -1
- package/src/cmd/build/vite/registry-generator.ts +78 -24
- package/src/cmd/build/vite/route-discovery.ts +20 -0
- package/src/cmd/build/vite/vite-builder.ts +1 -1
- package/src/cmd/cloud/deploy.ts +78 -1
- package/src/cmd/cloud/sandbox/create.ts +22 -0
- package/src/cmd/cloud/sandbox/delete.ts +2 -6
- package/src/cmd/cloud/sandbox/download.ts +96 -0
- package/src/cmd/cloud/sandbox/env.ts +104 -0
- package/src/cmd/cloud/sandbox/get.ts +5 -0
- package/src/cmd/cloud/sandbox/index.ts +14 -0
- package/src/cmd/cloud/sandbox/ls.ts +126 -0
- package/src/cmd/cloud/sandbox/mkdir.ts +65 -0
- package/src/cmd/cloud/sandbox/rm.ts +51 -0
- package/src/cmd/cloud/sandbox/rmdir.ts +65 -0
- package/src/cmd/cloud/sandbox/snapshot/create.ts +0 -2
- package/src/cmd/cloud/sandbox/snapshot/get.ts +0 -2
- package/src/cmd/cloud/sandbox/snapshot/list.ts +0 -3
- package/src/cmd/cloud/sandbox/upload.ts +83 -0
- package/src/cmd/dev/index.ts +32 -19
- package/src/cmd/dev/sync.ts +26 -30
- package/src/cmd/git/account/add.ts +317 -0
- package/src/cmd/git/account/index.ts +12 -0
- package/src/cmd/git/account/list.ts +139 -0
- package/src/cmd/git/account/remove.ts +212 -0
- package/src/cmd/git/index.ts +20 -0
- package/src/cmd/git/link.ts +468 -0
- package/src/cmd/git/list.ts +161 -0
- package/src/cmd/git/status.ts +144 -0
- package/src/cmd/git/unlink.ts +117 -0
- package/src/cmd/index.ts +2 -0
- package/src/cmd/integration/api.ts +379 -0
- package/src/cmd/integration/github/connect.ts +242 -0
- package/src/cmd/integration/github/disconnect.ts +149 -0
- package/src/cmd/integration/github/index.ts +21 -0
- package/src/cmd/integration/index.ts +16 -0
- package/src/config.ts +34 -0
- package/src/errors.ts +7 -0
- package/src/types.ts +4 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIResponseSchema } from '@agentuity/server';
|
|
3
|
+
import type { APIClient } from '../../api';
|
|
4
|
+
import { StructuredError } from '@agentuity/core';
|
|
5
|
+
|
|
6
|
+
const GithubStartDataSchema = z.object({
|
|
7
|
+
shortId: z.string(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const GithubIntegrationSchema = z.object({
|
|
11
|
+
id: z.string(),
|
|
12
|
+
githubAccountName: z.string(),
|
|
13
|
+
githubAccountType: z.enum(['user', 'org']),
|
|
14
|
+
connectedBy: z.string(),
|
|
15
|
+
connectedAt: z.string(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const GithubStatusDataSchema = z.object({
|
|
19
|
+
connected: z.boolean(),
|
|
20
|
+
integrations: z.array(GithubIntegrationSchema).optional(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export interface GithubIntegration {
|
|
24
|
+
id: string;
|
|
25
|
+
githubAccountName: string;
|
|
26
|
+
githubAccountType: 'user' | 'org';
|
|
27
|
+
connectedBy: string;
|
|
28
|
+
connectedAt: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface GithubIntegrationStartResult {
|
|
32
|
+
shortId: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface GithubIntegrationStatusResult {
|
|
36
|
+
connected: boolean;
|
|
37
|
+
integrations: GithubIntegration[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const GithubIntegrationStartError = StructuredError(
|
|
41
|
+
'GithubIntegrationStartError',
|
|
42
|
+
'Error starting GitHub integration flow'
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export async function startGithubIntegration(
|
|
46
|
+
apiClient: APIClient,
|
|
47
|
+
orgId: string
|
|
48
|
+
): Promise<GithubIntegrationStartResult> {
|
|
49
|
+
const resp = await apiClient.get(
|
|
50
|
+
`/cli/github/start?orgId=${encodeURIComponent(orgId)}`,
|
|
51
|
+
APIResponseSchema(GithubStartDataSchema)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (!resp.success) {
|
|
55
|
+
throw new GithubIntegrationStartError();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!resp.data) {
|
|
59
|
+
throw new GithubIntegrationStartError();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { shortId: resp.data.shortId };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const GithubIntegrationStatusError = StructuredError(
|
|
66
|
+
'GithubIntegrationStatusError',
|
|
67
|
+
'Error checking GitHub integration status'
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
export async function getGithubIntegrationStatus(
|
|
71
|
+
apiClient: APIClient,
|
|
72
|
+
orgId: string
|
|
73
|
+
): Promise<GithubIntegrationStatusResult> {
|
|
74
|
+
const resp = await apiClient.get(
|
|
75
|
+
`/cli/github/status?orgId=${encodeURIComponent(orgId)}`,
|
|
76
|
+
APIResponseSchema(GithubStatusDataSchema)
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (!resp.success) {
|
|
80
|
+
throw new GithubIntegrationStatusError();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!resp.data) {
|
|
84
|
+
throw new GithubIntegrationStatusError();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
connected: resp.data.connected,
|
|
89
|
+
integrations: resp.data.integrations ?? [],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const GithubDisconnectDataSchema = z.object({
|
|
94
|
+
disconnected: z.boolean(),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export interface GithubDisconnectResult {
|
|
98
|
+
disconnected: boolean;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const GithubDisconnectError = StructuredError(
|
|
102
|
+
'GithubDisconnectError',
|
|
103
|
+
'Error disconnecting GitHub integration'
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
export async function disconnectGithubIntegration(
|
|
107
|
+
apiClient: APIClient,
|
|
108
|
+
orgId: string,
|
|
109
|
+
integrationId: string
|
|
110
|
+
): Promise<GithubDisconnectResult> {
|
|
111
|
+
const resp = await apiClient.delete(
|
|
112
|
+
`/cli/github/disconnect?orgId=${encodeURIComponent(orgId)}&integrationId=${encodeURIComponent(integrationId)}`,
|
|
113
|
+
APIResponseSchema(GithubDisconnectDataSchema)
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
if (!resp.success) {
|
|
117
|
+
throw new GithubDisconnectError();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!resp.data) {
|
|
121
|
+
throw new GithubDisconnectError();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { disconnected: resp.data.disconnected };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Existing integrations
|
|
128
|
+
|
|
129
|
+
const GithubExistingIntegrationSchema = z.object({
|
|
130
|
+
id: z.string(),
|
|
131
|
+
integrationId: z.string().nullable(),
|
|
132
|
+
orgId: z.string(),
|
|
133
|
+
orgName: z.string(),
|
|
134
|
+
githubAccountName: z.string(),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const GithubExistingDataSchema = z.object({
|
|
138
|
+
integrations: z.array(GithubExistingIntegrationSchema),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
export interface ExistingGithubIntegration {
|
|
142
|
+
id: string;
|
|
143
|
+
integrationId: string | null;
|
|
144
|
+
orgId: string;
|
|
145
|
+
orgName: string;
|
|
146
|
+
githubAccountName: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const GithubExistingError = StructuredError(
|
|
150
|
+
'GithubExistingError',
|
|
151
|
+
'Error fetching existing GitHub integrations'
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
export async function getExistingGithubIntegrations(
|
|
155
|
+
apiClient: APIClient,
|
|
156
|
+
excludeOrgId?: string
|
|
157
|
+
): Promise<ExistingGithubIntegration[]> {
|
|
158
|
+
const query = excludeOrgId ? `?excludeOrgId=${encodeURIComponent(excludeOrgId)}` : '';
|
|
159
|
+
const resp = await apiClient.get(
|
|
160
|
+
`/cli/github/existing${query}`,
|
|
161
|
+
APIResponseSchema(GithubExistingDataSchema)
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
if (!resp.success || !resp.data) {
|
|
165
|
+
throw new GithubExistingError();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return resp.data.integrations;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Copy integration
|
|
172
|
+
|
|
173
|
+
const GithubCopyDataSchema = z.object({
|
|
174
|
+
copied: z.boolean(),
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const GithubCopyError = StructuredError('GithubCopyError', 'Error copying GitHub integration');
|
|
178
|
+
|
|
179
|
+
export async function copyGithubIntegration(
|
|
180
|
+
apiClient: APIClient,
|
|
181
|
+
fromOrgId: string,
|
|
182
|
+
toOrgId: string
|
|
183
|
+
): Promise<boolean> {
|
|
184
|
+
const resp = await apiClient.post(
|
|
185
|
+
'/cli/github/copy',
|
|
186
|
+
{ fromOrgId, toOrgId },
|
|
187
|
+
APIResponseSchema(GithubCopyDataSchema)
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
if (!resp.success || !resp.data) {
|
|
191
|
+
throw new GithubCopyError();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return resp.data.copied;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Polling
|
|
198
|
+
|
|
199
|
+
const PollForGithubIntegrationError = StructuredError('PollForGithubIntegrationError');
|
|
200
|
+
const PollForGithubIntegrationTimeout = StructuredError(
|
|
201
|
+
'PollForGithubIntegrationTimeout',
|
|
202
|
+
'Timed out waiting for GitHub integration. Aborting.'
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
export async function pollForGithubIntegration(
|
|
206
|
+
apiClient: APIClient,
|
|
207
|
+
orgId: string,
|
|
208
|
+
initialCount: number,
|
|
209
|
+
timeoutMs = 600000 // 10 minutes
|
|
210
|
+
): Promise<GithubIntegrationStatusResult> {
|
|
211
|
+
const started = Date.now();
|
|
212
|
+
let delay = 2000; // Start with 2 seconds
|
|
213
|
+
const maxDelay = 10000; // Cap at 10 seconds
|
|
214
|
+
|
|
215
|
+
while (Date.now() - started < timeoutMs) {
|
|
216
|
+
const resp = await apiClient.get(
|
|
217
|
+
`/cli/github/status?orgId=${encodeURIComponent(orgId)}`,
|
|
218
|
+
APIResponseSchema(GithubStatusDataSchema)
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
if (!resp.success || !resp.data) {
|
|
222
|
+
throw new PollForGithubIntegrationError();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const currentCount = resp.data.integrations?.length ?? 0;
|
|
226
|
+
if (currentCount > initialCount) {
|
|
227
|
+
return {
|
|
228
|
+
connected: true,
|
|
229
|
+
integrations: resp.data.integrations ?? [],
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
await Bun.sleep(delay);
|
|
234
|
+
delay = Math.min(delay * 1.5, maxDelay);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
throw new PollForGithubIntegrationTimeout();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Project linking
|
|
241
|
+
|
|
242
|
+
const GithubRepoSchema = z.object({
|
|
243
|
+
id: z.number(),
|
|
244
|
+
name: z.string(),
|
|
245
|
+
fullName: z.string(),
|
|
246
|
+
private: z.boolean(),
|
|
247
|
+
defaultBranch: z.string(),
|
|
248
|
+
integrationId: z.string(),
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const GithubReposDataSchema = z.object({
|
|
252
|
+
repos: z.array(GithubRepoSchema),
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
export interface GithubRepo {
|
|
256
|
+
id: number;
|
|
257
|
+
name: string;
|
|
258
|
+
fullName: string;
|
|
259
|
+
private: boolean;
|
|
260
|
+
defaultBranch: string;
|
|
261
|
+
integrationId: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const GithubReposError = StructuredError('GithubReposError', 'Error fetching GitHub repositories');
|
|
265
|
+
|
|
266
|
+
export async function listGithubRepos(
|
|
267
|
+
apiClient: APIClient,
|
|
268
|
+
orgId: string,
|
|
269
|
+
integrationId?: string
|
|
270
|
+
): Promise<GithubRepo[]> {
|
|
271
|
+
let url = `/cli/github/repos?orgId=${encodeURIComponent(orgId)}`;
|
|
272
|
+
if (integrationId) {
|
|
273
|
+
url += `&integrationId=${encodeURIComponent(integrationId)}`;
|
|
274
|
+
}
|
|
275
|
+
const resp = await apiClient.get(url, APIResponseSchema(GithubReposDataSchema));
|
|
276
|
+
|
|
277
|
+
if (!resp.success || !resp.data) {
|
|
278
|
+
throw new GithubReposError();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return resp.data.repos;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const ProjectLinkDataSchema = z.object({
|
|
285
|
+
linked: z.boolean(),
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
export interface LinkProjectOptions {
|
|
289
|
+
projectId: string;
|
|
290
|
+
repoFullName: string;
|
|
291
|
+
branch: string;
|
|
292
|
+
autoDeploy: boolean;
|
|
293
|
+
previewDeploy: boolean;
|
|
294
|
+
directory?: string;
|
|
295
|
+
integrationId?: string;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const ProjectLinkError = StructuredError('ProjectLinkError', 'Error linking project to repository');
|
|
299
|
+
|
|
300
|
+
export async function linkProjectToRepo(
|
|
301
|
+
apiClient: APIClient,
|
|
302
|
+
options: LinkProjectOptions
|
|
303
|
+
): Promise<boolean> {
|
|
304
|
+
const resp = await apiClient.post(
|
|
305
|
+
'/cli/github/link',
|
|
306
|
+
options,
|
|
307
|
+
APIResponseSchema(ProjectLinkDataSchema)
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
if (!resp.success || !resp.data) {
|
|
311
|
+
throw new ProjectLinkError();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return resp.data.linked;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const ProjectUnlinkDataSchema = z.object({
|
|
318
|
+
unlinked: z.boolean(),
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
const ProjectUnlinkError = StructuredError(
|
|
322
|
+
'ProjectUnlinkError',
|
|
323
|
+
'Error unlinking project from repository'
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
export async function unlinkProjectFromRepo(
|
|
327
|
+
apiClient: APIClient,
|
|
328
|
+
projectId: string
|
|
329
|
+
): Promise<boolean> {
|
|
330
|
+
const resp = await apiClient.delete(
|
|
331
|
+
`/cli/github/unlink?projectId=${encodeURIComponent(projectId)}`,
|
|
332
|
+
APIResponseSchema(ProjectUnlinkDataSchema)
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
if (!resp.success || !resp.data) {
|
|
336
|
+
throw new ProjectUnlinkError();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return resp.data.unlinked;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const ProjectGithubStatusSchema = z.object({
|
|
343
|
+
linked: z.boolean(),
|
|
344
|
+
repoFullName: z.string().optional(),
|
|
345
|
+
branch: z.string().optional(),
|
|
346
|
+
autoDeploy: z.boolean().optional(),
|
|
347
|
+
previewDeploy: z.boolean().optional(),
|
|
348
|
+
directory: z.string().optional(),
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
export interface ProjectGithubStatus {
|
|
352
|
+
linked: boolean;
|
|
353
|
+
repoFullName?: string;
|
|
354
|
+
branch?: string;
|
|
355
|
+
autoDeploy?: boolean;
|
|
356
|
+
previewDeploy?: boolean;
|
|
357
|
+
directory?: string;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const ProjectGithubStatusError = StructuredError(
|
|
361
|
+
'ProjectGithubStatusError',
|
|
362
|
+
'Error fetching project GitHub status'
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
export async function getProjectGithubStatus(
|
|
366
|
+
apiClient: APIClient,
|
|
367
|
+
projectId: string
|
|
368
|
+
): Promise<ProjectGithubStatus> {
|
|
369
|
+
const resp = await apiClient.get(
|
|
370
|
+
`/cli/github/project-status?projectId=${encodeURIComponent(projectId)}`,
|
|
371
|
+
APIResponseSchema(ProjectGithubStatusSchema)
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
if (!resp.success || !resp.data) {
|
|
375
|
+
throw new ProjectGithubStatusError();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return resp.data;
|
|
379
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { createSubcommand } from '../../../types';
|
|
2
|
+
import * as tui from '../../../tui';
|
|
3
|
+
import { getCommand } from '../../../command-prefix';
|
|
4
|
+
import { getAPIBaseURL } from '../../../api';
|
|
5
|
+
import { ErrorCode } from '../../../errors';
|
|
6
|
+
import { listOrganizations } from '@agentuity/server';
|
|
7
|
+
import enquirer from 'enquirer';
|
|
8
|
+
import {
|
|
9
|
+
startGithubIntegration,
|
|
10
|
+
pollForGithubIntegration,
|
|
11
|
+
getGithubIntegrationStatus,
|
|
12
|
+
getExistingGithubIntegrations,
|
|
13
|
+
copyGithubIntegration,
|
|
14
|
+
} from '../api';
|
|
15
|
+
|
|
16
|
+
export const connectSubcommand = createSubcommand({
|
|
17
|
+
name: 'connect',
|
|
18
|
+
description: 'Connect your GitHub account to enable automatic deployments',
|
|
19
|
+
tags: ['mutating', 'creates-resource', 'slow', 'api-intensive'],
|
|
20
|
+
idempotent: false,
|
|
21
|
+
requires: { auth: true, apiClient: true },
|
|
22
|
+
examples: [
|
|
23
|
+
{
|
|
24
|
+
command: getCommand('integration github connect'),
|
|
25
|
+
description: 'Connect GitHub to your organization',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
|
|
29
|
+
async handler(ctx) {
|
|
30
|
+
const { logger, apiClient } = ctx;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
// Fetch organizations
|
|
34
|
+
const orgs = await tui.spinner({
|
|
35
|
+
message: 'Fetching organizations...',
|
|
36
|
+
clearOnSuccess: true,
|
|
37
|
+
callback: () => listOrganizations(apiClient),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (orgs.length === 0) {
|
|
41
|
+
tui.fatal('No organizations found for your account');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Check GitHub status for each org
|
|
45
|
+
const orgStatuses = await tui.spinner({
|
|
46
|
+
message: 'Checking GitHub integration status...',
|
|
47
|
+
clearOnSuccess: true,
|
|
48
|
+
callback: async () => {
|
|
49
|
+
const statuses = await Promise.all(
|
|
50
|
+
orgs.map(async (org) => {
|
|
51
|
+
const status = await getGithubIntegrationStatus(apiClient, org.id);
|
|
52
|
+
return {
|
|
53
|
+
...org,
|
|
54
|
+
connected: status.connected,
|
|
55
|
+
integrations: status.integrations,
|
|
56
|
+
};
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
return statuses;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Sort orgs alphabetically
|
|
64
|
+
const sortedOrgs = [...orgStatuses].sort((a, b) => a.name.localeCompare(b.name));
|
|
65
|
+
|
|
66
|
+
// Build choices showing integration count
|
|
67
|
+
const choices = sortedOrgs.map((org) => {
|
|
68
|
+
const count = org.integrations.length;
|
|
69
|
+
const suffix =
|
|
70
|
+
count > 0 ? tui.muted(` (${count} GitHub account${count > 1 ? 's' : ''})`) : '';
|
|
71
|
+
return {
|
|
72
|
+
name: org.name,
|
|
73
|
+
message: `${org.name}${suffix}`,
|
|
74
|
+
value: org.id,
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Show picker
|
|
79
|
+
const response = await enquirer.prompt<{ orgName: string }>({
|
|
80
|
+
type: 'select',
|
|
81
|
+
name: 'orgName',
|
|
82
|
+
message: 'Select an organization to connect',
|
|
83
|
+
choices,
|
|
84
|
+
result(name: string) {
|
|
85
|
+
// @ts-expect-error - this.map exists at runtime
|
|
86
|
+
return this.map(name)[name];
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const orgId = response.orgName;
|
|
91
|
+
const selectedOrg = sortedOrgs.find((o) => o.id === orgId);
|
|
92
|
+
const orgDisplay = selectedOrg ? selectedOrg.name : orgId;
|
|
93
|
+
const initialCount = selectedOrg?.integrations.length ?? 0;
|
|
94
|
+
|
|
95
|
+
// Check if user has existing GitHub integrations in other orgs
|
|
96
|
+
const existingIntegrations = await tui.spinner({
|
|
97
|
+
message: 'Checking for existing GitHub connections...',
|
|
98
|
+
clearOnSuccess: true,
|
|
99
|
+
callback: () => getExistingGithubIntegrations(apiClient, orgId),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Filter out integrations already connected to target org
|
|
103
|
+
const alreadyConnectedNames = new Set(
|
|
104
|
+
selectedOrg?.integrations.map((i) => i.githubAccountName) ?? []
|
|
105
|
+
);
|
|
106
|
+
const availableIntegrations = existingIntegrations.filter(
|
|
107
|
+
(i) => !alreadyConnectedNames.has(i.githubAccountName)
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (availableIntegrations.length > 0) {
|
|
111
|
+
tui.newline();
|
|
112
|
+
|
|
113
|
+
// Build checkbox choices
|
|
114
|
+
const integrationChoices = availableIntegrations.map((i) => ({
|
|
115
|
+
name: i.id,
|
|
116
|
+
message: `${i.githubAccountName} ${tui.muted(`(from ${i.orgName})`)}`,
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
console.log(tui.muted('Press enter with none selected to connect a new account'));
|
|
120
|
+
tui.newline();
|
|
121
|
+
|
|
122
|
+
const selectResponse = await enquirer.prompt<{ integrationIds: string[] }>({
|
|
123
|
+
type: 'multiselect',
|
|
124
|
+
name: 'integrationIds',
|
|
125
|
+
message: 'Select GitHub accounts to connect',
|
|
126
|
+
choices: integrationChoices,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (selectResponse.integrationIds.length > 0) {
|
|
130
|
+
const selectedIntegrations = availableIntegrations.filter((i) =>
|
|
131
|
+
selectResponse.integrationIds.includes(i.id)
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const accountNames = selectedIntegrations.map((i) => i.githubAccountName).join(', ');
|
|
135
|
+
|
|
136
|
+
// Confirm
|
|
137
|
+
const confirmResponse = await enquirer.prompt<{ confirm: boolean }>({
|
|
138
|
+
type: 'confirm',
|
|
139
|
+
name: 'confirm',
|
|
140
|
+
message: `Connect ${tui.bold(accountNames)} to ${tui.bold(orgDisplay)}?`,
|
|
141
|
+
initial: true,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
if (confirmResponse.confirm) {
|
|
145
|
+
await tui.spinner({
|
|
146
|
+
message: `Copying ${selectedIntegrations.length} GitHub connection${selectedIntegrations.length > 1 ? 's' : ''}...`,
|
|
147
|
+
clearOnSuccess: true,
|
|
148
|
+
callback: async () => {
|
|
149
|
+
for (const integration of selectedIntegrations) {
|
|
150
|
+
await copyGithubIntegration(apiClient, integration.orgId, orgId);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
tui.newline();
|
|
156
|
+
tui.success(`GitHub connected to ${tui.bold(orgDisplay)}`);
|
|
157
|
+
tui.newline();
|
|
158
|
+
console.log(
|
|
159
|
+
'You can now link repositories to your projects for automatic deployments.'
|
|
160
|
+
);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const startResult = await tui.spinner({
|
|
167
|
+
message: 'Getting GitHub authorization URL...',
|
|
168
|
+
clearOnSuccess: true,
|
|
169
|
+
callback: () => startGithubIntegration(apiClient, orgId),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (!startResult) {
|
|
173
|
+
tui.error('Failed to get GitHub authorization URL');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const { shortId } = startResult;
|
|
178
|
+
const apiBaseUrl = getAPIBaseURL(ctx.config);
|
|
179
|
+
const url = `${apiBaseUrl}/github/connect/${shortId}`;
|
|
180
|
+
|
|
181
|
+
const copied = await tui.copyToClipboard(url);
|
|
182
|
+
|
|
183
|
+
tui.newline();
|
|
184
|
+
if (copied) {
|
|
185
|
+
console.log('GitHub authorization URL copied to clipboard! Open it in your browser:');
|
|
186
|
+
} else {
|
|
187
|
+
console.log('Open this URL in your browser to authorize GitHub access:');
|
|
188
|
+
}
|
|
189
|
+
tui.newline();
|
|
190
|
+
console.log(` ${tui.link(url)}`);
|
|
191
|
+
tui.newline();
|
|
192
|
+
console.log(tui.muted('Press Enter to open in your browser, or Ctrl+C to cancel'));
|
|
193
|
+
tui.newline();
|
|
194
|
+
|
|
195
|
+
const result = await tui.spinner({
|
|
196
|
+
type: 'countdown',
|
|
197
|
+
message: 'Waiting for GitHub authorization',
|
|
198
|
+
timeoutMs: 600000, // 10 minutes
|
|
199
|
+
clearOnSuccess: true,
|
|
200
|
+
onEnterPress: () => {
|
|
201
|
+
const platform = process.platform;
|
|
202
|
+
if (platform === 'win32') {
|
|
203
|
+
Bun.spawn(['cmd', '/c', 'start', '', url], {
|
|
204
|
+
stdout: 'ignore',
|
|
205
|
+
stderr: 'ignore',
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
const command = platform === 'darwin' ? 'open' : 'xdg-open';
|
|
209
|
+
Bun.spawn([command, url], { stdout: 'ignore', stderr: 'ignore' });
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
callback: async () => {
|
|
213
|
+
return await pollForGithubIntegration(apiClient, orgId, initialCount);
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
tui.newline();
|
|
218
|
+
if (result.connected) {
|
|
219
|
+
tui.success(`GitHub connected to ${tui.bold(orgDisplay)}`);
|
|
220
|
+
tui.newline();
|
|
221
|
+
console.log(
|
|
222
|
+
'You can now link repositories to your projects for automatic deployments.'
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
} catch (error) {
|
|
226
|
+
// Handle user cancellation (Ctrl+C) - enquirer throws empty string or Error with empty message
|
|
227
|
+
const isCancel =
|
|
228
|
+
error === '' ||
|
|
229
|
+
(error instanceof Error &&
|
|
230
|
+
(error.message === '' || error.message === 'User cancelled'));
|
|
231
|
+
|
|
232
|
+
if (isCancel) {
|
|
233
|
+
tui.newline();
|
|
234
|
+
tui.info('Cancelled');
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
logger.trace(error);
|
|
239
|
+
logger.fatal('GitHub integration failed: %s', error, ErrorCode.INTEGRATION_FAILED);
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
});
|