@agentuity/cli 1.0.41 → 1.0.42
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/cmd/build/ast.d.ts.map +1 -1
- package/dist/cmd/build/ast.js +3 -3
- package/dist/cmd/build/ast.js.map +1 -1
- package/dist/cmd/build/typecheck.d.ts.map +1 -1
- package/dist/cmd/build/typecheck.js +52 -1
- package/dist/cmd/build/typecheck.js.map +1 -1
- package/dist/cmd/build/vite/static-renderer.d.ts.map +1 -1
- package/dist/cmd/build/vite/static-renderer.js +22 -8
- package/dist/cmd/build/vite/static-renderer.js.map +1 -1
- package/dist/cmd/cloud/index.d.ts.map +1 -1
- package/dist/cmd/cloud/index.js +4 -0
- package/dist/cmd/cloud/index.js.map +1 -1
- package/dist/cmd/cloud/monitor.d.ts +3 -0
- package/dist/cmd/cloud/monitor.d.ts.map +1 -0
- package/dist/cmd/cloud/monitor.js +300 -0
- package/dist/cmd/cloud/monitor.js.map +1 -0
- package/dist/cmd/cloud/oidc/activity.d.ts +2 -0
- package/dist/cmd/cloud/oidc/activity.d.ts.map +1 -0
- package/dist/cmd/cloud/oidc/activity.js +54 -0
- package/dist/cmd/cloud/oidc/activity.js.map +1 -0
- package/dist/cmd/cloud/oidc/create.d.ts +2 -0
- package/dist/cmd/cloud/oidc/create.d.ts.map +1 -0
- package/dist/cmd/cloud/oidc/create.js +201 -0
- package/dist/cmd/cloud/oidc/create.js.map +1 -0
- package/dist/cmd/cloud/oidc/delete.d.ts +2 -0
- package/dist/cmd/cloud/oidc/delete.d.ts.map +1 -0
- package/dist/cmd/cloud/oidc/delete.js +56 -0
- package/dist/cmd/cloud/oidc/delete.js.map +1 -0
- package/dist/cmd/cloud/oidc/get.d.ts +2 -0
- package/dist/cmd/cloud/oidc/get.d.ts.map +1 -0
- package/dist/cmd/cloud/oidc/get.js +59 -0
- package/dist/cmd/cloud/oidc/get.js.map +1 -0
- package/dist/cmd/cloud/oidc/index.d.ts +3 -0
- package/dist/cmd/cloud/oidc/index.d.ts.map +1 -0
- package/dist/cmd/cloud/oidc/index.js +32 -0
- package/dist/cmd/cloud/oidc/index.js.map +1 -0
- package/dist/cmd/cloud/oidc/list.d.ts +2 -0
- package/dist/cmd/cloud/oidc/list.d.ts.map +1 -0
- package/dist/cmd/cloud/oidc/list.js +45 -0
- package/dist/cmd/cloud/oidc/list.js.map +1 -0
- package/dist/cmd/cloud/oidc/rotate-secret.d.ts +2 -0
- package/dist/cmd/cloud/oidc/rotate-secret.d.ts.map +1 -0
- package/dist/cmd/cloud/oidc/rotate-secret.js +63 -0
- package/dist/cmd/cloud/oidc/rotate-secret.js.map +1 -0
- package/dist/cmd/cloud/oidc/users.d.ts +2 -0
- package/dist/cmd/cloud/oidc/users.d.ts.map +1 -0
- package/dist/cmd/cloud/oidc/users.js +50 -0
- package/dist/cmd/cloud/oidc/users.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -5
- package/dist/config.js.map +1 -1
- package/dist/utils/jsonc.d.ts +13 -0
- package/dist/utils/jsonc.d.ts.map +1 -0
- package/dist/utils/jsonc.js +63 -0
- package/dist/utils/jsonc.js.map +1 -0
- package/dist/utils/route-migration.d.ts +2 -1
- package/dist/utils/route-migration.d.ts.map +1 -1
- package/dist/utils/route-migration.js +23 -32
- package/dist/utils/route-migration.js.map +1 -1
- package/dist/utils/zip.d.ts.map +1 -1
- package/dist/utils/zip.js +18 -2
- package/dist/utils/zip.js.map +1 -1
- package/package.json +6 -7
- package/src/cmd/build/ast.ts +6 -3
- package/src/cmd/build/typecheck.ts +60 -1
- package/src/cmd/build/vite/static-renderer.ts +24 -8
- package/src/cmd/cloud/index.ts +4 -0
- package/src/cmd/cloud/monitor.ts +375 -0
- package/src/cmd/cloud/oidc/activity.ts +61 -0
- package/src/cmd/cloud/oidc/create.ts +232 -0
- package/src/cmd/cloud/oidc/delete.ts +63 -0
- package/src/cmd/cloud/oidc/get.ts +65 -0
- package/src/cmd/cloud/oidc/index.ts +35 -0
- package/src/cmd/cloud/oidc/list.ts +50 -0
- package/src/cmd/cloud/oidc/rotate-secret.ts +77 -0
- package/src/cmd/cloud/oidc/users.ts +57 -0
- package/src/config.ts +16 -5
- package/src/utils/jsonc.ts +67 -0
- package/src/utils/route-migration.ts +29 -40
- package/src/utils/zip.ts +17 -2
package/dist/cmd/cloud/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import webhookCommand from './webhook';
|
|
|
14
14
|
import { agentCommand } from './agent';
|
|
15
15
|
import envCommand from './env';
|
|
16
16
|
import apikeyCommand from './apikey';
|
|
17
|
+
import oidcCommand from './oidc';
|
|
17
18
|
import streamCommand from './stream';
|
|
18
19
|
import vectorCommand from './vector';
|
|
19
20
|
import { emailCommand } from './email';
|
|
@@ -23,6 +24,7 @@ import scheduleCommand from './schedule';
|
|
|
23
24
|
import servicesCommand from './services';
|
|
24
25
|
import { regionSubcommand } from './region';
|
|
25
26
|
import { machineCommand } from './machine';
|
|
27
|
+
import { monitorSubcommand } from './monitor';
|
|
26
28
|
import { evalCommand } from './eval';
|
|
27
29
|
import { evalRunCommand } from './eval-run';
|
|
28
30
|
import { getCommand } from '../../command-prefix';
|
|
@@ -37,6 +39,7 @@ export const command = createCommand({
|
|
|
37
39
|
],
|
|
38
40
|
subcommands: [
|
|
39
41
|
apikeyCommand,
|
|
42
|
+
oidcCommand,
|
|
40
43
|
keyvalueCommand,
|
|
41
44
|
queueCommand,
|
|
42
45
|
webhookCommand,
|
|
@@ -59,6 +62,7 @@ export const command = createCommand({
|
|
|
59
62
|
threadCommand,
|
|
60
63
|
sshSubcommand,
|
|
61
64
|
scpSubcommand,
|
|
65
|
+
monitorSubcommand,
|
|
62
66
|
deploymentCommand,
|
|
63
67
|
regionSubcommand,
|
|
64
68
|
machineCommand,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmd/cloud/index.ts"],"names":[],"mappings":"AAAA,OAA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W,EAAE,sBAAsB,EAAE;QACrF,EAAE,OAAO,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE,WAAW,EAAE,oBAAoB,EAAE;KACjF;IACD,WAAW,EAAE;QACZ,aAAa;QACb,WAAW;QACX,eAAe;QACf,YAAY;QACZ,cAAc;QACd,WAAW;QACX,YAAY;QACZ,aAAa;QACb,YAAY;QACZ,aAAa;QACb,cAAc;QACd,eAAe;QACf,UAAU;QACV,WAAW;QACX,cAAc;QACd,gBAAgB;QAChB,SAAS;QACT,YAAY;QACZ,cAAc;QACd,eAAe;QACf,cAAc;QACd,aAAa;QACb,aAAa;QACb,aAAa;QACb,iBAAiB;QACjB,iBAAiB;QACjB,gBAAgB;QAChB,cAAc;KACd;CACD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor.d.ts","sourceRoot":"","sources":["../../../src/cmd/cloud/monitor.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,iBAAiB,sCAoH5B,CAAC;AA2OH,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getMonitorNode, listDistressedNodes, listMonitorNodeContainers, listMonitorNodes, MonitorWebSocketClient, } from '@agentuity/core';
|
|
3
|
+
import { getAPIBaseURL } from '../../api';
|
|
4
|
+
import { getCommand } from '../../command-prefix';
|
|
5
|
+
import { createSubcommand } from '../../types';
|
|
6
|
+
import * as tui from '../../tui';
|
|
7
|
+
const monitorOptionsSchema = z.object({
|
|
8
|
+
machine: z.string().optional().describe('Monitor a specific machine id'),
|
|
9
|
+
deployment: z.string().optional().describe('Monitor machines for a deployment id'),
|
|
10
|
+
distressed: z.boolean().optional().describe('Only include distressed machines'),
|
|
11
|
+
snapshot: z.boolean().optional().describe('One-shot snapshot (no stream watch)'),
|
|
12
|
+
});
|
|
13
|
+
export const monitorSubcommand = createSubcommand({
|
|
14
|
+
name: 'monitor',
|
|
15
|
+
description: 'Monitor infrastructure machines in real time',
|
|
16
|
+
tags: ['read-only', 'slow', 'requires-auth'],
|
|
17
|
+
requires: { auth: true, apiClient: true },
|
|
18
|
+
optional: { org: true },
|
|
19
|
+
idempotent: true,
|
|
20
|
+
examples: [
|
|
21
|
+
{ command: getCommand('cloud monitor --snapshot'), description: 'Show a monitor snapshot' },
|
|
22
|
+
{
|
|
23
|
+
command: getCommand('cloud monitor --distressed'),
|
|
24
|
+
description: 'Watch distressed machines',
|
|
25
|
+
},
|
|
26
|
+
{ command: getCommand('cloud monitor --machine mach_123'), description: 'Watch one machine' },
|
|
27
|
+
],
|
|
28
|
+
schema: {
|
|
29
|
+
options: monitorOptionsSchema,
|
|
30
|
+
},
|
|
31
|
+
webUrl: '/infrastructure/monitoring',
|
|
32
|
+
async handler(ctx) {
|
|
33
|
+
const { apiClient, options, opts, auth, config, orgId } = ctx;
|
|
34
|
+
if (opts.machine && opts.distressed) {
|
|
35
|
+
ctx.logger.fatal('--machine and --distressed are mutually exclusive.');
|
|
36
|
+
}
|
|
37
|
+
if (opts.deployment && opts.distressed) {
|
|
38
|
+
ctx.logger.fatal('--deployment and --distressed are mutually exclusive.');
|
|
39
|
+
}
|
|
40
|
+
if (opts.snapshot || options.json) {
|
|
41
|
+
const machines = await getSnapshotMachines({
|
|
42
|
+
apiClient,
|
|
43
|
+
machineId: opts.machine,
|
|
44
|
+
deploymentId: opts.deployment,
|
|
45
|
+
distressed: opts.distressed,
|
|
46
|
+
});
|
|
47
|
+
if (options.json) {
|
|
48
|
+
console.log(JSON.stringify(machines, null, 2));
|
|
49
|
+
return machines;
|
|
50
|
+
}
|
|
51
|
+
renderMachineTable(machines);
|
|
52
|
+
return machines;
|
|
53
|
+
}
|
|
54
|
+
const machineMap = new Map();
|
|
55
|
+
const initialMachines = await getSnapshotMachines({
|
|
56
|
+
apiClient,
|
|
57
|
+
machineId: opts.machine,
|
|
58
|
+
deploymentId: opts.deployment,
|
|
59
|
+
distressed: opts.distressed,
|
|
60
|
+
});
|
|
61
|
+
for (const machine of initialMachines) {
|
|
62
|
+
machineMap.set(machine.machineId, machine);
|
|
63
|
+
}
|
|
64
|
+
renderWatchTable(machineMap, {
|
|
65
|
+
mode: 'snapshot',
|
|
66
|
+
machineId: opts.machine,
|
|
67
|
+
deploymentId: opts.deployment,
|
|
68
|
+
distressed: opts.distressed,
|
|
69
|
+
});
|
|
70
|
+
tui.info('Connecting to monitoring stream...');
|
|
71
|
+
let processingChain = Promise.resolve();
|
|
72
|
+
let resolveWait = null;
|
|
73
|
+
const monitorClient = new MonitorWebSocketClient({
|
|
74
|
+
baseUrl: getAPIBaseURL(config),
|
|
75
|
+
token: auth.apiKey,
|
|
76
|
+
orgId,
|
|
77
|
+
scope: toMonitorScope(opts.machine, opts.deployment),
|
|
78
|
+
onOpen: () => {
|
|
79
|
+
tui.success('Connected to monitoring stream');
|
|
80
|
+
},
|
|
81
|
+
onError: (error) => {
|
|
82
|
+
tui.error(`Monitoring stream error: ${error.message}`);
|
|
83
|
+
},
|
|
84
|
+
onClose: () => {
|
|
85
|
+
tui.info('Monitoring stream disconnected');
|
|
86
|
+
resolveWait?.();
|
|
87
|
+
},
|
|
88
|
+
onMessage: (message) => {
|
|
89
|
+
processingChain = processingChain.then(async () => {
|
|
90
|
+
await applyMonitorMessage(machineMap, message, apiClient, opts.deployment);
|
|
91
|
+
renderWatchTable(machineMap, {
|
|
92
|
+
mode: 'watch',
|
|
93
|
+
machineId: opts.machine,
|
|
94
|
+
deploymentId: opts.deployment,
|
|
95
|
+
distressed: opts.distressed,
|
|
96
|
+
lastMessage: message,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
monitorClient.connect();
|
|
102
|
+
await new Promise((resolve) => {
|
|
103
|
+
resolveWait = resolve;
|
|
104
|
+
const onSigInt = () => {
|
|
105
|
+
monitorClient.close();
|
|
106
|
+
process.off('SIGINT', onSigInt);
|
|
107
|
+
resolve();
|
|
108
|
+
};
|
|
109
|
+
process.on('SIGINT', onSigInt);
|
|
110
|
+
});
|
|
111
|
+
return Array.from(machineMap.values());
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
async function getSnapshotMachines(params) {
|
|
115
|
+
const { apiClient, machineId, deploymentId, distressed } = params;
|
|
116
|
+
let machines;
|
|
117
|
+
if (distressed) {
|
|
118
|
+
machines = await listDistressedNodes(apiClient);
|
|
119
|
+
}
|
|
120
|
+
else if (machineId) {
|
|
121
|
+
machines = [await getMonitorNode(apiClient, machineId)];
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
machines = await listMonitorNodes(apiClient);
|
|
125
|
+
}
|
|
126
|
+
if (!deploymentId) {
|
|
127
|
+
return machines;
|
|
128
|
+
}
|
|
129
|
+
const results = await Promise.all(machines.map(async (machine) => {
|
|
130
|
+
const containers = await listMonitorNodeContainers(apiClient, machine.machineId);
|
|
131
|
+
const hasDeployment = containers.some((container) => container.deploymentId === deploymentId);
|
|
132
|
+
return hasDeployment ? machine : null;
|
|
133
|
+
}));
|
|
134
|
+
return results.filter((m) => m !== null);
|
|
135
|
+
}
|
|
136
|
+
function toMonitorScope(machineId, deploymentId) {
|
|
137
|
+
if (machineId) {
|
|
138
|
+
return { scope: 'machine', machineId };
|
|
139
|
+
}
|
|
140
|
+
if (deploymentId) {
|
|
141
|
+
return { scope: 'deployment', deploymentId };
|
|
142
|
+
}
|
|
143
|
+
return { scope: 'org' };
|
|
144
|
+
}
|
|
145
|
+
async function applyMonitorMessage(machineMap, message, apiClient, deploymentId) {
|
|
146
|
+
if (message.type === 'snapshot') {
|
|
147
|
+
machineMap.clear();
|
|
148
|
+
for (const machine of message.machines) {
|
|
149
|
+
machineMap.set(machine.machineId, machine);
|
|
150
|
+
}
|
|
151
|
+
if (deploymentId) {
|
|
152
|
+
await filterMapByDeployment(machineMap, apiClient, deploymentId);
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (message.type === 'update') {
|
|
157
|
+
const existing = machineMap.get(message.machineId);
|
|
158
|
+
const next = {
|
|
159
|
+
machineId: message.machineId,
|
|
160
|
+
orgId: existing?.orgId ?? '',
|
|
161
|
+
report: message.report,
|
|
162
|
+
compositeScore: message.report.capacity?.compositeScore ?? existing?.compositeScore ?? 0,
|
|
163
|
+
health: message.health,
|
|
164
|
+
reportedAt: usecToISO(message.report.reportedAtUs) ?? existing?.reportedAt ?? '',
|
|
165
|
+
updatedAt: new Date().toISOString(),
|
|
166
|
+
gravity: existing?.gravity ?? '',
|
|
167
|
+
};
|
|
168
|
+
if (deploymentId) {
|
|
169
|
+
const containers = await listMonitorNodeContainers(apiClient, message.machineId);
|
|
170
|
+
const include = containers.some((container) => container.deploymentId === deploymentId);
|
|
171
|
+
if (!include) {
|
|
172
|
+
machineMap.delete(message.machineId);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
machineMap.set(message.machineId, next);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const existing = machineMap.get(message.machineId);
|
|
180
|
+
if (existing) {
|
|
181
|
+
existing.health = message.health;
|
|
182
|
+
existing.updatedAt = new Date().toISOString();
|
|
183
|
+
machineMap.set(message.machineId, existing);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async function filterMapByDeployment(machineMap, apiClient, deploymentId) {
|
|
187
|
+
const entries = Array.from(machineMap.keys());
|
|
188
|
+
const results = await Promise.all(entries.map(async (machineId) => {
|
|
189
|
+
const containers = await listMonitorNodeContainers(apiClient, machineId);
|
|
190
|
+
const include = containers.some((container) => container.deploymentId === deploymentId);
|
|
191
|
+
return { machineId, include };
|
|
192
|
+
}));
|
|
193
|
+
for (const { machineId, include } of results) {
|
|
194
|
+
if (!include) {
|
|
195
|
+
machineMap.delete(machineId);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function renderWatchTable(machineMap, params) {
|
|
200
|
+
console.clear();
|
|
201
|
+
const subtitle = [
|
|
202
|
+
params.mode === 'watch' ? 'Live mode' : 'Snapshot mode',
|
|
203
|
+
params.machineId ? `machine=${params.machineId}` : undefined,
|
|
204
|
+
params.deploymentId ? `deployment=${params.deploymentId}` : undefined,
|
|
205
|
+
params.distressed ? 'distressed=true' : undefined,
|
|
206
|
+
]
|
|
207
|
+
.filter(Boolean)
|
|
208
|
+
.join(' • ');
|
|
209
|
+
tui.header('Cloud Monitor');
|
|
210
|
+
if (subtitle) {
|
|
211
|
+
tui.info(subtitle);
|
|
212
|
+
}
|
|
213
|
+
if (params.lastMessage && params.lastMessage.type === 'state_change') {
|
|
214
|
+
tui.warning(`${params.lastMessage.machineId}: ${params.lastMessage.previousHealth} -> ${params.lastMessage.health}`);
|
|
215
|
+
}
|
|
216
|
+
renderMachineTable(Array.from(machineMap.values()));
|
|
217
|
+
tui.info('Press Ctrl+C to stop watching.');
|
|
218
|
+
}
|
|
219
|
+
function renderMachineTable(machines) {
|
|
220
|
+
if (machines.length === 0) {
|
|
221
|
+
tui.info('No machines found');
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const rows = machines
|
|
225
|
+
.slice()
|
|
226
|
+
.sort((a, b) => a.machineId.localeCompare(b.machineId))
|
|
227
|
+
.map((machine) => ({
|
|
228
|
+
Machine: machine.machineId,
|
|
229
|
+
Health: formatHealth(machine.health),
|
|
230
|
+
CPU: formatPercent(machine.report?.host?.cpu?.usagePercent),
|
|
231
|
+
Memory: formatPercent(machine.report?.host?.memory?.usagePercent),
|
|
232
|
+
Disk: formatPercent(maxDiskUsage(machine.report?.host?.disks)),
|
|
233
|
+
Pressure: formatScore(machine.compositeScore),
|
|
234
|
+
Containers: `${machine.report?.capacity?.runningContainers ?? 0}/${machine.report?.capacity?.totalContainers ?? 0}`,
|
|
235
|
+
'Last Report': formatAge(machine.reportedAt),
|
|
236
|
+
}));
|
|
237
|
+
tui.table(rows, [
|
|
238
|
+
{ name: 'Machine' },
|
|
239
|
+
{ name: 'Health' },
|
|
240
|
+
{ name: 'CPU', alignment: 'right' },
|
|
241
|
+
{ name: 'Memory', alignment: 'right' },
|
|
242
|
+
{ name: 'Disk', alignment: 'right' },
|
|
243
|
+
{ name: 'Pressure', alignment: 'right' },
|
|
244
|
+
{ name: 'Containers', alignment: 'right' },
|
|
245
|
+
{ name: 'Last Report' },
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
248
|
+
function formatHealth(health) {
|
|
249
|
+
if (health === 'CONNECTED')
|
|
250
|
+
return '● CONNECTED';
|
|
251
|
+
if (health === 'STALE')
|
|
252
|
+
return '◌ STALE';
|
|
253
|
+
if (health === 'DISCONNECTED')
|
|
254
|
+
return '○ DISCONNECTED';
|
|
255
|
+
return health;
|
|
256
|
+
}
|
|
257
|
+
function formatPercent(value) {
|
|
258
|
+
if (value === undefined || value === null || Number.isNaN(value)) {
|
|
259
|
+
return '-';
|
|
260
|
+
}
|
|
261
|
+
return `${value.toFixed(1)}%`;
|
|
262
|
+
}
|
|
263
|
+
function formatScore(score) {
|
|
264
|
+
if (score === undefined || score === null || Number.isNaN(score)) {
|
|
265
|
+
return '-';
|
|
266
|
+
}
|
|
267
|
+
if (score >= 0.85) {
|
|
268
|
+
return `${score.toFixed(2)} ⚠`;
|
|
269
|
+
}
|
|
270
|
+
return score.toFixed(2);
|
|
271
|
+
}
|
|
272
|
+
function maxDiskUsage(disks) {
|
|
273
|
+
if (!disks || disks.length === 0) {
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
return Math.max(...disks.map((d) => d.usagePercent));
|
|
277
|
+
}
|
|
278
|
+
function formatAge(timestamp) {
|
|
279
|
+
const date = new Date(timestamp);
|
|
280
|
+
const time = date.getTime();
|
|
281
|
+
if (Number.isNaN(time)) {
|
|
282
|
+
return '-';
|
|
283
|
+
}
|
|
284
|
+
const diff = Date.now() - time;
|
|
285
|
+
if (diff < 60_000)
|
|
286
|
+
return `${Math.max(0, Math.floor(diff / 1000))}s ago`;
|
|
287
|
+
if (diff < 3_600_000)
|
|
288
|
+
return `${Math.floor(diff / 60_000)}m ago`;
|
|
289
|
+
if (diff < 86_400_000)
|
|
290
|
+
return `${Math.floor(diff / 3_600_000)}h ago`;
|
|
291
|
+
return `${Math.floor(diff / 86_400_000)}d ago`;
|
|
292
|
+
}
|
|
293
|
+
function usecToISO(us) {
|
|
294
|
+
if (us === undefined || us <= 0 || Number.isNaN(us)) {
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
return new Date(Math.floor(us / 1000)).toISOString();
|
|
298
|
+
}
|
|
299
|
+
export default monitorSubcommand;
|
|
300
|
+
//# sourceMappingURL=monitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor.js","sourceRoot":"","sources":["../../../src/cmd/cloud/monitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACN,cAAc,EACd,mBAAmB,EACnB,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,GAItB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AAEjC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;IACxE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,sCAAsC,CAAC;IAClF,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC;IAC/E,QAAQ,EAAE,CAA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AAI,GAAG,UAAU,CAAC,OAAO,CAAC;AAChD,CAAC;AAED,SAAS,SAAS,CAAC,EAAW;IAC7B,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;QACrD,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AACtD,CAAC;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity.d.ts","sourceRoot":"","sources":["../../../../src/cmd/cloud/oidc/activity.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,kBAAkB,yCA8C7B,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { oauthClientActivity } from '@agentuity/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getCommand } from '../../../command-prefix';
|
|
4
|
+
import * as tui from '../../../tui';
|
|
5
|
+
import { createSubcommand } from '../../../types';
|
|
6
|
+
const OAuthClientActivityResponseSchema = z.array(z.object({
|
|
7
|
+
activity_date: z.string(),
|
|
8
|
+
total_access: z.number(),
|
|
9
|
+
unique_users: z.number(),
|
|
10
|
+
}));
|
|
11
|
+
export const activitySubcommand = createSubcommand({
|
|
12
|
+
name: 'activity',
|
|
13
|
+
description: 'Show activity for an OAuth application',
|
|
14
|
+
tags: ['read-only', 'requires-auth'],
|
|
15
|
+
examples: [
|
|
16
|
+
{ command: getCommand('cloud oidc activity <id>'), description: 'Show OAuth activity' },
|
|
17
|
+
{
|
|
18
|
+
command: getCommand('cloud oidc activity <id> --days=30'),
|
|
19
|
+
description: 'Show OAuth activity for last 30 days',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
requires: { auth: true, apiClient: true },
|
|
23
|
+
idempotent: true,
|
|
24
|
+
schema: {
|
|
25
|
+
args: z.object({
|
|
26
|
+
id: z.string().describe('the OAuth client id'),
|
|
27
|
+
}),
|
|
28
|
+
options: z.object({
|
|
29
|
+
days: z.coerce.number().int().min(1).max(365).default(7).describe('Number of days'),
|
|
30
|
+
}),
|
|
31
|
+
response: OAuthClientActivityResponseSchema,
|
|
32
|
+
},
|
|
33
|
+
async handler(ctx) {
|
|
34
|
+
const { args, opts, apiClient, options } = ctx;
|
|
35
|
+
const activity = await tui.spinner('Fetching OAuth activity', () => {
|
|
36
|
+
return oauthClientActivity(apiClient, args.id, opts.days);
|
|
37
|
+
});
|
|
38
|
+
if (!options.json) {
|
|
39
|
+
if (activity.length === 0) {
|
|
40
|
+
tui.info('No OAuth activity found');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const rows = activity.map((item) => ({
|
|
44
|
+
activity_date: item.activity_date,
|
|
45
|
+
total_access: item.total_access,
|
|
46
|
+
unique_users: item.unique_users,
|
|
47
|
+
}));
|
|
48
|
+
tui.table(rows);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return activity;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=activity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity.js","sourceRoot":"","sources":["../../../../src/cmd/cloud/oidc/activity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAkB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,iCAAiC,GAAG,CAAC,CAAC,KAAK,CAChD,CAAC,CAAC,MAAM,CAAC;IACR,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,YA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AI,CAAC,IAAI,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACnB,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3B,GAAG,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;YACrC,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;oBACpC,aAAa,EAAE,IAAI,CAAC,aAAa;oBACjC,YAAY,EAAE,IAAI,CAAC,YAAY;oBAC/B,YAAY,EAAE,IAAI,CAAC,YAAY;iBAC/B,CAAC,CAAC,CAAC;gBAEJ,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;QACF,CAAC;QAED,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/cmd/cloud/oidc/create.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,gBAAgB,yCAoM3B,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { oauthClientCreate, oauthScopes, } from '@agentuity/core';
|
|
2
|
+
import enquirer from 'enquirer';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { getCommand } from '../../../command-prefix';
|
|
5
|
+
import * as tui from '../../../tui';
|
|
6
|
+
import { createSubcommand as createSubcommandHelper } from '../../../types';
|
|
7
|
+
const OAuthClientCreateResponseSchema = z.object({
|
|
8
|
+
client: z.object({
|
|
9
|
+
id: z.string(),
|
|
10
|
+
name: z.string(),
|
|
11
|
+
description: z.string(),
|
|
12
|
+
homepage_url: z.string(),
|
|
13
|
+
client_type: z.enum(['public', 'confidential']),
|
|
14
|
+
redirect_uris: z.array(z.string()),
|
|
15
|
+
scopes: z.array(z.string()),
|
|
16
|
+
created_at: z.string(),
|
|
17
|
+
updated_at: z.string(),
|
|
18
|
+
}),
|
|
19
|
+
client_secret: z.string(),
|
|
20
|
+
});
|
|
21
|
+
function parseCsv(value) {
|
|
22
|
+
if (!value)
|
|
23
|
+
return [];
|
|
24
|
+
return value
|
|
25
|
+
.split(',')
|
|
26
|
+
.map((part) => part.trim())
|
|
27
|
+
.filter(Boolean);
|
|
28
|
+
}
|
|
29
|
+
export const createSubcommand = createSubcommandHelper({
|
|
30
|
+
name: 'create',
|
|
31
|
+
aliases: ['new'],
|
|
32
|
+
description: 'Create a new OAuth application',
|
|
33
|
+
tags: ['creates-resource', 'slow', 'requires-auth'],
|
|
34
|
+
examples: [
|
|
35
|
+
{
|
|
36
|
+
command: getCommand('cloud oidc create --name "My App" --description "OAuth app" --homepage-url "https://example.com" --type confidential --redirect-uris "https://example.com/callback" --scopes "openid,profile,email"'),
|
|
37
|
+
description: 'Create OAuth application non-interactively',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
command: getCommand('cloud oidc create'),
|
|
41
|
+
description: 'Create OAuth application interactively',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
requires: { auth: true, apiClient: true },
|
|
45
|
+
idempotent: false,
|
|
46
|
+
schema: {
|
|
47
|
+
options: z.object({
|
|
48
|
+
name: z.string().optional().describe('the OAuth application name'),
|
|
49
|
+
description: z.string().optional().describe('the OAuth application description'),
|
|
50
|
+
'homepage-url': z.string().optional().describe('the homepage URL'),
|
|
51
|
+
type: z
|
|
52
|
+
.enum(['public', 'confidential'])
|
|
53
|
+
.optional()
|
|
54
|
+
.describe('OAuth client type: public or confidential'),
|
|
55
|
+
'redirect-uris': z
|
|
56
|
+
.string()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('comma-separated redirect URIs (e.g. https://app/callback,https://app/alt)'),
|
|
59
|
+
scopes: z
|
|
60
|
+
.string()
|
|
61
|
+
.optional()
|
|
62
|
+
.describe('comma-separated OAuth scopes (e.g. openid,profile,email)'),
|
|
63
|
+
}),
|
|
64
|
+
response: OAuthClientCreateResponseSchema,
|
|
65
|
+
},
|
|
66
|
+
async handler(ctx) {
|
|
67
|
+
const { opts, apiClient, options } = ctx;
|
|
68
|
+
const availableScopes = await tui.spinner('Fetching available OAuth scopes', () => {
|
|
69
|
+
return oauthScopes(apiClient);
|
|
70
|
+
});
|
|
71
|
+
const nonInteractive = !process.stdin.isTTY || !process.stdout.isTTY;
|
|
72
|
+
let name = opts?.name?.trim() || '';
|
|
73
|
+
let description = opts?.description?.trim() || '';
|
|
74
|
+
let homepageUrl = opts?.['homepage-url']?.trim() || '';
|
|
75
|
+
let clientType = opts?.type;
|
|
76
|
+
let redirectUris = parseCsv(opts?.['redirect-uris']);
|
|
77
|
+
let scopes = parseCsv(opts?.scopes);
|
|
78
|
+
if (!name) {
|
|
79
|
+
if (nonInteractive) {
|
|
80
|
+
tui.fatal('--name is required in non-interactive mode');
|
|
81
|
+
}
|
|
82
|
+
const answer = await enquirer.prompt({
|
|
83
|
+
type: 'input',
|
|
84
|
+
name: 'name',
|
|
85
|
+
message: 'Application name:',
|
|
86
|
+
});
|
|
87
|
+
name = answer.name?.trim() || '';
|
|
88
|
+
}
|
|
89
|
+
if (!description && !nonInteractive) {
|
|
90
|
+
const answer = await enquirer.prompt({
|
|
91
|
+
type: 'input',
|
|
92
|
+
name: 'description',
|
|
93
|
+
message: 'Description:',
|
|
94
|
+
});
|
|
95
|
+
description = answer.description?.trim() || '';
|
|
96
|
+
}
|
|
97
|
+
if (!homepageUrl) {
|
|
98
|
+
if (nonInteractive) {
|
|
99
|
+
tui.fatal('--homepage-url is required in non-interactive mode');
|
|
100
|
+
}
|
|
101
|
+
const answer = await enquirer.prompt({
|
|
102
|
+
type: 'input',
|
|
103
|
+
name: 'homepageUrl',
|
|
104
|
+
message: 'Homepage URL:',
|
|
105
|
+
});
|
|
106
|
+
homepageUrl = answer.homepageUrl?.trim() || '';
|
|
107
|
+
}
|
|
108
|
+
if (!clientType) {
|
|
109
|
+
if (nonInteractive) {
|
|
110
|
+
tui.fatal('--type is required in non-interactive mode');
|
|
111
|
+
}
|
|
112
|
+
const answer = await enquirer.prompt({
|
|
113
|
+
type: 'select',
|
|
114
|
+
name: 'clientType',
|
|
115
|
+
message: 'Client type:',
|
|
116
|
+
choices: [
|
|
117
|
+
{ name: 'public', message: 'public' },
|
|
118
|
+
{ name: 'confidential', message: 'confidential' },
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
clientType = answer.clientType;
|
|
122
|
+
}
|
|
123
|
+
if (redirectUris.length === 0) {
|
|
124
|
+
if (nonInteractive) {
|
|
125
|
+
tui.fatal('--redirect-uris is required in non-interactive mode');
|
|
126
|
+
}
|
|
127
|
+
const answer = await enquirer.prompt({
|
|
128
|
+
type: 'input',
|
|
129
|
+
name: 'redirectUris',
|
|
130
|
+
message: 'Redirect URIs (comma-separated):',
|
|
131
|
+
});
|
|
132
|
+
redirectUris = parseCsv(answer.redirectUris);
|
|
133
|
+
}
|
|
134
|
+
if (scopes.length === 0) {
|
|
135
|
+
if (nonInteractive) {
|
|
136
|
+
tui.fatal('--scopes is required in non-interactive mode');
|
|
137
|
+
}
|
|
138
|
+
const choices = availableScopes.scopes.map((scope) => ({
|
|
139
|
+
name: scope.name,
|
|
140
|
+
message: `${scope.name} — ${scope.description}`,
|
|
141
|
+
}));
|
|
142
|
+
const answer = await enquirer.prompt({
|
|
143
|
+
type: 'multiselect',
|
|
144
|
+
name: 'scopes',
|
|
145
|
+
message: 'Select OAuth scopes:',
|
|
146
|
+
choices,
|
|
147
|
+
});
|
|
148
|
+
scopes = answer.scopes;
|
|
149
|
+
}
|
|
150
|
+
if (!name) {
|
|
151
|
+
tui.fatal('Name is required');
|
|
152
|
+
}
|
|
153
|
+
if (!homepageUrl) {
|
|
154
|
+
tui.fatal('Homepage URL is required');
|
|
155
|
+
}
|
|
156
|
+
if (!clientType) {
|
|
157
|
+
tui.fatal('Client type is required');
|
|
158
|
+
}
|
|
159
|
+
if (redirectUris.length === 0) {
|
|
160
|
+
tui.fatal('At least one redirect URI is required');
|
|
161
|
+
}
|
|
162
|
+
if (scopes.length === 0) {
|
|
163
|
+
tui.fatal('At least one scope is required');
|
|
164
|
+
}
|
|
165
|
+
const availableScopeNames = new Set(availableScopes.scopes.map((scope) => scope.name));
|
|
166
|
+
const invalidScopes = scopes.filter((scope) => !availableScopeNames.has(scope));
|
|
167
|
+
if (invalidScopes.length > 0) {
|
|
168
|
+
tui.fatal(`Invalid scopes: ${invalidScopes.join(', ')}`);
|
|
169
|
+
}
|
|
170
|
+
const request = {
|
|
171
|
+
name,
|
|
172
|
+
description,
|
|
173
|
+
homepage_url: homepageUrl,
|
|
174
|
+
client_type: clientType,
|
|
175
|
+
redirect_uris: redirectUris,
|
|
176
|
+
scopes,
|
|
177
|
+
};
|
|
178
|
+
const result = await tui.spinner('Creating OAuth application', () => {
|
|
179
|
+
return oauthClientCreate(apiClient, request);
|
|
180
|
+
});
|
|
181
|
+
if (!options.json) {
|
|
182
|
+
tui.newline();
|
|
183
|
+
tui.success('OAuth application created successfully!');
|
|
184
|
+
tui.newline();
|
|
185
|
+
tui.warning('Copy the client secret now. It will only be shown once.');
|
|
186
|
+
tui.newline();
|
|
187
|
+
tui.table([
|
|
188
|
+
{
|
|
189
|
+
ID: result.client.id,
|
|
190
|
+
Name: result.client.name,
|
|
191
|
+
Type: result.client.client_type,
|
|
192
|
+
'Client Secret': result.client_secret,
|
|
193
|
+
'Redirect URIs': result.client.redirect_uris.join(', '),
|
|
194
|
+
Scopes: result.client.scopes.join(', '),
|
|
195
|
+
},
|
|
196
|
+
], undefined, { layout: 'vertical' });
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
//# sourceMappingURL=create.js.map
|