@agentuity/cli 3.0.0-alpha.4 → 3.0.0-alpha.7
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/build-report.d.ts +1 -1
- package/dist/build-report.d.ts.map +1 -1
- package/dist/build-report.js +0 -1
- package/dist/build-report.js.map +1 -1
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deploy.js +101 -46
- package/dist/cmd/cloud/deploy.js.map +1 -1
- package/dist/cmd/cloud/index.d.ts.map +1 -1
- package/dist/cmd/cloud/index.js +0 -4
- package/dist/cmd/cloud/index.js.map +1 -1
- package/dist/cmd/cloud/sandbox/exec.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/exec.js +41 -24
- package/dist/cmd/cloud/sandbox/exec.js.map +1 -1
- package/dist/cmd/cloud/sandbox/job/logs.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/job/logs.js +1 -0
- package/dist/cmd/cloud/sandbox/job/logs.js.map +1 -1
- package/dist/cmd/cloud/sandbox/run.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/run.js +34 -5
- package/dist/cmd/cloud/sandbox/run.js.map +1 -1
- package/dist/cmd/cloud/sandbox/util.d.ts +9 -0
- package/dist/cmd/cloud/sandbox/util.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/util.js +20 -1
- package/dist/cmd/cloud/sandbox/util.js.map +1 -1
- package/dist/cmd/cloud/session/get.d.ts.map +1 -1
- package/dist/cmd/cloud/session/get.js +1 -41
- package/dist/cmd/cloud/session/get.js.map +1 -1
- package/dist/cmd/coder/start.d.ts.map +1 -1
- package/dist/cmd/coder/start.js +2 -0
- package/dist/cmd/coder/start.js.map +1 -1
- package/dist/cmd/coder/tui-init.js +1 -1
- package/dist/cmd/coder/tui-init.js.map +1 -1
- package/dist/cmd/project/create.d.ts.map +1 -1
- package/dist/cmd/project/create.js +0 -2
- package/dist/cmd/project/create.js.map +1 -1
- package/dist/cmd/project/frameworks.d.ts.map +1 -1
- package/dist/cmd/project/frameworks.js +18 -4
- package/dist/cmd/project/frameworks.js.map +1 -1
- package/dist/cmd/project/index.d.ts.map +1 -1
- package/dist/cmd/project/index.js +0 -3
- package/dist/cmd/project/index.js.map +1 -1
- package/dist/cmd/project/template-flow.d.ts +0 -1
- package/dist/cmd/project/template-flow.d.ts.map +1 -1
- package/dist/cmd/project/template-flow.js +1 -104
- package/dist/cmd/project/template-flow.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/onboarding/agentPrompt.d.ts.map +1 -1
- package/dist/onboarding/agentPrompt.js +5 -8
- package/dist/onboarding/agentPrompt.js.map +1 -1
- package/dist/types.d.ts +3 -170
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +70 -84
- package/src/build-report.ts +0 -1
- package/src/cmd/ai/prompt/web.md +43 -17
- package/src/cmd/cloud/deploy.ts +120 -56
- package/src/cmd/cloud/index.ts +0 -4
- package/src/cmd/cloud/sandbox/exec.ts +49 -23
- package/src/cmd/cloud/sandbox/job/logs.ts +1 -0
- package/src/cmd/cloud/sandbox/run.ts +47 -9
- package/src/cmd/cloud/sandbox/util.ts +20 -1
- package/src/cmd/cloud/session/get.ts +1 -51
- package/src/cmd/coder/start.ts +2 -0
- package/src/cmd/coder/tui-init.ts +1 -1
- package/src/cmd/project/create.ts +0 -2
- package/src/cmd/project/frameworks.ts +16 -4
- package/src/cmd/project/index.ts +0 -3
- package/src/cmd/project/template-flow.ts +0 -127
- package/src/cmd/project/templates/vite-react/vite.config.ts +8 -0
- package/src/index.ts +0 -4
- package/src/onboarding/agentPrompt.ts +5 -8
- package/src/runtime-bootstrap.md +2 -3
- package/src/types.ts +0 -186
- package/dist/cmd/build/app-config-extractor.d.ts +0 -27
- package/dist/cmd/build/app-config-extractor.d.ts.map +0 -1
- package/dist/cmd/build/app-config-extractor.js +0 -152
- package/dist/cmd/build/app-config-extractor.js.map +0 -1
- package/dist/cmd/cloud/eval/get.d.ts +0 -2
- package/dist/cmd/cloud/eval/get.d.ts.map +0 -1
- package/dist/cmd/cloud/eval/get.js +0 -80
- package/dist/cmd/cloud/eval/get.js.map +0 -1
- package/dist/cmd/cloud/eval/index.d.ts +0 -2
- package/dist/cmd/cloud/eval/index.d.ts.map +0 -1
- package/dist/cmd/cloud/eval/index.js +0 -16
- package/dist/cmd/cloud/eval/index.js.map +0 -1
- package/dist/cmd/cloud/eval/list.d.ts +0 -2
- package/dist/cmd/cloud/eval/list.d.ts.map +0 -1
- package/dist/cmd/cloud/eval/list.js +0 -124
- package/dist/cmd/cloud/eval/list.js.map +0 -1
- package/dist/cmd/cloud/eval-run/get.d.ts +0 -2
- package/dist/cmd/cloud/eval-run/get.d.ts.map +0 -1
- package/dist/cmd/cloud/eval-run/get.js +0 -107
- package/dist/cmd/cloud/eval-run/get.js.map +0 -1
- package/dist/cmd/cloud/eval-run/index.d.ts +0 -2
- package/dist/cmd/cloud/eval-run/index.d.ts.map +0 -1
- package/dist/cmd/cloud/eval-run/index.js +0 -16
- package/dist/cmd/cloud/eval-run/index.js.map +0 -1
- package/dist/cmd/cloud/eval-run/list.d.ts +0 -2
- package/dist/cmd/cloud/eval-run/list.d.ts.map +0 -1
- package/dist/cmd/cloud/eval-run/list.js +0 -149
- package/dist/cmd/cloud/eval-run/list.js.map +0 -1
- package/dist/cmd/project/auth/generate.d.ts +0 -5
- package/dist/cmd/project/auth/generate.d.ts.map +0 -1
- package/dist/cmd/project/auth/generate.js +0 -102
- package/dist/cmd/project/auth/generate.js.map +0 -1
- package/dist/cmd/project/auth/index.d.ts +0 -2
- package/dist/cmd/project/auth/index.d.ts.map +0 -1
- package/dist/cmd/project/auth/index.js +0 -21
- package/dist/cmd/project/auth/index.js.map +0 -1
- package/dist/cmd/project/auth/init.d.ts +0 -2
- package/dist/cmd/project/auth/init.d.ts.map +0 -1
- package/dist/cmd/project/auth/init.js +0 -213
- package/dist/cmd/project/auth/init.js.map +0 -1
- package/dist/cmd/project/auth/shared.d.ts +0 -93
- package/dist/cmd/project/auth/shared.d.ts.map +0 -1
- package/dist/cmd/project/auth/shared.js +0 -451
- package/dist/cmd/project/auth/shared.js.map +0 -1
- package/dist/utils/bun-version-checker.d.ts +0 -11
- package/dist/utils/bun-version-checker.d.ts.map +0 -1
- package/dist/utils/bun-version-checker.js +0 -56
- package/dist/utils/bun-version-checker.js.map +0 -1
- package/dist/utils/dependency-checker.d.ts +0 -20
- package/dist/utils/dependency-checker.d.ts.map +0 -1
- package/dist/utils/dependency-checker.js +0 -160
- package/dist/utils/dependency-checker.js.map +0 -1
- package/dist/utils/detectSubagent.d.ts +0 -15
- package/dist/utils/detectSubagent.d.ts.map +0 -1
- package/dist/utils/detectSubagent.js +0 -28
- package/dist/utils/detectSubagent.js.map +0 -1
- package/dist/utils/stream-capture.d.ts +0 -9
- package/dist/utils/stream-capture.d.ts.map +0 -1
- package/dist/utils/stream-capture.js +0 -34
- package/dist/utils/stream-capture.js.map +0 -1
- package/dist/utils/string.d.ts +0 -6
- package/dist/utils/string.d.ts.map +0 -1
- package/dist/utils/string.js +0 -6
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/version-mismatch.d.ts +0 -39
- package/dist/utils/version-mismatch.d.ts.map +0 -1
- package/dist/utils/version-mismatch.js +0 -161
- package/dist/utils/version-mismatch.js.map +0 -1
- package/dist/utils/workbench-notify.d.ts +0 -29
- package/dist/utils/workbench-notify.d.ts.map +0 -1
- package/dist/utils/workbench-notify.js +0 -56
- package/dist/utils/workbench-notify.js.map +0 -1
- package/src/cmd/build/app-config-extractor.ts +0 -186
- package/src/cmd/cloud/eval/get.ts +0 -86
- package/src/cmd/cloud/eval/index.ts +0 -16
- package/src/cmd/cloud/eval/list.ts +0 -135
- package/src/cmd/cloud/eval-run/get.ts +0 -114
- package/src/cmd/cloud/eval-run/index.ts +0 -16
- package/src/cmd/cloud/eval-run/list.ts +0 -160
- package/src/cmd/project/auth/generate.ts +0 -116
- package/src/cmd/project/auth/index.ts +0 -21
- package/src/cmd/project/auth/init.ts +0 -256
- package/src/cmd/project/auth/shared.ts +0 -566
- package/src/utils/bun-version-checker.ts +0 -70
- package/src/utils/dependency-checker.ts +0 -205
- package/src/utils/detectSubagent.ts +0 -36
- package/src/utils/stream-capture.ts +0 -39
- package/src/utils/string.ts +0 -6
- package/src/utils/version-mismatch.ts +0 -204
- package/src/utils/workbench-notify.ts +0 -67
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { createSubcommand } from '../../../types';
|
|
3
|
-
import * as tui from '../../../tui';
|
|
4
|
-
import { getCommand } from '../../../command-prefix';
|
|
5
|
-
import { ErrorCode } from '../../../errors';
|
|
6
|
-
import { evalRunList } from '@agentuity/server';
|
|
7
|
-
|
|
8
|
-
const EvalRunListResponseSchema = z.array(
|
|
9
|
-
z.object({
|
|
10
|
-
id: z.string().describe('Eval run ID'),
|
|
11
|
-
eval_id: z.string().describe('Eval ID'),
|
|
12
|
-
eval_name: z.string().nullable().describe('Eval name'),
|
|
13
|
-
agent_identifier: z.string().nullable().describe('Agent identifier'),
|
|
14
|
-
session_id: z.string().describe('Session ID'),
|
|
15
|
-
created_at: z.string().describe('Creation timestamp'),
|
|
16
|
-
pending: z.boolean().describe('Whether the eval run is pending'),
|
|
17
|
-
success: z.boolean().describe('Whether the eval run succeeded'),
|
|
18
|
-
error: z.string().nullable().describe('Error message if failed'),
|
|
19
|
-
reason: z.string().nullable().describe('Reason for the result'),
|
|
20
|
-
})
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
export const listSubcommand = createSubcommand({
|
|
24
|
-
name: 'list',
|
|
25
|
-
aliases: ['ls'],
|
|
26
|
-
description: 'List eval runs',
|
|
27
|
-
tags: ['read-only', 'fast', 'requires-auth'],
|
|
28
|
-
examples: [
|
|
29
|
-
{ command: getCommand('cloud eval-run list'), description: 'List 10 most recent eval runs' },
|
|
30
|
-
{
|
|
31
|
-
command: getCommand('cloud eval-run list --count=25'),
|
|
32
|
-
description: 'List 25 most recent eval runs',
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
command: getCommand('cloud eval-run list --eval-id=eval_*'),
|
|
36
|
-
description: 'Filter by eval',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
command: getCommand('cloud eval-run list --session-id=sess_*'),
|
|
40
|
-
description: 'Filter by session',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
command: getCommand('cloud eval-run list --project-id=proj_*'),
|
|
44
|
-
description: 'Filter by project',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
command: getCommand('cloud eval-run list --agent-id=agent_*'),
|
|
48
|
-
description: 'Filter by agent',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
command: getCommand('cloud eval-run list --all'),
|
|
52
|
-
description: 'List all eval runs regardless of project context',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
requires: { auth: true, apiClient: true },
|
|
56
|
-
optional: { project: true },
|
|
57
|
-
idempotent: true,
|
|
58
|
-
pagination: {
|
|
59
|
-
supported: true,
|
|
60
|
-
defaultLimit: 10,
|
|
61
|
-
maxLimit: 100,
|
|
62
|
-
parameters: {
|
|
63
|
-
limit: 'count',
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
schema: {
|
|
67
|
-
options: z.object({
|
|
68
|
-
orgId: z.string().optional().describe('filter by organization id'),
|
|
69
|
-
count: z.coerce
|
|
70
|
-
.number()
|
|
71
|
-
.int()
|
|
72
|
-
.min(1)
|
|
73
|
-
.max(100)
|
|
74
|
-
.default(10)
|
|
75
|
-
.describe('Number of eval runs to list (1–100)'),
|
|
76
|
-
projectId: z.string().optional().describe('Filter by project ID'),
|
|
77
|
-
all: z.boolean().optional().describe('List all eval runs regardless of project context'),
|
|
78
|
-
evalId: z.string().optional().describe('Filter by eval ID'),
|
|
79
|
-
agentId: z.string().optional().describe('Filter by agent ID'),
|
|
80
|
-
sessionId: z.string().optional().describe('Filter by session ID'),
|
|
81
|
-
}),
|
|
82
|
-
response: EvalRunListResponseSchema,
|
|
83
|
-
},
|
|
84
|
-
webUrl: (ctx) => {
|
|
85
|
-
const projectId = ctx.opts?.all ? undefined : ctx.opts?.projectId || ctx.project?.projectId;
|
|
86
|
-
return projectId ? `/projects/${encodeURIComponent(projectId)}/eval-runs` : undefined;
|
|
87
|
-
},
|
|
88
|
-
async handler(ctx) {
|
|
89
|
-
const { apiClient, project, opts, options } = ctx;
|
|
90
|
-
|
|
91
|
-
if (opts?.orgId && opts?.projectId) {
|
|
92
|
-
tui.fatal('--org-id and --project-id are mutually exclusive. Use one or the other.');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const projectId = opts.all || opts.orgId ? undefined : opts.projectId || project?.projectId;
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
const evalRuns = await evalRunList(apiClient, {
|
|
99
|
-
orgId: opts?.orgId,
|
|
100
|
-
projectId,
|
|
101
|
-
evalId: opts.evalId,
|
|
102
|
-
sessionId: opts.sessionId,
|
|
103
|
-
agentId: opts.agentId,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const result = evalRuns.map((r) => ({
|
|
107
|
-
id: r.id,
|
|
108
|
-
eval_id: r.evalId,
|
|
109
|
-
eval_name: r.evalName,
|
|
110
|
-
agent_identifier: r.agentIdentifier,
|
|
111
|
-
session_id: r.sessionId,
|
|
112
|
-
created_at: r.createdAt,
|
|
113
|
-
pending: r.pending,
|
|
114
|
-
success: r.success,
|
|
115
|
-
error: r.error,
|
|
116
|
-
reason: r.result?.reason ?? null,
|
|
117
|
-
}));
|
|
118
|
-
|
|
119
|
-
if (options.json) {
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (evalRuns.length === 0) {
|
|
124
|
-
tui.info('No eval runs found.');
|
|
125
|
-
return [];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const tableData = evalRuns.map((r) => {
|
|
129
|
-
const reason = r.result?.reason;
|
|
130
|
-
return {
|
|
131
|
-
ID: r.id,
|
|
132
|
-
'Eval Name': r.evalName || '-',
|
|
133
|
-
Agent: r.agentIdentifier || '-',
|
|
134
|
-
Success: r.success ? '✓' : '✗',
|
|
135
|
-
Pending: r.pending ? '⏳' : '✓',
|
|
136
|
-
Reason: reason
|
|
137
|
-
? reason.length > 30
|
|
138
|
-
? reason.substring(0, 27) + '...'
|
|
139
|
-
: reason
|
|
140
|
-
: '-',
|
|
141
|
-
Created: new Date(r.createdAt).toLocaleString(),
|
|
142
|
-
};
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
tui.table(tableData, [
|
|
146
|
-
{ name: 'ID', alignment: 'left' },
|
|
147
|
-
{ name: 'Eval Name', alignment: 'left' },
|
|
148
|
-
{ name: 'Agent', alignment: 'left' },
|
|
149
|
-
{ name: 'Success', alignment: 'center' },
|
|
150
|
-
{ name: 'Pending', alignment: 'center' },
|
|
151
|
-
{ name: 'Reason', alignment: 'left' },
|
|
152
|
-
{ name: 'Created', alignment: 'left' },
|
|
153
|
-
]);
|
|
154
|
-
|
|
155
|
-
return result;
|
|
156
|
-
} catch (ex) {
|
|
157
|
-
tui.fatal(`Failed to list eval runs: ${ex}`, ErrorCode.API_ERROR);
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate auth schema SQL using drizzle-kit export
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
import * as fs from 'node:fs';
|
|
7
|
-
import * as path from 'node:path';
|
|
8
|
-
import { createSubcommand } from '../../../types';
|
|
9
|
-
import * as tui from '../../../tui';
|
|
10
|
-
import { getCommand } from '../../../command-prefix';
|
|
11
|
-
import { generateAuthSchemaSql, getGeneratedSqlDir } from './shared';
|
|
12
|
-
|
|
13
|
-
export const generateSubcommand = createSubcommand({
|
|
14
|
-
name: 'generate',
|
|
15
|
-
description: 'Generate SQL schema for Agentuity Auth tables',
|
|
16
|
-
tags: ['slow'],
|
|
17
|
-
requires: { project: true },
|
|
18
|
-
examples: [
|
|
19
|
-
{
|
|
20
|
-
command: getCommand('project auth generate'),
|
|
21
|
-
description: 'Generate SQL schema and save to agentuity-auth-schema.sql',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
command: getCommand('project auth generate --output ./migrations/auth.sql'),
|
|
25
|
-
description: 'Generate schema to a custom path',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
command: getCommand('project auth generate --output -'),
|
|
29
|
-
description: 'Output SQL to stdout',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
schema: {
|
|
33
|
-
options: z.object({
|
|
34
|
-
output: z
|
|
35
|
-
.string()
|
|
36
|
-
.optional()
|
|
37
|
-
.describe(
|
|
38
|
-
'Output path for generated SQL (default: ./agentuity-auth-schema.sql). Use "-" for stdout.'
|
|
39
|
-
),
|
|
40
|
-
}),
|
|
41
|
-
response: z.object({
|
|
42
|
-
success: z.boolean().describe('Whether generation succeeded'),
|
|
43
|
-
outputPath: z.string().optional().describe('Path where SQL was written'),
|
|
44
|
-
}),
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
async handler(ctx) {
|
|
48
|
-
const { logger, opts, projectDir, options } = ctx;
|
|
49
|
-
const explicitOutput = opts?.output as string | undefined;
|
|
50
|
-
const toStdout = explicitOutput === '-';
|
|
51
|
-
const isJson = options?.json === true;
|
|
52
|
-
|
|
53
|
-
if (!toStdout && !isJson) {
|
|
54
|
-
tui.newline();
|
|
55
|
-
tui.info(tui.bold('Agentuity Auth Schema Generation'));
|
|
56
|
-
tui.newline();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const sql = isJson
|
|
61
|
-
? await generateAuthSchemaSql(logger, projectDir)
|
|
62
|
-
: await tui.spinner({
|
|
63
|
-
message: 'Generating auth schema SQL from Drizzle schema',
|
|
64
|
-
clearOnSuccess: true,
|
|
65
|
-
callback: () => generateAuthSchemaSql(logger, projectDir),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (toStdout) {
|
|
69
|
-
console.log(sql);
|
|
70
|
-
return { success: true };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
let outputPath: string;
|
|
74
|
-
let displayPath: string;
|
|
75
|
-
|
|
76
|
-
if (explicitOutput) {
|
|
77
|
-
outputPath = path.resolve(projectDir, explicitOutput);
|
|
78
|
-
displayPath = explicitOutput;
|
|
79
|
-
} else {
|
|
80
|
-
const sqlOutputDir = await getGeneratedSqlDir(projectDir);
|
|
81
|
-
const sqlFileName = 'agentuity-auth-schema.sql';
|
|
82
|
-
outputPath = path.join(sqlOutputDir, sqlFileName);
|
|
83
|
-
displayPath =
|
|
84
|
-
sqlOutputDir === projectDir ? sqlFileName : path.relative(projectDir, outputPath);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
fs.writeFileSync(outputPath, sql);
|
|
88
|
-
|
|
89
|
-
if (!isJson) {
|
|
90
|
-
tui.success(`Auth schema SQL saved to ${tui.bold(displayPath)}`);
|
|
91
|
-
tui.newline();
|
|
92
|
-
tui.info('Next steps:');
|
|
93
|
-
console.log(' 1. Review the generated SQL file');
|
|
94
|
-
console.log(' 2. Run the SQL against your database');
|
|
95
|
-
console.log(` ${tui.muted('Or use: agentuity project auth init')}`);
|
|
96
|
-
tui.newline();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return { success: true, outputPath };
|
|
100
|
-
} catch (error) {
|
|
101
|
-
logger.error('Schema generation failed', { error });
|
|
102
|
-
|
|
103
|
-
if (!isJson) {
|
|
104
|
-
tui.error(
|
|
105
|
-
`Schema generation failed: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
106
|
-
);
|
|
107
|
-
tui.newline();
|
|
108
|
-
tui.info('Make sure you have:');
|
|
109
|
-
console.log(' 1. @agentuity/auth installed as a dependency');
|
|
110
|
-
console.log(' 2. drizzle-kit available (installed with @agentuity/auth)');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return { success: false };
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createCommand } from '../../../types';
|
|
2
|
-
import { initSubcommand } from './init';
|
|
3
|
-
import { generateSubcommand } from './generate';
|
|
4
|
-
import { getCommand } from '../../../command-prefix';
|
|
5
|
-
|
|
6
|
-
export const authCommand = createCommand({
|
|
7
|
-
name: 'auth',
|
|
8
|
-
description: 'Manage project authentication (Agentuity Auth)',
|
|
9
|
-
tags: ['slow', 'requires-auth'],
|
|
10
|
-
examples: [
|
|
11
|
-
{
|
|
12
|
-
command: getCommand('project auth init'),
|
|
13
|
-
description: 'Set up Agentuity Auth for an existing project',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
command: getCommand('project auth generate'),
|
|
17
|
-
description: 'Generate SQL schema for auth tables',
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
subcommands: [initSubcommand, generateSubcommand],
|
|
21
|
-
});
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import enquirer from 'enquirer';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import { getCommand } from '../../../command-prefix';
|
|
6
|
-
import { readEnvFile, writeEnvFile } from '../../../env-util';
|
|
7
|
-
import * as tui from '../../../tui';
|
|
8
|
-
import { createSubcommand } from '../../../types';
|
|
9
|
-
import {
|
|
10
|
-
detectOrmSetup,
|
|
11
|
-
ensureAuthDependencies,
|
|
12
|
-
generateAuthFileContent,
|
|
13
|
-
generateAuthSchemaSql,
|
|
14
|
-
getGeneratedSqlDir,
|
|
15
|
-
printIntegrationExamples,
|
|
16
|
-
runAuthMigrations,
|
|
17
|
-
selectOrCreateDatabase,
|
|
18
|
-
} from './shared';
|
|
19
|
-
|
|
20
|
-
export const initSubcommand = createSubcommand({
|
|
21
|
-
name: 'init',
|
|
22
|
-
description: 'Set up Agentuity Auth for your project',
|
|
23
|
-
tags: ['mutating', 'slow', 'requires-auth'],
|
|
24
|
-
requires: { auth: true, org: true },
|
|
25
|
-
idempotent: false,
|
|
26
|
-
examples: [
|
|
27
|
-
{
|
|
28
|
-
command: getCommand('project auth init'),
|
|
29
|
-
description: 'Set up Agentuity Auth with database selection',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
schema: {
|
|
33
|
-
options: z.object({
|
|
34
|
-
skipMigrations: z
|
|
35
|
-
.boolean()
|
|
36
|
-
.optional()
|
|
37
|
-
.describe(
|
|
38
|
-
'Skip running database migrations (run `agentuity project auth generate` later)'
|
|
39
|
-
),
|
|
40
|
-
}),
|
|
41
|
-
response: z.object({
|
|
42
|
-
success: z.boolean().describe('Whether setup succeeded'),
|
|
43
|
-
database: z.string().optional().describe('Database name used'),
|
|
44
|
-
authFileCreated: z.boolean().describe('Whether auth.ts was created'),
|
|
45
|
-
migrationsRun: z.boolean().describe('Whether migrations were run'),
|
|
46
|
-
}),
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
async handler(ctx) {
|
|
50
|
-
const { logger, opts, auth, orgId, config } = ctx;
|
|
51
|
-
|
|
52
|
-
tui.newline();
|
|
53
|
-
tui.info(tui.bold('Agentuity Auth Setup'));
|
|
54
|
-
tui.newline();
|
|
55
|
-
tui.info('This will:');
|
|
56
|
-
console.log(' • Ensure you have a Postgres database configured');
|
|
57
|
-
console.log(' • Install @agentuity/auth');
|
|
58
|
-
console.log(' • Run database migrations to create auth tables');
|
|
59
|
-
console.log(' • Show you how to wire auth into your API and UI');
|
|
60
|
-
tui.newline();
|
|
61
|
-
|
|
62
|
-
const projectDir = process.cwd();
|
|
63
|
-
|
|
64
|
-
// Check for package.json
|
|
65
|
-
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
66
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
67
|
-
tui.fatal('No package.json found. Run this command from your project root.');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Step 1: Check for DATABASE_URL or select/create database
|
|
71
|
-
let databaseUrl = process.env.DATABASE_URL;
|
|
72
|
-
|
|
73
|
-
if (!databaseUrl) {
|
|
74
|
-
// Check .env file
|
|
75
|
-
const envPath = path.join(projectDir, '.env');
|
|
76
|
-
if (fs.existsSync(envPath)) {
|
|
77
|
-
const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
78
|
-
const match = envContent.match(/^DATABASE_URL=(.+)$/m);
|
|
79
|
-
if (match?.[1]) {
|
|
80
|
-
databaseUrl = match[1].trim().replace(/^["']|["']$/g, '');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Show database picker (with existing as first option if configured)
|
|
86
|
-
const dbInfo = await selectOrCreateDatabase({
|
|
87
|
-
logger,
|
|
88
|
-
auth,
|
|
89
|
-
orgId,
|
|
90
|
-
config,
|
|
91
|
-
existingUrl: databaseUrl,
|
|
92
|
-
projectDir,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Get the region from the selected database
|
|
96
|
-
const region = dbInfo.region;
|
|
97
|
-
|
|
98
|
-
const databaseName = dbInfo.name;
|
|
99
|
-
|
|
100
|
-
// Update .env with database URL using proper parsing
|
|
101
|
-
const envPath = path.join(projectDir, '.env');
|
|
102
|
-
const existingEnv = await readEnvFile(envPath);
|
|
103
|
-
|
|
104
|
-
// Check if DATABASE_URL already exists
|
|
105
|
-
const hasDatabaseUrl = 'DATABASE_URL' in existingEnv;
|
|
106
|
-
|
|
107
|
-
if (dbInfo.url !== databaseUrl || !hasDatabaseUrl) {
|
|
108
|
-
if (hasDatabaseUrl) {
|
|
109
|
-
// DATABASE_URL exists, use AUTH_DATABASE_URL instead
|
|
110
|
-
await writeEnvFile(envPath, { AUTH_DATABASE_URL: dbInfo.url });
|
|
111
|
-
tui.success('AUTH_DATABASE_URL added to .env');
|
|
112
|
-
tui.warning(
|
|
113
|
-
`DATABASE_URL already exists. Update your ${tui.bold('src/auth.ts')} to use AUTH_DATABASE_URL.`
|
|
114
|
-
);
|
|
115
|
-
} else {
|
|
116
|
-
await writeEnvFile(envPath, { DATABASE_URL: dbInfo.url });
|
|
117
|
-
tui.success('DATABASE_URL added to .env');
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
tui.success(`Using database: ${databaseName}`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Add AGENTUITY_AUTH_SECRET if not present
|
|
124
|
-
// Re-read env to get latest state
|
|
125
|
-
const currentEnv = await readEnvFile(envPath);
|
|
126
|
-
|
|
127
|
-
const hasAuthSecret =
|
|
128
|
-
'AGENTUITY_AUTH_SECRET' in currentEnv || 'BETTER_AUTH_SECRET' in currentEnv;
|
|
129
|
-
if (!hasAuthSecret) {
|
|
130
|
-
const devSecret = `dev-${crypto.randomUUID()}-CHANGE-ME`;
|
|
131
|
-
await writeEnvFile(envPath, { AGENTUITY_AUTH_SECRET: devSecret });
|
|
132
|
-
tui.success('AGENTUITY_AUTH_SECRET added to .env (development default)');
|
|
133
|
-
tui.warning(
|
|
134
|
-
`Replace ${tui.bold('AGENTUITY_AUTH_SECRET')} with a secure value before deploying.`
|
|
135
|
-
);
|
|
136
|
-
tui.info(`Generate one with: ${tui.muted('openssl rand -hex 32')}`);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Step 2: Install dependencies
|
|
140
|
-
tui.newline();
|
|
141
|
-
await ensureAuthDependencies({ projectDir, logger });
|
|
142
|
-
|
|
143
|
-
// Step 3: Generate auth.ts if it doesn't exist
|
|
144
|
-
const authFilePath = path.join(projectDir, 'src', 'auth.ts');
|
|
145
|
-
let authFileCreated = false;
|
|
146
|
-
|
|
147
|
-
if (fs.existsSync(authFilePath)) {
|
|
148
|
-
tui.info('src/auth.ts already exists, skipping generation');
|
|
149
|
-
} else {
|
|
150
|
-
const { createFile } = await enquirer.prompt<{ createFile: boolean }>({
|
|
151
|
-
type: 'confirm',
|
|
152
|
-
name: 'createFile',
|
|
153
|
-
message: 'Create src/auth.ts with default configuration?',
|
|
154
|
-
initial: true,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
if (createFile) {
|
|
158
|
-
// Ensure src directory exists
|
|
159
|
-
const srcDir = path.join(projectDir, 'src');
|
|
160
|
-
if (!fs.existsSync(srcDir)) {
|
|
161
|
-
fs.mkdirSync(srcDir, { recursive: true });
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
fs.writeFileSync(authFilePath, generateAuthFileContent());
|
|
165
|
-
tui.success('Created src/auth.ts');
|
|
166
|
-
authFileCreated = true;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Step 4: Run migrations (ORM-aware)
|
|
171
|
-
let migrationsRun = false;
|
|
172
|
-
|
|
173
|
-
if (opts.skipMigrations) {
|
|
174
|
-
tui.info('Skipping migrations (run `agentuity project auth generate` later)');
|
|
175
|
-
} else if (databaseName) {
|
|
176
|
-
tui.newline();
|
|
177
|
-
|
|
178
|
-
const ormSetup = await detectOrmSetup(projectDir);
|
|
179
|
-
|
|
180
|
-
if (ormSetup === 'drizzle') {
|
|
181
|
-
tui.info(tui.bold('Drizzle detected in your project.'));
|
|
182
|
-
tui.newline();
|
|
183
|
-
console.log(
|
|
184
|
-
' Since you manage your own Drizzle schema, add authSchema to your schema:'
|
|
185
|
-
);
|
|
186
|
-
tui.newline();
|
|
187
|
-
console.log(tui.muted(" import * as authSchema from '@agentuity/auth/schema';"));
|
|
188
|
-
console.log(tui.muted(' export const schema = { ...authSchema, ...yourSchema };'));
|
|
189
|
-
tui.newline();
|
|
190
|
-
console.log(' Then run migrations:');
|
|
191
|
-
console.log(tui.muted(' bunx drizzle-kit push'));
|
|
192
|
-
tui.newline();
|
|
193
|
-
} else if (ormSetup === 'prisma') {
|
|
194
|
-
tui.info(tui.bold('Prisma detected in your project.'));
|
|
195
|
-
tui.newline();
|
|
196
|
-
|
|
197
|
-
const sql = await tui.spinner({
|
|
198
|
-
message: 'Preparing auth database schema...',
|
|
199
|
-
clearOnSuccess: true,
|
|
200
|
-
callback: () => generateAuthSchemaSql(logger, projectDir),
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const sqlOutputDir = await getGeneratedSqlDir(projectDir);
|
|
204
|
-
const sqlFileName = 'agentuity-auth-schema.sql';
|
|
205
|
-
const sqlFilePath = path.join(sqlOutputDir, sqlFileName);
|
|
206
|
-
const relativePath =
|
|
207
|
-
sqlOutputDir === projectDir ? sqlFileName : path.relative(projectDir, sqlFilePath);
|
|
208
|
-
fs.writeFileSync(sqlFilePath, sql);
|
|
209
|
-
tui.success(`Auth schema SQL saved to ${tui.bold(relativePath)}`);
|
|
210
|
-
tui.newline();
|
|
211
|
-
console.log(' Run this SQL against your database to create auth tables.');
|
|
212
|
-
tui.newline();
|
|
213
|
-
} else {
|
|
214
|
-
const { runMigrations } = await enquirer.prompt<{ runMigrations: boolean }>({
|
|
215
|
-
type: 'confirm',
|
|
216
|
-
name: 'runMigrations',
|
|
217
|
-
message: 'Run database migrations now? (idempotent, safe to re-run)',
|
|
218
|
-
initial: true,
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
if (runMigrations) {
|
|
222
|
-
const sql = await tui.spinner({
|
|
223
|
-
message: 'Preparing auth database schema...',
|
|
224
|
-
clearOnSuccess: true,
|
|
225
|
-
callback: () => generateAuthSchemaSql(logger, projectDir),
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
await runAuthMigrations({
|
|
229
|
-
logger,
|
|
230
|
-
auth,
|
|
231
|
-
orgId,
|
|
232
|
-
region,
|
|
233
|
-
databaseName,
|
|
234
|
-
sql,
|
|
235
|
-
config,
|
|
236
|
-
});
|
|
237
|
-
migrationsRun = true;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
} else {
|
|
241
|
-
tui.warning(
|
|
242
|
-
'Could not determine database name. Run `agentuity project auth generate` manually.'
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Step 5: Print integration examples
|
|
247
|
-
printIntegrationExamples();
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
success: true,
|
|
251
|
-
database: databaseName,
|
|
252
|
-
authFileCreated,
|
|
253
|
-
migrationsRun,
|
|
254
|
-
};
|
|
255
|
-
},
|
|
256
|
-
});
|