@antasphere/cli-core 0.3.0 → 0.5.0
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/README.md +210 -103
- package/dist/config.d.ts +61 -31
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +42 -27
- package/dist/config.js.map +1 -1
- package/dist/connect-on-demand.d.ts +85 -32
- package/dist/connect-on-demand.d.ts.map +1 -1
- package/dist/connect-on-demand.js +106 -50
- package/dist/connect-on-demand.js.map +1 -1
- package/dist/connect.d.ts +58 -28
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +31 -9
- package/dist/connect.js.map +1 -1
- package/dist/index.d.ts +15 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -9
- package/dist/index.js.map +1 -1
- package/dist/resolve.d.ts +125 -10
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js +167 -8
- package/dist/resolve.js.map +1 -1
- package/package.json +2 -2
- package/src/config.ts +91 -45
- package/src/connect-on-demand.ts +192 -78
- package/src/connect.ts +69 -31
- package/src/index.ts +51 -15
- package/src/resolve.ts +234 -13
- package/dist/org.d.ts +0 -42
- package/dist/org.d.ts.map +0 -1
- package/dist/org.js +0 -39
- package/dist/org.js.map +0 -1
- package/src/org.ts +0 -73
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAA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W,CAAC;IAC9C,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAW,EACX,IAAY,EACZ,WAAmB,EACnB,cAAsB;IAEtB,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC7C,IAAI,CAAC,OAAO,EAAE,WAAW,IAAI,CAAC,CAAC,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;QAAE,OAAO,KAAK,CAAC;IACpF,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IACpE,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;QACjD,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IACnE,CAAC;IACD,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9B,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,27 +1,46 @@
|
|
|
1
1
|
import type { CliEnv } from './config.js';
|
|
2
2
|
import type { CliConnectResult } from './connect.js';
|
|
3
|
+
import type { ResolvedProfile } from './resolve.js';
|
|
3
4
|
/**
|
|
4
5
|
* Connect-on-demand (binding patterns §7, gcloud model), extracted from the
|
|
5
6
|
* Slideless CLI so every Antasphere tool CLI inherits "one `antasphere login`
|
|
6
7
|
* serves every federated tool". When a tool CLI resolves NO credential of its
|
|
7
|
-
* own, it calls `connectOnDemand
|
|
8
|
+
* own, it calls `connectOnDemand` with the profile it selected
|
|
9
|
+
* (`selectProfile`: the profile IS the instance):
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* 0. The cache is consulted FIRST: a key minted earlier for THIS instance
|
|
12
|
+
* under the active hub profile is USER-scoped (hub ADR 014) — it serves
|
|
13
|
+
* every subsequent run and every org, with zero network (no probe, no
|
|
14
|
+
* hub round-trip, no fresh mint). It is read on the selected profile
|
|
15
|
+
* only when that profile is at the resolved instance (its `baseUrl`,
|
|
16
|
+
* else the tool's `cloudUrl` when the profile has none), so a cached
|
|
17
|
+
* key never travels to another origin. `cached: false` skips this step.
|
|
18
|
+
* 1. On a miss, discovery gates the flow: only an Antasphere-CLOUD
|
|
19
|
+
* instance can mint keys through the hub (unauthenticated GET
|
|
20
|
+
* /instance — never guess). Unreachable, foreign, or self-hosted
|
|
21
|
+
* instances answer `not_cloud` and the tool raises its classic no-key
|
|
22
|
+
* error unchanged.
|
|
13
23
|
* 2. The hub credential is what `antasphere login` stored on the hub
|
|
14
24
|
* profile (the config home's HUB_TOOL namespace) — hub URL included,
|
|
15
25
|
* never a hardcoded constant here.
|
|
16
26
|
* 3. `CliConnectClient.exchange` trades it for a tool-local key (one
|
|
17
27
|
* re-exchange retry when the 120 s JWT dies in transit; a rejected hub
|
|
18
|
-
* credential maps to guided `antasphere login` advice
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
28
|
+
* credential maps to guided `antasphere login` advice on either
|
|
29
|
+
* attempt; a hub REFUSAL, a 403 that is not the scope case, propagates
|
|
30
|
+
* as its `CliConnectError` with the hub's own sentence and `exitCode`
|
|
31
|
+
* 3).
|
|
32
|
+
* 4. The minted key is cached on the SELECTED profile under the hub
|
|
33
|
+
* profile's name. A profile not on disk yet is created with this
|
|
34
|
+
* instance's URL, and made active only when the tool had no profile at
|
|
35
|
+
* all; an existing profile is never renamed or repointed, and one that
|
|
36
|
+
* is at another instance never receives the key.
|
|
22
37
|
*
|
|
23
|
-
* A
|
|
24
|
-
*
|
|
38
|
+
* A stranded key recovers: on a 401 with a key that came from the cache,
|
|
39
|
+
* the tool CLI calls `refreshConnectKey` once (evict, exchange again with
|
|
40
|
+
* `cached: false`) and retries its request once; a second 401 fails.
|
|
41
|
+
*
|
|
42
|
+
* A new tool needs only its namespace, its cloud URL, and copy — the flow
|
|
43
|
+
* itself is tool-agnostic.
|
|
25
44
|
*/
|
|
26
45
|
/** What the unauthenticated discovery probe learned about a tool instance. */
|
|
27
46
|
export interface ToolInstanceProbe {
|
|
@@ -40,19 +59,26 @@ export interface ToolInstanceProbe {
|
|
|
40
59
|
* callers treat both exactly like "not cloud".
|
|
41
60
|
*/
|
|
42
61
|
export declare function probeToolInstance(toolBaseUrl: string, fetchImpl?: typeof globalThis.fetch): Promise<ToolInstanceProbe | null>;
|
|
43
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The ACTIVE hub profile — what `antasphere login` stored. Its NAME is the
|
|
64
|
+
* connect cache's slot (config.ts `connectKeys`): stable per hub account on
|
|
65
|
+
* this machine, independent of any org selection.
|
|
66
|
+
*/
|
|
67
|
+
export declare function activeHubProfile(env: CliEnv): ResolvedProfile;
|
|
68
|
+
/** The facts the connected notice is rendered from (fresh exchanges only —
|
|
69
|
+
* cache hits are silent). */
|
|
44
70
|
export interface ConnectNoticeFacts {
|
|
45
71
|
/** The tool instance the exchange connected to (origin-normalized). */
|
|
46
72
|
toolBaseUrl: string;
|
|
47
73
|
/** The signed-in account's email at mint. */
|
|
48
74
|
email: string;
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
75
|
+
/** Whether the minted key was persisted for the next run (on the
|
|
76
|
+
* selected profile, under the hub profile's name); false = the profile
|
|
77
|
+
* is at another instance. */
|
|
78
|
+
stored: boolean;
|
|
53
79
|
/** The tool profile the cache targeted. */
|
|
54
80
|
profileName: string;
|
|
55
|
-
/** When NOT
|
|
81
|
+
/** When NOT stored: the other instance the profile is at. */
|
|
56
82
|
profileBaseUrl?: string;
|
|
57
83
|
}
|
|
58
84
|
/**
|
|
@@ -74,30 +100,42 @@ export interface ConnectOnDemandOptions {
|
|
|
74
100
|
tool: string;
|
|
75
101
|
/** The resolved tool instance origin the CLI is talking to. */
|
|
76
102
|
toolBaseUrl: string;
|
|
103
|
+
/** The tool's cloud URL, the same value `selectProfile` got: what a
|
|
104
|
+
* profile with no `baseUrl` of its own is at. Omit only for a tool with
|
|
105
|
+
* no cloud instance. */
|
|
106
|
+
cloudUrl?: string | undefined;
|
|
77
107
|
/** The exchange resource URL; default = this instance's MCP endpoint,
|
|
78
108
|
* `${toolBaseUrl}/mcp` (the tool's registered resource URL). */
|
|
79
109
|
resource?: string;
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
profileName?: string;
|
|
110
|
+
/** The tool profile the CLI selected for this run (`selectProfile`), the
|
|
111
|
+
* one the minted key is cached on. Not on disk yet → created with
|
|
112
|
+
* `toolBaseUrl` on first contact; at another instance → the key is
|
|
113
|
+
* returned but never stored. cli-core never guesses it. */
|
|
114
|
+
profileName: string;
|
|
86
115
|
env: CliEnv;
|
|
87
116
|
fetch?: typeof globalThis.fetch;
|
|
88
117
|
/** Receives the human "Connected to …" notice (tools wire their stderr);
|
|
89
|
-
* omitted = silent.
|
|
118
|
+
* omitted = silent. Cache hits are always silent either way. */
|
|
90
119
|
notify?: (line: string) => void;
|
|
91
120
|
messages?: ConnectOnDemandMessages;
|
|
121
|
+
/** false = do not read the cache: run the exchange even when a key is
|
|
122
|
+
* cached (the one re-exchange after a 401 on a cached key;
|
|
123
|
+
* `refreshConnectKey` sets it). Default true. */
|
|
124
|
+
cached?: boolean;
|
|
92
125
|
}
|
|
93
126
|
export type ConnectOnDemandOutcome = {
|
|
94
127
|
outcome: 'connected';
|
|
95
|
-
/** The
|
|
128
|
+
/** The tool-local key — this invocation's credential. */
|
|
96
129
|
key: string;
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
130
|
+
/** true = served from the (tool profile, hub profile) config cache:
|
|
131
|
+
* zero network, nothing minted. false = a fresh exchange ran. A 401
|
|
132
|
+
* on a `cached: true` key is what warrants `refreshConnectKey`. */
|
|
100
133
|
cached: boolean;
|
|
134
|
+
/** Fresh exchanges only: the full result (user, key meta). */
|
|
135
|
+
result?: CliConnectResult;
|
|
136
|
+
/** Fresh exchanges only: whether the minted key was persisted for
|
|
137
|
+
* the next run (false = the profile is at another instance). */
|
|
138
|
+
stored?: boolean;
|
|
101
139
|
} | {
|
|
102
140
|
/** Not an Antasphere-cloud instance (or unreachable): the caller
|
|
103
141
|
* raises its classic no-key error unchanged. */
|
|
@@ -105,10 +143,25 @@ export type ConnectOnDemandOutcome = {
|
|
|
105
143
|
};
|
|
106
144
|
/**
|
|
107
145
|
* The hub → tool exchange fallback a tool CLI runs when no direct credential
|
|
108
|
-
* resolved.
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
146
|
+
* resolved. Serves the cached user-scoped key when one exists for this
|
|
147
|
+
* (instance, hub profile) on the selected profile; otherwise returns
|
|
148
|
+
* `not_cloud` when the instance is not an Antasphere-cloud one (or
|
|
149
|
+
* unreachable). Throws a guided `CliUsageError` when the instance IS cloud
|
|
150
|
+
* but the hub login is missing or rejected; a refusal and every other
|
|
151
|
+
* exchange failure propagate as their `CliConnectError` (`exitCode` says 3
|
|
152
|
+
* for the refusal, `message` is the server's own sentence).
|
|
112
153
|
*/
|
|
113
154
|
export declare function connectOnDemand(opts: ConnectOnDemandOptions): Promise<ConnectOnDemandOutcome>;
|
|
155
|
+
/**
|
|
156
|
+
* The stranded-key recovery: what a tool CLI calls once when a request
|
|
157
|
+
* answered 401 with a key that `connectOnDemand` served from the cache
|
|
158
|
+
* (`cached: true`). Evicts that key from the selected profile (the hub
|
|
159
|
+
* revoked it, or a membership was swept), only when that profile is at
|
|
160
|
+
* this instance (a key of another instance is never touched), and runs the
|
|
161
|
+
* exchange again with the cache skipped. The caller retries its request
|
|
162
|
+
* once with the new key and fails on a second 401; `not_cloud` means there
|
|
163
|
+
* is nothing to recover with, and the caller fails with its 401 as it
|
|
164
|
+
* stands.
|
|
165
|
+
*/
|
|
166
|
+
export declare function refreshConnectKey(opts: ConnectOnDemandOptions): Promise<ConnectOnDemandOutcome>;
|
|
114
167
|
//# sourceMappingURL=connect-on-demand.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-on-demand.d.ts","sourceRoot":"","sources":["../src/connect-on-demand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connect-on-demand.d.ts","sourceRoot":"","sources":["../src/connect-on-demand.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,aAAa,CAAC;AAEtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AASrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC;4EACwE;IACxE,KAAK,EAAE,OAAO,CAAC;IACf,gEAAgE;IAChE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,sEAAsE;IACtE,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,GAClC,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAsBnC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EA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AAC;IAChB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;qEACiE;IACjE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GACD;IACE;qDACiD;IACjD,OAAO,EAAE,WAAW,CAAC;CACtB,CAAC;AAoBN;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAgGnG;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAOrG"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { assertToolNamespace, HUB_TOOL, loadConfig,
|
|
1
|
+
import { assertToolNamespace, HUB_TOOL, loadConfig, lookupConnectKey, removeConnectKey, storeConnectKey } from './config.js';
|
|
2
2
|
import { CliConnectClient, CliConnectError } from './connect.js';
|
|
3
|
-
import { CliUsageError,
|
|
3
|
+
import { CliUsageError, firstSet, normalizeUrl, profileUrl, resolveProfile, sameInstance } from './resolve.js';
|
|
4
4
|
/**
|
|
5
5
|
* Probe a tool instance's unauthenticated discovery endpoint
|
|
6
6
|
* (`GET {toolBaseUrl}/api/v1/instance`). Returns what it advertises, or
|
|
@@ -30,6 +30,14 @@ export async function probeToolInstance(toolBaseUrl, fetchImpl) {
|
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* The ACTIVE hub profile — what `antasphere login` stored. Its NAME is the
|
|
35
|
+
* connect cache's slot (config.ts `connectKeys`): stable per hub account on
|
|
36
|
+
* this machine, independent of any org selection.
|
|
37
|
+
*/
|
|
38
|
+
export function activeHubProfile(env) {
|
|
39
|
+
return resolveProfile(loadConfig(env, HUB_TOOL), undefined);
|
|
40
|
+
}
|
|
33
41
|
function defaultMissingHubLogin(tool) {
|
|
34
42
|
const envVar = `${tool.replace(/-/g, '_').toUpperCase()}_API_KEY`;
|
|
35
43
|
return (`This ${tool} instance signs in through the Antasphere hub. Run \`antasphere login\` once, ` +
|
|
@@ -37,23 +45,55 @@ function defaultMissingHubLogin(tool) {
|
|
|
37
45
|
}
|
|
38
46
|
const DEFAULT_HUB_LOGIN_REJECTED = 'The stored Antasphere hub credential was rejected — run `antasphere login` again, then retry.';
|
|
39
47
|
function defaultConnected(facts) {
|
|
40
|
-
return (`Connected to ${facts.toolBaseUrl} as ${facts.email} via Antasphere
|
|
41
|
-
(facts.
|
|
48
|
+
return (`Connected to ${facts.toolBaseUrl} as ${facts.email} via Antasphere` +
|
|
49
|
+
(facts.stored
|
|
42
50
|
? ''
|
|
43
51
|
: ` — key NOT cached: profile '${facts.profileName}' points at ${facts.profileBaseUrl}`) +
|
|
44
52
|
'.\n');
|
|
45
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Where the selected profile stands with respect to the resolved instance:
|
|
56
|
+
* `here` (its `baseUrl`, else the tool's cloud URL, is this instance),
|
|
57
|
+
* `elsewhere` (it is at another instance), or `free` (absent, or with no
|
|
58
|
+
* instance at all: no `baseUrl` and no cloud URL known). The cache is read
|
|
59
|
+
* only when `here`; a key is stored unless `elsewhere`; a key is evicted
|
|
60
|
+
* only when `here`.
|
|
61
|
+
*/
|
|
62
|
+
function placeOf(existing, toolBaseUrl, cloudUrl) {
|
|
63
|
+
const at = existing ? profileUrl(existing, cloudUrl) : undefined;
|
|
64
|
+
if (!existing || at === undefined)
|
|
65
|
+
return { place: 'free' };
|
|
66
|
+
return sameInstance(at, toolBaseUrl) ? { place: 'here', at } : { place: 'elsewhere', at };
|
|
67
|
+
}
|
|
46
68
|
/**
|
|
47
69
|
* The hub → tool exchange fallback a tool CLI runs when no direct credential
|
|
48
|
-
* resolved.
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
70
|
+
* resolved. Serves the cached user-scoped key when one exists for this
|
|
71
|
+
* (instance, hub profile) on the selected profile; otherwise returns
|
|
72
|
+
* `not_cloud` when the instance is not an Antasphere-cloud one (or
|
|
73
|
+
* unreachable). Throws a guided `CliUsageError` when the instance IS cloud
|
|
74
|
+
* but the hub login is missing or rejected; a refusal and every other
|
|
75
|
+
* exchange failure propagate as their `CliConnectError` (`exitCode` says 3
|
|
76
|
+
* for the refusal, `message` is the server's own sentence).
|
|
52
77
|
*/
|
|
53
78
|
export async function connectOnDemand(opts) {
|
|
54
79
|
assertToolNamespace(opts.tool);
|
|
55
|
-
const toolBaseUrl = opts.toolBaseUrl
|
|
80
|
+
const toolBaseUrl = normalizeUrl(opts.toolBaseUrl);
|
|
56
81
|
const messages = opts.messages ?? {};
|
|
82
|
+
const { profileName } = opts;
|
|
83
|
+
// 0. The cache: a key minted earlier by the active hub profile is
|
|
84
|
+
// user-scoped — it serves every run and every org (hub ADR 014; the
|
|
85
|
+
// org is a per-request parameter, never part of the credential). Only
|
|
86
|
+
// the selected profile is read, and only when it is at THIS instance:
|
|
87
|
+
// a cached key never travels to a different instance. A hit costs zero
|
|
88
|
+
// network. `cached: false` (the re-exchange after a 401) skips it.
|
|
89
|
+
const hub = activeHubProfile(opts.env);
|
|
90
|
+
const existing = loadConfig(opts.env, opts.tool).profiles[profileName];
|
|
91
|
+
const { place, at } = placeOf(existing, toolBaseUrl, opts.cloudUrl);
|
|
92
|
+
if (opts.cached !== false && place === 'here' && hub.name) {
|
|
93
|
+
const cachedKey = lookupConnectKey(existing, hub.name);
|
|
94
|
+
if (cachedKey)
|
|
95
|
+
return { outcome: 'connected', key: cachedKey, cached: true };
|
|
96
|
+
}
|
|
57
97
|
// 1. Only a CLOUD instance can mint keys through the hub — ask discovery,
|
|
58
98
|
// never guess. An unreachable or foreign instance is `not_cloud`.
|
|
59
99
|
const probe = await probeToolInstance(toolBaseUrl, opts.fetch);
|
|
@@ -62,69 +102,85 @@ export async function connectOnDemand(opts) {
|
|
|
62
102
|
// 2. The hub credential is what `antasphere login` stored on the hub
|
|
63
103
|
// profile (HUB_TOOL namespace) — one login for the whole tool family.
|
|
64
104
|
// The hub URL comes from that same profile, never from a constant here.
|
|
65
|
-
|
|
66
|
-
const hubKey =
|
|
67
|
-
const hubBaseUrl =
|
|
68
|
-
if (!hubKey || !hubBaseUrl) {
|
|
105
|
+
// A blank field is no field (the package's one blank rule, firstSet).
|
|
106
|
+
const hubKey = firstSet(hub.profile?.apiKey);
|
|
107
|
+
const hubBaseUrl = firstSet(hub.profile?.baseUrl);
|
|
108
|
+
if (!hubKey || !hubBaseUrl || !hub.name) {
|
|
69
109
|
throw new CliUsageError(messages.missingHubLogin ?? defaultMissingHubLogin(opts.tool));
|
|
70
110
|
}
|
|
71
111
|
// 3. The exchange resource defaults to THIS instance's registered resource
|
|
72
112
|
// URL — its MCP endpoint, derived from the resolved instance origin.
|
|
113
|
+
// The body names NO org: the exchange is user-scoped end to end.
|
|
73
114
|
const resource = opts.resource ?? `${toolBaseUrl}/mcp`;
|
|
74
115
|
const connect = new CliConnectClient({
|
|
75
116
|
hubBaseUrl,
|
|
76
117
|
toolBaseUrl,
|
|
77
118
|
...(opts.fetch ? { fetch: opts.fetch } : {})
|
|
78
119
|
});
|
|
79
|
-
const body = { resource
|
|
120
|
+
const body = { resource };
|
|
121
|
+
// One attempt, with the hub's verdict on the KEY mapped to the guided
|
|
122
|
+
// login error whichever attempt it comes on. A refusal (403 that is not
|
|
123
|
+
// the scope case) and every wire error propagate as they are: the error
|
|
124
|
+
// carries the server's own sentence and its exit code.
|
|
125
|
+
const attempt = async () => {
|
|
126
|
+
try {
|
|
127
|
+
return await connect.exchange(hubKey, body);
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
if (e instanceof CliConnectError && e.needsHubLogin) {
|
|
131
|
+
throw new CliUsageError(messages.hubLoginRejected ?? DEFAULT_HUB_LOGIN_REJECTED);
|
|
132
|
+
}
|
|
133
|
+
throw e;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
80
136
|
let result;
|
|
81
137
|
try {
|
|
82
|
-
result = await
|
|
138
|
+
result = await attempt();
|
|
83
139
|
}
|
|
84
140
|
catch (e) {
|
|
85
|
-
if (e instanceof CliConnectError && e.needsReExchange)
|
|
86
|
-
// The 120 s JWT died in transit (expired/replayed) — one fresh
|
|
87
|
-
// exchange; a second rejection propagates.
|
|
88
|
-
result = await connect.exchange(hubKey, body);
|
|
89
|
-
}
|
|
90
|
-
else if (e instanceof CliConnectError && e.needsHubLogin) {
|
|
91
|
-
throw new CliUsageError(messages.hubLoginRejected ?? DEFAULT_HUB_LOGIN_REJECTED);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
141
|
+
if (!(e instanceof CliConnectError && e.needsReExchange))
|
|
94
142
|
throw e;
|
|
95
|
-
|
|
143
|
+
// The 120 s JWT died in transit (expired/replayed) — one fresh
|
|
144
|
+
// exchange; a second rejection propagates.
|
|
145
|
+
result = await attempt();
|
|
96
146
|
}
|
|
97
|
-
// 4. Cache the minted key
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
storeWorkspaceKey(opts.env, opts.tool, profileName, result.hubWorkspaceId, {
|
|
105
|
-
apiKey: result.key,
|
|
106
|
-
toolWorkspaceId: result.toolWorkspaceId,
|
|
107
|
-
email: result.user.email,
|
|
108
|
-
mintedAt: new Date().toISOString()
|
|
109
|
-
});
|
|
110
|
-
if (!existing?.baseUrl) {
|
|
111
|
-
// First contact: pin the profile to this instance so the next
|
|
112
|
-
// invocation resolves the URL and the cached key with no flags.
|
|
113
|
-
const cfg = loadConfig(opts.env, opts.tool);
|
|
114
|
-
cfg.profiles[profileName] = { ...cfg.profiles[profileName], baseUrl: toolBaseUrl };
|
|
115
|
-
saveConfig(opts.env, opts.tool, cfg);
|
|
116
|
-
}
|
|
147
|
+
// 4. Cache the minted key on the SELECTED profile under the hub profile's
|
|
148
|
+
// name. A profile not on disk yet, or one with no instance of its own,
|
|
149
|
+
// takes this instance's URL; a profile at another instance never
|
|
150
|
+
// receives the key and is never repointed.
|
|
151
|
+
const stored = place !== 'elsewhere';
|
|
152
|
+
if (stored) {
|
|
153
|
+
storeConnectKey(opts.env, opts.tool, profileName, hub.name, { apiKey: result.key, email: result.user.email, mintedAt: new Date().toISOString() }, { baseUrl: toolBaseUrl });
|
|
117
154
|
}
|
|
118
155
|
const facts = {
|
|
119
156
|
toolBaseUrl,
|
|
120
157
|
email: result.user.email,
|
|
121
|
-
|
|
122
|
-
cached,
|
|
158
|
+
stored,
|
|
123
159
|
profileName,
|
|
124
|
-
// `
|
|
125
|
-
...(
|
|
160
|
+
// `stored` is false only when the profile is at another instance.
|
|
161
|
+
...(stored ? {} : { profileBaseUrl: at })
|
|
126
162
|
};
|
|
127
163
|
opts.notify?.((messages.connected ?? defaultConnected)(facts));
|
|
128
|
-
return { outcome: 'connected', key: result.key, result, cached };
|
|
164
|
+
return { outcome: 'connected', key: result.key, result, cached: false, stored };
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The stranded-key recovery: what a tool CLI calls once when a request
|
|
168
|
+
* answered 401 with a key that `connectOnDemand` served from the cache
|
|
169
|
+
* (`cached: true`). Evicts that key from the selected profile (the hub
|
|
170
|
+
* revoked it, or a membership was swept), only when that profile is at
|
|
171
|
+
* this instance (a key of another instance is never touched), and runs the
|
|
172
|
+
* exchange again with the cache skipped. The caller retries its request
|
|
173
|
+
* once with the new key and fails on a second 401; `not_cloud` means there
|
|
174
|
+
* is nothing to recover with, and the caller fails with its 401 as it
|
|
175
|
+
* stands.
|
|
176
|
+
*/
|
|
177
|
+
export async function refreshConnectKey(opts) {
|
|
178
|
+
assertToolNamespace(opts.tool);
|
|
179
|
+
const hub = activeHubProfile(opts.env);
|
|
180
|
+
const existing = loadConfig(opts.env, opts.tool).profiles[opts.profileName];
|
|
181
|
+
const { place } = placeOf(existing, normalizeUrl(opts.toolBaseUrl), opts.cloudUrl);
|
|
182
|
+
if (hub.name && place === 'here')
|
|
183
|
+
removeConnectKey(opts.env, opts.tool, opts.profileName, hub.name);
|
|
184
|
+
return connectOnDemand({ ...opts, cached: false });
|
|
129
185
|
}
|
|
130
186
|
//# sourceMappingURL=connect-on-demand.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-on-demand.js","sourceRoot":"","sources":["../src/connect-on-demand.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"connect-on-demand.js","sourceRoot":"","sources":["../src/connect-on-demand.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EACL,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,cAAc,EACd,YAAY,EACb,MAAM,cAAc,CAAC;AAwDtB;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,WAAmB,EACnB,SAAmC;IAEnC,MAAM,CAAC,GAAG,SAAS,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,kBAAkB,EAAE;YACxE,MAAM,EAAE,KAAK;YACb,mEAAmE;YACnE,+DAA+D;YAC/D,KAAK,EAAE,UAAU;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QACzB,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAGxC,CAAC;QACT,MAAM,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC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HANGED
|
@@ -5,16 +5,25 @@ import { CliAuthError, type CliAuthMintedKey } from './auth.js';
|
|
|
5
5
|
* API key is traded for a tool-local key in two calls:
|
|
6
6
|
*
|
|
7
7
|
* 1. POST {hub}/api/v1/sso/tool-token — auth = hub API key (Bearer),
|
|
8
|
-
* body `{ resource
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* body `{ resource }` → a USER-scoped, 120-second JWT for the tool's
|
|
9
|
+
* resource URL plus a one-time `hubRefreshToken` (the tool's standing
|
|
10
|
+
* offline grant for live as-the-user hub reads). Both are OPAQUE to
|
|
11
|
+
* this client: relayed hub → tool, never inspected or stored. The
|
|
12
|
+
* exchange names NO organization (hub ADR 014): the credential
|
|
13
|
+
* identifies the user; the organization is a per-request parameter
|
|
14
|
+
* tool-side, the hub's server-side default unless `--org` says
|
|
15
|
+
* otherwise.
|
|
11
16
|
* 2. POST {tool}/api/v1/sso/cli-connect — NO auth header (the JWT is
|
|
12
|
-
* the credential), body `{ token }` → the tool
|
|
13
|
-
*
|
|
17
|
+
* the credential), body `{ token, hubRefreshToken }` → the tool
|
|
18
|
+
* verifies, JIT-provisions, stores the grant, and mints an ordinary
|
|
19
|
+
* USER-scoped tool-local API key, returned exactly once.
|
|
14
20
|
*
|
|
15
21
|
* The hub key is sent to the HUB only — it never reaches the tool. The
|
|
16
|
-
*
|
|
17
|
-
*
|
|
22
|
+
* hubRefreshToken is sent to the TOOL only (it is that tool's own grant;
|
|
23
|
+
* redeeming it needs the tool client's credentials) and never persisted by
|
|
24
|
+
* the CLI. The minted key is cached per (tool profile, hub profile) in the
|
|
25
|
+
* tool's config namespace (config.ts `connectKeys`), on the profile of the
|
|
26
|
+
* instance it was minted for; day-to-day tool CLI calls then take the
|
|
18
27
|
* ordinary local API-key path with the hub out of the loop.
|
|
19
28
|
*/
|
|
20
29
|
export type CliConnectStage = 'hub' | 'tool';
|
|
@@ -23,10 +32,10 @@ export type CliConnectStage = 'hub' | 'tool';
|
|
|
23
32
|
* pick the remedy without string-matching:
|
|
24
33
|
*
|
|
25
34
|
* - hub 400 `unknown_resource` — the resource URL is not in the registry.
|
|
26
|
-
* - hub 403 `no_membership` / `workspace_suspended` — the target org is
|
|
27
|
-
* not exchangeable for this user; pick another org.
|
|
28
35
|
* - `needsHubLogin` — the hub rejected the KEY itself; re-run
|
|
29
36
|
* `antasphere login`.
|
|
37
|
+
* - `refusal` — the account was refused (403), not the key: print the
|
|
38
|
+
* server's own sentence and exit 3. No login fixes it.
|
|
30
39
|
* - `needsReExchange` — the tool rejected the 120 s JWT (expired/replayed
|
|
31
40
|
* in transit); run the exchange again.
|
|
32
41
|
* - tool 429 `rate_limited` — back off and retry.
|
|
@@ -42,21 +51,35 @@ export declare class CliConnectError extends CliAuthError {
|
|
|
42
51
|
get needsHubLogin(): boolean;
|
|
43
52
|
/** The tool rejected the JWT (expired/replayed) — run the exchange again. */
|
|
44
53
|
get needsReExchange(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* The person was refused, not the credential: a 403 that is not the
|
|
56
|
+
* scope case, from either side (`tool_access_denied` on a restricted
|
|
57
|
+
* tool, `unverified_email`, a grant the tool will not take). `message`
|
|
58
|
+
* is the server's own sentence; a runner prints it as is and exits
|
|
59
|
+
* `exitCode`, 3, the code the tool docs promise for a refusal.
|
|
60
|
+
*/
|
|
61
|
+
get refusal(): boolean;
|
|
62
|
+
/** The exit code a runner uses for this error: 3 for a refusal, 1 otherwise. */
|
|
63
|
+
get exitCode(): number;
|
|
45
64
|
}
|
|
46
65
|
export interface CliToolTokenBody {
|
|
47
|
-
/** The tool's registry resource URL (e.g. `https://app.slideless.ai/mcp`).
|
|
66
|
+
/** The tool's registry resource URL (e.g. `https://app.slideless.ai/mcp`).
|
|
67
|
+
* The ONLY field — the exchange is user-scoped and names no org
|
|
68
|
+
* (hub contract `ssoToolTokenRequestSchema`, ADR 014). */
|
|
48
69
|
resource: string;
|
|
49
|
-
/** Target hub org — any live ACTIVE membership of the user (gcloud
|
|
50
|
-
* model); omit = the hub key's bound workspace. */
|
|
51
|
-
workspaceId?: string;
|
|
52
70
|
}
|
|
71
|
+
/** The hub's tool-token response (hub contract `ssoToolTokenSchema`). */
|
|
53
72
|
export interface CliToolTokenMinted {
|
|
54
|
-
/** The
|
|
73
|
+
/** The user-scoped exchange JWT — opaque, ~120 s; relay it, never keep it. */
|
|
55
74
|
token: string;
|
|
56
75
|
/** ISO expiry of the JWT (informational; the minted key outlives it). */
|
|
57
76
|
expiresAt: string;
|
|
58
|
-
/** The
|
|
59
|
-
|
|
77
|
+
/** The raw one-time offline-grant refresh token for the TARGET TOOL —
|
|
78
|
+
* relayed to that tool's /sso/cli-connect exactly once (it stores it as
|
|
79
|
+
* the standing grant for live as-the-user hub reads) and NEVER persisted
|
|
80
|
+
* or logged by the CLI. Without it, a fresh CLI user's connect is
|
|
81
|
+
* refused tool-side (`hub_grant_missing` — no key is minted born-dead). */
|
|
82
|
+
hubRefreshToken: string;
|
|
60
83
|
}
|
|
61
84
|
export interface CliConnected {
|
|
62
85
|
/** Full tool-local key (`slk_`-style) — shown once, never retrievable. */
|
|
@@ -67,12 +90,14 @@ export interface CliConnected {
|
|
|
67
90
|
email: string;
|
|
68
91
|
name: string;
|
|
69
92
|
};
|
|
70
|
-
/** The tool
|
|
71
|
-
|
|
93
|
+
/** The tool workspace the key is PINNED to — null on the live contract
|
|
94
|
+
* (user-scoped, unpinned; the org is a per-request parameter). */
|
|
95
|
+
workspaceId: string | null;
|
|
72
96
|
}
|
|
73
|
-
/** The flattened outcome of a full exchange
|
|
97
|
+
/** The flattened outcome of a full exchange. */
|
|
74
98
|
export interface CliConnectResult {
|
|
75
|
-
/** Full tool-local key —
|
|
99
|
+
/** Full tool-local key — user-scoped: ONE per (tool profile, hub profile),
|
|
100
|
+
* valid for every org the user can select per request (config.ts). */
|
|
76
101
|
key: string;
|
|
77
102
|
apiKey: CliAuthMintedKey;
|
|
78
103
|
user: {
|
|
@@ -80,10 +105,9 @@ export interface CliConnectResult {
|
|
|
80
105
|
email: string;
|
|
81
106
|
name: string;
|
|
82
107
|
};
|
|
83
|
-
/** The
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
toolWorkspaceId: string;
|
|
108
|
+
/** The tool workspace the key is pinned to — null = unpinned (the live
|
|
109
|
+
* contract always answers null; informational). */
|
|
110
|
+
toolWorkspaceId: string | null;
|
|
87
111
|
}
|
|
88
112
|
export interface CliConnectClientOptions {
|
|
89
113
|
/** Hub origin, e.g. https://account.antasphere.com */
|
|
@@ -97,11 +121,17 @@ export declare class CliConnectClient {
|
|
|
97
121
|
private readonly toolBaseUrl;
|
|
98
122
|
private readonly fetchImpl;
|
|
99
123
|
constructor(options: CliConnectClientOptions);
|
|
100
|
-
/** Step 1 — the hub mints the 120 s
|
|
124
|
+
/** Step 1 — the hub mints the 120 s user-scoped JWT for the tool's resource. */
|
|
101
125
|
toolToken(hubApiKey: string, body: CliToolTokenBody): Promise<CliToolTokenMinted>;
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Step 2 — the tool verifies the JWT (its only credential) and mints its
|
|
128
|
+
* key. `hubRefreshToken` is the SAME response's offline grant, relayed so
|
|
129
|
+
* the tool can store it (a grant-less connect is refused for users with
|
|
130
|
+
* none already stored — `hub_grant_missing`).
|
|
131
|
+
*/
|
|
132
|
+
cliConnect(token: string, hubRefreshToken?: string): Promise<CliConnected>;
|
|
133
|
+
/** The full two-call exchange. The hub key goes to the hub ONLY; the
|
|
134
|
+
* offline grant goes to the TOOL only — neither is ever persisted here. */
|
|
105
135
|
exchange(hubApiKey: string, body: CliToolTokenBody): Promise<CliConnectResult>;
|
|
106
136
|
/** Mirrors CliAuthClient's parse: `{ error: { code, message, details } }` envelopes. */
|
|
107
137
|
private call;
|