@agentage/cli 0.65.0 → 0.65.2
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.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { cliFetch } from '../net/fetch.js';
|
|
2
|
+
const TIMEOUT_MS = 5_000;
|
|
3
|
+
const userOf = (body) => {
|
|
4
|
+
const user = body?.data?.user;
|
|
5
|
+
const { id, email } = user ?? {};
|
|
6
|
+
return typeof id === 'string' && typeof email === 'string' ? { id, email } : undefined;
|
|
7
|
+
};
|
|
8
|
+
// The user a cloud app host's shell shows: auth answers its exchange with { id, email }, so the
|
|
9
|
+
// local shell reads the same fields. The short token in the answer is dropped, never stored.
|
|
10
|
+
export const fetchAccountUser = async (issuer, accessToken) => {
|
|
11
|
+
try {
|
|
12
|
+
const res = await cliFetch(`${issuer}/account/extension-token`, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: { authorization: `Bearer ${accessToken}`, 'content-type': 'application/json' },
|
|
15
|
+
body: JSON.stringify({ extension: 'platform', access: 'read' }),
|
|
16
|
+
}, { timeoutMs: TIMEOUT_MS });
|
|
17
|
+
return res.status === 201 ? userOf(await res.json()) : void (await res.body?.cancel());
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Links } from '../net/origins.js';
|
|
2
|
+
import { fetchAccountUser } from './account-user.js';
|
|
2
3
|
import { startCallbackServer } from './callback-server.js';
|
|
3
4
|
import { introspectToken } from './introspect.js';
|
|
4
5
|
import { exchangeCode, registerClient, revokeToken } from './oauth.js';
|
|
@@ -14,6 +15,7 @@ export interface SignInDeps {
|
|
|
14
15
|
startServer: typeof startCallbackServer;
|
|
15
16
|
openBrowser: (url: string) => Promise<void>;
|
|
16
17
|
introspect: typeof introspectToken;
|
|
18
|
+
accountUser: typeof fetchAccountUser;
|
|
17
19
|
discover: (fqdn: string) => Promise<Links>;
|
|
18
20
|
log: (msg: string) => void;
|
|
19
21
|
}
|
package/dist/lib/auth/sign-in.js
CHANGED
|
@@ -3,6 +3,8 @@ import { deleteAuth, ensureConfigDir, mutateAuth, readAuth } from '../fs/config.
|
|
|
3
3
|
import { discoverTarget } from '../net/discovery.js';
|
|
4
4
|
import { siteFqdn } from '../net/origins.js';
|
|
5
5
|
import { CliError, isJsonRun } from '../json-output.js';
|
|
6
|
+
import { fetchAccountUser } from './account-user.js';
|
|
7
|
+
import { updateSession } from './api.js';
|
|
6
8
|
import { AuthRequiredError } from './auth-errors.js';
|
|
7
9
|
import { startCallbackServer } from './callback-server.js';
|
|
8
10
|
import { credentialLinks, detectEnvMismatch } from './env-match.js';
|
|
@@ -20,6 +22,7 @@ const defaultDeps = {
|
|
|
20
22
|
await open(url);
|
|
21
23
|
},
|
|
22
24
|
introspect: introspectToken,
|
|
25
|
+
accountUser: fetchAccountUser,
|
|
23
26
|
discover: async (fqdn) => (await discoverTarget(fqdn)).links,
|
|
24
27
|
log: (msg) => console.log(msg),
|
|
25
28
|
};
|
|
@@ -56,8 +59,15 @@ export const signIn = async (opts, deps = defaultDeps) => {
|
|
|
56
59
|
const redirectUri = server.redirectUri;
|
|
57
60
|
const res = await deps.exchange(authUrl, { clientId, code, redirectUri, verifier });
|
|
58
61
|
const tokens = tokensFrom(res);
|
|
62
|
+
const user = await deps.accountUser(authUrl, tokens.accessToken);
|
|
59
63
|
const old = readAuth();
|
|
60
|
-
await mutateAuth(() => ({
|
|
64
|
+
await mutateAuth(() => ({
|
|
65
|
+
siteFqdn: fqdn,
|
|
66
|
+
issuer: authUrl,
|
|
67
|
+
clientId,
|
|
68
|
+
tokens,
|
|
69
|
+
...(user && { user }),
|
|
70
|
+
}));
|
|
61
71
|
if (old)
|
|
62
72
|
await revokePlatformPats({ ...old, clientId, tokens }, to);
|
|
63
73
|
deps.log(chalk.green('\nSigned in.\n'));
|
|
@@ -79,10 +89,19 @@ export const signOut = async (deps = defaultDeps) => {
|
|
|
79
89
|
};
|
|
80
90
|
const mismatchNote = (m) => `Signed in to ${m.credentialFqdn} (${m.credentialEnv}), but this run targets ` +
|
|
81
91
|
`${m.targetFqdn} (${m.targetEnv}) - signing you into ${m.targetEnv}.\n`;
|
|
92
|
+
// A session stored before cli 0.66 has no user, so the local shell would show the bare id.
|
|
93
|
+
const rememberUser = async (auth, deps) => {
|
|
94
|
+
if (auth.user || !auth.issuer)
|
|
95
|
+
return;
|
|
96
|
+
const user = await deps.accountUser(auth.issuer, auth.tokens.accessToken);
|
|
97
|
+
if (user)
|
|
98
|
+
await updateSession(auth.clientId, (current) => void (current.user = user));
|
|
99
|
+
};
|
|
82
100
|
// Only a dead session re-signs: a transient verify failure keeps the credentials.
|
|
83
101
|
const verifyStored = async (auth, deps) => {
|
|
84
102
|
try {
|
|
85
103
|
await deps.introspect(auth, credentialLinks(auth));
|
|
104
|
+
await rememberUser(auth, deps);
|
|
86
105
|
deps.log(`Already signed in. Run ${chalk.white('agentage setup --reauth')} to sign in again.\n`);
|
|
87
106
|
return true;
|
|
88
107
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/cli",
|
|
3
|
-
"version": "0.65.
|
|
3
|
+
"version": "0.65.2",
|
|
4
4
|
"description": "The agentage CLI - connect this machine to agentage from the terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"prepublishOnly": "npm run verify"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@agentage/extension": "0.
|
|
57
|
+
"@agentage/extension": "0.19.0",
|
|
58
58
|
"@electric-sql/pglite": "^0.5.16",
|
|
59
59
|
"@tailwindcss/postcss": "^4.3.5",
|
|
60
60
|
"chalk": "^6.0.0",
|