@dexto/agent-management 1.15.0-beta.2 → 1.16.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/dist/auth/index.cjs +0 -25
- package/dist/auth/index.d.ts +0 -6
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +0 -10
- package/dist/auth/model-auth-handlers.cjs +1 -3
- package/dist/auth/model-auth-handlers.d.ts +1 -6
- package/dist/auth/model-auth-handlers.d.ts.map +1 -1
- package/dist/auth/model-auth-handlers.js +1 -6
- package/dist/config/errors.cjs +6 -6
- package/dist/config/errors.js +6 -6
- package/dist/images/image-store.cjs +4 -2
- package/dist/images/image-store.d.ts.map +1 -1
- package/dist/images/image-store.js +4 -2
- package/dist/index.cjs +29 -40
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -9
- package/dist/installation.cjs +2 -2
- package/dist/installation.js +2 -2
- package/dist/plugins/discover-skills.cjs +2 -5
- package/dist/plugins/discover-skills.d.ts +2 -6
- package/dist/plugins/discover-skills.d.ts.map +1 -1
- package/dist/plugins/discover-skills.js +2 -5
- package/dist/plugins/errors.cjs +2 -2
- package/dist/plugins/errors.js +2 -2
- package/dist/plugins/marketplace/errors.cjs +4 -4
- package/dist/plugins/marketplace/errors.js +4 -4
- package/dist/preferences/errors.cjs +1 -1
- package/dist/preferences/errors.js +1 -1
- package/dist/registry/registry.cjs +3 -3
- package/dist/registry/registry.js +3 -3
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.js +1 -1
- package/dist/tool-factories/agent-spawner/factory.cjs +218 -1
- package/dist/tool-factories/agent-spawner/factory.d.ts.map +1 -1
- package/dist/tool-factories/agent-spawner/factory.js +228 -1
- package/dist/utils/dexto-auth.cjs +58 -3
- package/dist/utils/dexto-auth.d.ts +18 -4
- package/dist/utils/dexto-auth.d.ts.map +1 -1
- package/dist/utils/dexto-auth.js +57 -3
- package/package.json +6 -5
- package/dist/auth/dexto-accounts.cjs +0 -277
- package/dist/auth/dexto-accounts.d.ts +0 -144
- package/dist/auth/dexto-accounts.d.ts.map +0 -1
- package/dist/auth/dexto-accounts.js +0 -230
- package/dist/auth/dexto-cloud.cjs +0 -51
- package/dist/auth/dexto-cloud.d.ts +0 -9
- package/dist/auth/dexto-cloud.d.ts.map +0 -1
- package/dist/auth/dexto-cloud.js +0 -27
- package/dist/auth/dexto-gateway.cjs +0 -162
- package/dist/auth/dexto-gateway.d.ts +0 -55
- package/dist/auth/dexto-gateway.d.ts.map +0 -1
- package/dist/auth/dexto-gateway.js +0 -133
- package/dist/auth/dexto-mcp.cjs +0 -77
- package/dist/auth/dexto-mcp.d.ts +0 -23
- package/dist/auth/dexto-mcp.d.ts.map +0 -1
- package/dist/auth/dexto-mcp.js +0 -49
- package/dist/auth/dexto-sign-in.cjs +0 -345
- package/dist/auth/dexto-sign-in.d.ts +0 -86
- package/dist/auth/dexto-sign-in.d.ts.map +0 -1
- package/dist/auth/dexto-sign-in.js +0 -314
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var dexto_sign_in_exports = {};
|
|
20
|
-
__export(dexto_sign_in_exports, {
|
|
21
|
-
DEXTO_CLI_CLIENT_ID: () => DEXTO_CLI_CLIENT_ID,
|
|
22
|
-
OAuthHttpError: () => OAuthHttpError,
|
|
23
|
-
SignInEnded: () => SignInEnded,
|
|
24
|
-
endSignIn: () => endSignIn,
|
|
25
|
-
refreshSignIn: () => refreshSignIn,
|
|
26
|
-
signInPromptText: () => signInPromptText,
|
|
27
|
-
signInWithBrowser: () => signInWithBrowser,
|
|
28
|
-
signInWithDevice: () => signInWithDevice
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(dexto_sign_in_exports);
|
|
31
|
-
var import_node_crypto = require("node:crypto");
|
|
32
|
-
var import_zod = require("zod");
|
|
33
|
-
var import_dexto_accounts = require("./dexto-accounts.js");
|
|
34
|
-
const DEXTO_CLI_CLIENT_ID = "dexto-cli";
|
|
35
|
-
const BASE_CLOUD_SCOPES = ["cloud:read"];
|
|
36
|
-
const DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
37
|
-
const LOGIN_TIMEOUT_MS = 5 * 6e4;
|
|
38
|
-
const END_SIGN_IN_TIMEOUT_MS = 1e4;
|
|
39
|
-
function signInPromptText(prompt) {
|
|
40
|
-
if (prompt.kind === "browser")
|
|
41
|
-
return `Sign in to Dexto in your browser. If it doesn't open, visit:
|
|
42
|
-
${prompt.authorizeUrl}`;
|
|
43
|
-
return [
|
|
44
|
-
prompt.verificationUriComplete === null ? `To sign in, open this link on any device and enter ${prompt.userCode}:
|
|
45
|
-
${prompt.verificationUri}` : `To sign in, open this link on any device and check it shows ${prompt.userCode}:
|
|
46
|
-
${prompt.verificationUriComplete}`,
|
|
47
|
-
"Only approve this if you just ran dexto login."
|
|
48
|
-
].join("\n");
|
|
49
|
-
}
|
|
50
|
-
class SignInEnded extends Error {
|
|
51
|
-
constructor(reason, message) {
|
|
52
|
-
super(message);
|
|
53
|
-
this.reason = reason;
|
|
54
|
-
this.name = "SignInEnded";
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const ProtectedResourceSchema = import_zod.z.object({
|
|
58
|
-
authorization_servers: import_zod.z.array(import_zod.z.string().url()).min(1),
|
|
59
|
-
resource: import_zod.z.string().url(),
|
|
60
|
-
scopes_supported: import_zod.z.array(import_zod.z.string())
|
|
61
|
-
});
|
|
62
|
-
const AuthorizationServerSchema = import_zod.z.object({
|
|
63
|
-
authorization_endpoint: import_zod.z.string().url(),
|
|
64
|
-
device_authorization_endpoint: import_zod.z.string().url(),
|
|
65
|
-
revocation_endpoint: import_zod.z.string().url(),
|
|
66
|
-
token_endpoint: import_zod.z.string().url()
|
|
67
|
-
});
|
|
68
|
-
const TokenResponseSchema = import_zod.z.object({
|
|
69
|
-
access_token: import_zod.z.string().min(1),
|
|
70
|
-
refresh_token: import_zod.z.string().min(1),
|
|
71
|
-
expires_in: import_zod.z.number().int().positive(),
|
|
72
|
-
scope: import_zod.z.string(),
|
|
73
|
-
/** Who the tokens act as. */
|
|
74
|
-
dexto_account: import_dexto_accounts.SignedInAsSchema.shape.account.optional(),
|
|
75
|
-
dexto_organization: import_dexto_accounts.SignedInAsSchema.shape.organization.optional()
|
|
76
|
-
});
|
|
77
|
-
const DeviceAuthorizationSchema = import_zod.z.object({
|
|
78
|
-
device_code: import_zod.z.string().min(1),
|
|
79
|
-
user_code: import_zod.z.string().min(1),
|
|
80
|
-
expires_in: import_zod.z.number().int().positive(),
|
|
81
|
-
interval: import_zod.z.number().int().positive().optional(),
|
|
82
|
-
verification_uri: import_zod.z.string().url(),
|
|
83
|
-
verification_uri_complete: import_zod.z.string().url().optional()
|
|
84
|
-
});
|
|
85
|
-
async function readMetadata(runtime, appUrl) {
|
|
86
|
-
const resource = ProtectedResourceSchema.parse(
|
|
87
|
-
await getJson(runtime, `${appUrl}/.well-known/oauth-protected-resource/mcp`)
|
|
88
|
-
);
|
|
89
|
-
const issuer = (resource.authorization_servers[0] ?? appUrl).replace(/\/+$/u, "");
|
|
90
|
-
const server = AuthorizationServerSchema.parse(
|
|
91
|
-
await getJson(runtime, `${issuer}/.well-known/oauth-authorization-server`)
|
|
92
|
-
);
|
|
93
|
-
return { resource, server };
|
|
94
|
-
}
|
|
95
|
-
async function discover(runtime, input) {
|
|
96
|
-
const appUrl = input.appUrl.replace(/\/+$/u, "");
|
|
97
|
-
const { resource, server } = await readMetadata(runtime, appUrl);
|
|
98
|
-
const reading = resource.scopes_supported.filter((scope) => scope.endsWith(":read"));
|
|
99
|
-
const scopes = [.../* @__PURE__ */ new Set([...reading, ...BASE_CLOUD_SCOPES, ...input.extraScopes])];
|
|
100
|
-
return { appUrl, resource: resource.resource, scopes, server };
|
|
101
|
-
}
|
|
102
|
-
async function signInWithBrowser(runtime, input) {
|
|
103
|
-
const { appUrl, resource, scopes, server } = await discover(runtime, input);
|
|
104
|
-
const redirect = await runtime.listenForRedirect(appUrl);
|
|
105
|
-
try {
|
|
106
|
-
const verifier = (0, import_node_crypto.randomBytes)(32).toString("base64url");
|
|
107
|
-
const state = (0, import_node_crypto.randomBytes)(16).toString("base64url");
|
|
108
|
-
const authorizeUrl = new URL(server.authorization_endpoint);
|
|
109
|
-
for (const [name, value] of Object.entries({
|
|
110
|
-
client_id: DEXTO_CLI_CLIENT_ID,
|
|
111
|
-
code_challenge: (0, import_node_crypto.createHash)("sha256").update(verifier).digest("base64url"),
|
|
112
|
-
code_challenge_method: "S256",
|
|
113
|
-
redirect_uri: redirect.redirectUri,
|
|
114
|
-
resource,
|
|
115
|
-
response_type: "code",
|
|
116
|
-
scope: scopes.join(" "),
|
|
117
|
-
state,
|
|
118
|
-
...input.organization === null ? {} : { organization: input.organization }
|
|
119
|
-
}))
|
|
120
|
-
authorizeUrl.searchParams.set(name, value);
|
|
121
|
-
runtime.prompt({ kind: "browser", authorizeUrl: authorizeUrl.toString() });
|
|
122
|
-
if (input.openBrowser) await runtime.openBrowser(authorizeUrl.toString());
|
|
123
|
-
const params = await withTimeout(redirect.result, LOGIN_TIMEOUT_MS, runtime.signal);
|
|
124
|
-
if (params.get("state") !== state)
|
|
125
|
-
throw new Error("The sign-in reply didn't match this login.");
|
|
126
|
-
const error = params.get("error");
|
|
127
|
-
if (error !== null)
|
|
128
|
-
throw error === "access_denied" ? new SignInEnded("declined", "Sign-in was declined.") : new Error(`Sign-in failed: ${params.get("error_description") ?? error}.`);
|
|
129
|
-
const code = params.get("code");
|
|
130
|
-
if (code === null) throw new Error("The sign-in reply had no code.");
|
|
131
|
-
const tokens = TokenResponseSchema.parse(
|
|
132
|
-
await postForm(runtime, server.token_endpoint, {
|
|
133
|
-
client_id: DEXTO_CLI_CLIENT_ID,
|
|
134
|
-
code,
|
|
135
|
-
code_verifier: verifier,
|
|
136
|
-
grant_type: "authorization_code",
|
|
137
|
-
redirect_uri: redirect.redirectUri,
|
|
138
|
-
resource
|
|
139
|
-
})
|
|
140
|
-
);
|
|
141
|
-
return toLogin(tokens, {
|
|
142
|
-
apiBaseUrl: input.apiBaseUrl,
|
|
143
|
-
appUrl,
|
|
144
|
-
resource,
|
|
145
|
-
tokenEndpoint: server.token_endpoint
|
|
146
|
-
});
|
|
147
|
-
} finally {
|
|
148
|
-
redirect.close();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async function signInWithDevice(runtime, input) {
|
|
152
|
-
const { appUrl, resource, scopes, server } = await discover(runtime, input);
|
|
153
|
-
const device = DeviceAuthorizationSchema.parse(
|
|
154
|
-
await postForm(runtime, server.device_authorization_endpoint, {
|
|
155
|
-
client_id: DEXTO_CLI_CLIENT_ID,
|
|
156
|
-
resource,
|
|
157
|
-
scope: scopes.join(" "),
|
|
158
|
-
...input.organization === null ? {} : { organization: input.organization }
|
|
159
|
-
})
|
|
160
|
-
);
|
|
161
|
-
runtime.prompt({
|
|
162
|
-
kind: "device",
|
|
163
|
-
userCode: device.user_code,
|
|
164
|
-
verificationUri: device.verification_uri,
|
|
165
|
-
verificationUriComplete: device.verification_uri_complete ?? null,
|
|
166
|
-
expiresInSeconds: device.expires_in
|
|
167
|
-
});
|
|
168
|
-
const deadline = Date.now() + device.expires_in * 1e3;
|
|
169
|
-
let intervalSeconds = device.interval ?? 5;
|
|
170
|
-
while (Date.now() < deadline) {
|
|
171
|
-
await runtime.sleep(intervalSeconds * 1e3);
|
|
172
|
-
try {
|
|
173
|
-
const tokens = TokenResponseSchema.parse(
|
|
174
|
-
await postForm(runtime, server.token_endpoint, {
|
|
175
|
-
client_id: DEXTO_CLI_CLIENT_ID,
|
|
176
|
-
device_code: device.device_code,
|
|
177
|
-
grant_type: DEVICE_CODE_GRANT_TYPE,
|
|
178
|
-
resource
|
|
179
|
-
})
|
|
180
|
-
);
|
|
181
|
-
return toLogin(tokens, {
|
|
182
|
-
apiBaseUrl: input.apiBaseUrl,
|
|
183
|
-
appUrl,
|
|
184
|
-
resource,
|
|
185
|
-
tokenEndpoint: server.token_endpoint
|
|
186
|
-
});
|
|
187
|
-
} catch (error) {
|
|
188
|
-
if (error instanceof TypeError) continue;
|
|
189
|
-
if (!(error instanceof OAuthHttpError)) throw error;
|
|
190
|
-
if (error.status >= 500 || error.code === "authorization_pending") continue;
|
|
191
|
-
if (error.code === "slow_down") {
|
|
192
|
-
intervalSeconds += 5;
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
if (error.code === "access_denied")
|
|
196
|
-
throw new SignInEnded("declined", "Sign-in was declined.");
|
|
197
|
-
if (error.code !== "expired_token") throw error;
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
throw new SignInEnded("expired", "The sign-in code expired. Run dexto login --device again.");
|
|
202
|
-
}
|
|
203
|
-
function toLogin(tokens, client) {
|
|
204
|
-
return {
|
|
205
|
-
kind: "oauth",
|
|
206
|
-
...client,
|
|
207
|
-
clientId: DEXTO_CLI_CLIENT_ID,
|
|
208
|
-
accessToken: tokens.access_token,
|
|
209
|
-
refreshToken: tokens.refresh_token,
|
|
210
|
-
expiresAt: expiresAt(tokens.expires_in),
|
|
211
|
-
scopes: splitScopes(tokens.scope),
|
|
212
|
-
savedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
213
|
-
signedInAs: signedInAsFrom(tokens),
|
|
214
|
-
cloudProject: null
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
function signedInAsFrom(tokens) {
|
|
218
|
-
return tokens.dexto_account === void 0 || tokens.dexto_organization === void 0 ? null : { account: tokens.dexto_account, organization: tokens.dexto_organization };
|
|
219
|
-
}
|
|
220
|
-
async function refreshSignIn(runtime, login) {
|
|
221
|
-
let body;
|
|
222
|
-
try {
|
|
223
|
-
body = await postForm(runtime, login.tokenEndpoint, {
|
|
224
|
-
client_id: login.clientId,
|
|
225
|
-
grant_type: "refresh_token",
|
|
226
|
-
refresh_token: login.refreshToken,
|
|
227
|
-
resource: login.resource
|
|
228
|
-
});
|
|
229
|
-
} catch (error) {
|
|
230
|
-
if (error instanceof OAuthHttpError && error.status === 400)
|
|
231
|
-
throw new Error("Your Dexto sign-in has expired. Run dexto login again.");
|
|
232
|
-
throw error;
|
|
233
|
-
}
|
|
234
|
-
const tokens = TokenResponseSchema.parse(body);
|
|
235
|
-
return {
|
|
236
|
-
...login,
|
|
237
|
-
accessToken: tokens.access_token,
|
|
238
|
-
refreshToken: tokens.refresh_token,
|
|
239
|
-
expiresAt: expiresAt(tokens.expires_in),
|
|
240
|
-
scopes: splitScopes(tokens.scope),
|
|
241
|
-
signedInAs: signedInAsFrom(tokens) ?? login.signedInAs
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
async function endSignIn(runtime, login) {
|
|
245
|
-
const bounded = {
|
|
246
|
-
...runtime,
|
|
247
|
-
signal: AbortSignal.any([runtime.signal, AbortSignal.timeout(END_SIGN_IN_TIMEOUT_MS)])
|
|
248
|
-
};
|
|
249
|
-
try {
|
|
250
|
-
const { server } = await readMetadata(bounded, login.appUrl.replace(/\/+$/u, ""));
|
|
251
|
-
await postForm(bounded, server.revocation_endpoint, {
|
|
252
|
-
client_id: login.clientId,
|
|
253
|
-
token: login.refreshToken,
|
|
254
|
-
token_type_hint: "refresh_token"
|
|
255
|
-
});
|
|
256
|
-
return { status: "ended" };
|
|
257
|
-
} catch (error) {
|
|
258
|
-
return { status: "failed", reason: error instanceof Error ? error.message : String(error) };
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
class OAuthHttpError extends Error {
|
|
262
|
-
/** The OAuth `error` code, such as `authorization_pending`; null when the reply had none. */
|
|
263
|
-
code;
|
|
264
|
-
status;
|
|
265
|
-
constructor(status, code, message) {
|
|
266
|
-
super(message);
|
|
267
|
-
this.name = "OAuthHttpError";
|
|
268
|
-
this.code = code;
|
|
269
|
-
this.status = status;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
async function getJson(runtime, url) {
|
|
273
|
-
return await readJson(
|
|
274
|
-
await runtime.fetch(url, {
|
|
275
|
-
headers: { accept: "application/json" },
|
|
276
|
-
signal: runtime.signal
|
|
277
|
-
}),
|
|
278
|
-
url
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
async function postForm(runtime, url, fields) {
|
|
282
|
-
return await readJson(
|
|
283
|
-
await runtime.fetch(url, {
|
|
284
|
-
body: new URLSearchParams(fields),
|
|
285
|
-
headers: { accept: "application/json" },
|
|
286
|
-
method: "POST",
|
|
287
|
-
signal: runtime.signal
|
|
288
|
-
}),
|
|
289
|
-
url
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
const OAuthErrorSchema = import_zod.z.object({
|
|
293
|
-
error: import_zod.z.string().optional(),
|
|
294
|
-
error_description: import_zod.z.string().optional()
|
|
295
|
-
});
|
|
296
|
-
async function readJson(response, url) {
|
|
297
|
-
const text = await response.text();
|
|
298
|
-
if (response.ok) return text.length === 0 ? null : JSON.parse(text);
|
|
299
|
-
const reply = OAuthErrorSchema.safeParse(parseOrNull(text));
|
|
300
|
-
const code = reply.success ? reply.data.error ?? null : null;
|
|
301
|
-
const description = (reply.success ? reply.data.error_description : void 0) ?? code ?? `HTTP ${response.status}`;
|
|
302
|
-
throw new OAuthHttpError(response.status, code, `${new URL(url).pathname}: ${description}`);
|
|
303
|
-
}
|
|
304
|
-
function parseOrNull(text) {
|
|
305
|
-
try {
|
|
306
|
-
return JSON.parse(text);
|
|
307
|
-
} catch {
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
async function withTimeout(promise, ms, signal) {
|
|
312
|
-
let timer;
|
|
313
|
-
const stop = new Promise((_, reject) => {
|
|
314
|
-
timer = setTimeout(() => reject(new SignInEnded("timed_out", "Sign-in timed out.")), ms);
|
|
315
|
-
signal.addEventListener(
|
|
316
|
-
"abort",
|
|
317
|
-
() => reject(new SignInEnded("cancelled", "Sign-in was cancelled.")),
|
|
318
|
-
{
|
|
319
|
-
once: true
|
|
320
|
-
}
|
|
321
|
-
);
|
|
322
|
-
});
|
|
323
|
-
try {
|
|
324
|
-
return await Promise.race([promise, stop]);
|
|
325
|
-
} finally {
|
|
326
|
-
clearTimeout(timer);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
function splitScopes(scope) {
|
|
330
|
-
return scope.split(" ").filter((each) => each.length > 0);
|
|
331
|
-
}
|
|
332
|
-
function expiresAt(expiresInSeconds) {
|
|
333
|
-
return new Date(Date.now() + expiresInSeconds * 1e3).toISOString();
|
|
334
|
-
}
|
|
335
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
336
|
-
0 && (module.exports = {
|
|
337
|
-
DEXTO_CLI_CLIENT_ID,
|
|
338
|
-
OAuthHttpError,
|
|
339
|
-
SignInEnded,
|
|
340
|
-
endSignIn,
|
|
341
|
-
refreshSignIn,
|
|
342
|
-
signInPromptText,
|
|
343
|
-
signInWithBrowser,
|
|
344
|
-
signInWithDevice
|
|
345
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { type OAuthLogin } from './dexto-accounts.js';
|
|
2
|
-
/** Dexto's pre-registered public client for this CLI: no secret, no registration. */
|
|
3
|
-
export declare const DEXTO_CLI_CLIENT_ID = "dexto-cli";
|
|
4
|
-
/** A loopback listener for the browser's redirect back to the CLI. */
|
|
5
|
-
export interface RedirectListener {
|
|
6
|
-
/** `http://127.0.0.1:<port>/callback`. */
|
|
7
|
-
readonly redirectUri: string;
|
|
8
|
-
/** The redirect's query parameters. */
|
|
9
|
-
readonly result: Promise<URLSearchParams>;
|
|
10
|
-
readonly close: () => void;
|
|
11
|
-
}
|
|
12
|
-
/** What talking to the OAuth server needs: refreshing and ending a sign-in need only this. */
|
|
13
|
-
export interface OAuthServerRuntime {
|
|
14
|
-
readonly fetch: typeof globalThis.fetch;
|
|
15
|
-
readonly signal: AbortSignal;
|
|
16
|
-
}
|
|
17
|
-
/** What signing in does outside this module, injected so it can be tested. */
|
|
18
|
-
/**
|
|
19
|
-
* What the person does to finish signing in. The CLI words and styles it; `signInPromptText` is
|
|
20
|
-
* the plain wording.
|
|
21
|
-
*/
|
|
22
|
-
export type SignInPrompt = {
|
|
23
|
-
readonly kind: 'browser';
|
|
24
|
-
readonly authorizeUrl: string;
|
|
25
|
-
} | {
|
|
26
|
-
readonly kind: 'device';
|
|
27
|
-
readonly userCode: string;
|
|
28
|
-
readonly verificationUri: string;
|
|
29
|
-
/** The link with the code already in it, when the server gives one. */
|
|
30
|
-
readonly verificationUriComplete: string | null;
|
|
31
|
-
readonly expiresInSeconds: number;
|
|
32
|
-
};
|
|
33
|
-
export declare function signInPromptText(prompt: SignInPrompt): string;
|
|
34
|
-
/** Why a sign-in ended without signing in, so the CLI can say what to do next. */
|
|
35
|
-
export type SignInEndReason = 'declined' | 'timed_out' | 'cancelled' | 'expired';
|
|
36
|
-
export declare class SignInEnded extends Error {
|
|
37
|
-
readonly reason: SignInEndReason;
|
|
38
|
-
constructor(reason: SignInEndReason, message: string);
|
|
39
|
-
}
|
|
40
|
-
export interface SignInRuntime extends OAuthServerRuntime {
|
|
41
|
-
readonly prompt: (prompt: SignInPrompt) => void;
|
|
42
|
-
readonly openBrowser: (url: string) => Promise<void>;
|
|
43
|
-
/** Listens for the redirect; the browser then goes on to `appUrl`'s sign-in result page. */
|
|
44
|
-
readonly listenForRedirect: (appUrl: string) => Promise<RedirectListener>;
|
|
45
|
-
readonly sleep: (ms: number) => Promise<void>;
|
|
46
|
-
}
|
|
47
|
-
export interface SignInInput {
|
|
48
|
-
/** The Dexto app origin, home of its authorization server and MCP. */
|
|
49
|
-
readonly appUrl: string;
|
|
50
|
-
/** The public API the login is saved for. */
|
|
51
|
-
readonly apiBaseUrl: string;
|
|
52
|
-
/** The organization to sign in for (id, slug or name), where the approval page starts. */
|
|
53
|
-
readonly organization: string | null;
|
|
54
|
-
/** Scopes asked for on purpose, besides reading the workspace and Cloud. */
|
|
55
|
-
readonly extraScopes: readonly string[];
|
|
56
|
-
}
|
|
57
|
-
export interface BrowserSignInInput extends SignInInput {
|
|
58
|
-
/** Open the browser; when false the URL is only printed. */
|
|
59
|
-
readonly openBrowser: boolean;
|
|
60
|
-
}
|
|
61
|
-
export declare function signInWithBrowser(runtime: SignInRuntime, input: BrowserSignInInput): Promise<OAuthLogin>;
|
|
62
|
-
export declare function signInWithDevice(runtime: SignInRuntime, input: SignInInput): Promise<OAuthLogin>;
|
|
63
|
-
/**
|
|
64
|
-
* Trades the refresh token for new tokens, as the client that signed in; the old refresh token
|
|
65
|
-
* stops working.
|
|
66
|
-
*/
|
|
67
|
-
export declare function refreshSignIn(runtime: OAuthServerRuntime, login: OAuthLogin): Promise<OAuthLogin>;
|
|
68
|
-
/** What became of a sign-in on its server when logging out. */
|
|
69
|
-
export type EndedSignIn = {
|
|
70
|
-
readonly status: 'ended';
|
|
71
|
-
} | {
|
|
72
|
-
readonly status: 'failed';
|
|
73
|
-
readonly reason: string;
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Ends the sign-in on its server (RFC 7009), so its tokens stop working everywhere. Never throws:
|
|
77
|
-
* the login is forgotten either way, and the caller says what happened.
|
|
78
|
-
*/
|
|
79
|
-
export declare function endSignIn(runtime: OAuthServerRuntime, login: OAuthLogin): Promise<EndedSignIn>;
|
|
80
|
-
export declare class OAuthHttpError extends Error {
|
|
81
|
-
/** The OAuth `error` code, such as `authorization_pending`; null when the reply had none. */
|
|
82
|
-
readonly code: string | null;
|
|
83
|
-
readonly status: number;
|
|
84
|
-
constructor(status: number, code: string | null, message: string);
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=dexto-sign-in.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dexto-sign-in.d.ts","sourceRoot":"","sources":["../../src/auth/dexto-sign-in.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,UAAU,EAAoB,MAAM,qBAAqB,CAAC;AAExE,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAU/C,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC7B,0CAA0C;IAC1C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,8FAA8F;AAC9F,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAChC;AAED,8EAA8E;AAC9E;;;GAGG;AACH,MAAM,MAAM,YAAY,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAC3D;IACI,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAA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