@dexto/agent-management 1.14.6 → 1.15.0-beta.1
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/dexto-accounts.cjs +277 -0
- package/dist/auth/dexto-accounts.d.ts +144 -0
- package/dist/auth/dexto-accounts.d.ts.map +1 -0
- package/dist/auth/dexto-accounts.js +230 -0
- package/dist/auth/dexto-cloud.cjs +51 -0
- package/dist/auth/dexto-cloud.d.ts +9 -0
- package/dist/auth/dexto-cloud.d.ts.map +1 -0
- package/dist/auth/dexto-cloud.js +27 -0
- package/dist/auth/dexto-gateway.cjs +162 -0
- package/dist/auth/dexto-gateway.d.ts +55 -0
- package/dist/auth/dexto-gateway.d.ts.map +1 -0
- package/dist/auth/dexto-gateway.js +133 -0
- package/dist/auth/dexto-mcp.cjs +77 -0
- package/dist/auth/dexto-mcp.d.ts +23 -0
- package/dist/auth/dexto-mcp.d.ts.map +1 -0
- package/dist/auth/dexto-mcp.js +49 -0
- package/dist/auth/dexto-sign-in.cjs +324 -0
- package/dist/auth/dexto-sign-in.d.ts +63 -0
- package/dist/auth/dexto-sign-in.d.ts.map +1 -0
- package/dist/auth/dexto-sign-in.js +295 -0
- package/dist/auth/index.cjs +25 -0
- package/dist/auth/index.d.ts +6 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +10 -0
- package/dist/auth/model-auth-handlers.cjs +3 -1
- package/dist/auth/model-auth-handlers.d.ts +6 -1
- package/dist/auth/model-auth-handlers.d.ts.map +1 -1
- package/dist/auth/model-auth-handlers.js +6 -1
- package/dist/index.cjs +38 -29
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/tool-factories/agent-spawner/factory.cjs +1 -218
- package/dist/tool-factories/agent-spawner/factory.d.ts.map +1 -1
- package/dist/tool-factories/agent-spawner/factory.js +1 -228
- package/dist/utils/dexto-auth.cjs +3 -58
- package/dist/utils/dexto-auth.d.ts +4 -18
- package/dist/utils/dexto-auth.d.ts.map +1 -1
- package/dist/utils/dexto-auth.js +3 -57
- package/package.json +5 -6
|
@@ -0,0 +1,51 @@
|
|
|
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_cloud_exports = {};
|
|
20
|
+
__export(dexto_cloud_exports, {
|
|
21
|
+
listCloudProjects: () => listCloudProjects
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(dexto_cloud_exports);
|
|
24
|
+
var import_zod = require("zod");
|
|
25
|
+
const ProjectListSchema = import_zod.z.object({
|
|
26
|
+
data: import_zod.z.array(
|
|
27
|
+
import_zod.z.object({
|
|
28
|
+
id: import_zod.z.string(),
|
|
29
|
+
name: import_zod.z.string(),
|
|
30
|
+
is_default: import_zod.z.boolean(),
|
|
31
|
+
archived_at: import_zod.z.string().nullable()
|
|
32
|
+
})
|
|
33
|
+
)
|
|
34
|
+
});
|
|
35
|
+
async function listCloudProjects(fetch, apiBaseUrl, token) {
|
|
36
|
+
const response = await fetch(`${apiBaseUrl}/v1/projects`, {
|
|
37
|
+
headers: { accept: "application/json", authorization: `Bearer ${token}` },
|
|
38
|
+
signal: AbortSignal.timeout(1e4)
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) throw new Error(`Couldn't list Cloud projects: HTTP ${response.status}.`);
|
|
41
|
+
return ProjectListSchema.parse(await response.json()).data.map((project) => ({
|
|
42
|
+
id: project.id,
|
|
43
|
+
name: project.name,
|
|
44
|
+
isDefault: project.is_default,
|
|
45
|
+
archived: project.archived_at !== null
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
listCloudProjects
|
|
51
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CloudProject {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly isDefault: boolean;
|
|
5
|
+
readonly archived: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** The Cloud projects of the token's organization: `GET /v1/projects`. */
|
|
8
|
+
export declare function listCloudProjects(fetch: typeof globalThis.fetch, apiBaseUrl: string, token: string): Promise<CloudProject[]>;
|
|
9
|
+
//# sourceMappingURL=dexto-cloud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dexto-cloud.d.ts","sourceRoot":"","sources":["../../src/auth/dexto-cloud.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC9B;AAaD,0EAA0E;AAC1E,wBAAsB,iBAAiB,CACnC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GACd,OAAO,CAAC,YAAY,EAAE,CAAC,CAYzB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const ProjectListSchema = z.object({
|
|
3
|
+
data: z.array(
|
|
4
|
+
z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
name: z.string(),
|
|
7
|
+
is_default: z.boolean(),
|
|
8
|
+
archived_at: z.string().nullable()
|
|
9
|
+
})
|
|
10
|
+
)
|
|
11
|
+
});
|
|
12
|
+
async function listCloudProjects(fetch, apiBaseUrl, token) {
|
|
13
|
+
const response = await fetch(`${apiBaseUrl}/v1/projects`, {
|
|
14
|
+
headers: { accept: "application/json", authorization: `Bearer ${token}` },
|
|
15
|
+
signal: AbortSignal.timeout(1e4)
|
|
16
|
+
});
|
|
17
|
+
if (!response.ok) throw new Error(`Couldn't list Cloud projects: HTTP ${response.status}.`);
|
|
18
|
+
return ProjectListSchema.parse(await response.json()).data.map((project) => ({
|
|
19
|
+
id: project.id,
|
|
20
|
+
name: project.name,
|
|
21
|
+
isDefault: project.is_default,
|
|
22
|
+
archived: project.archived_at !== null
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
listCloudProjects
|
|
27
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
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_gateway_exports = {};
|
|
20
|
+
__export(dexto_gateway_exports, {
|
|
21
|
+
currentCredential: () => currentCredential,
|
|
22
|
+
defaultDextoGatewayOptions: () => defaultDextoGatewayOptions,
|
|
23
|
+
dextoBillingSummary: () => dextoBillingSummary,
|
|
24
|
+
dextoGatewayRuntimeAuth: () => dextoGatewayRuntimeAuth,
|
|
25
|
+
dextoModelAccess: () => dextoModelAccess,
|
|
26
|
+
dextoModels: () => dextoModels
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(dexto_gateway_exports);
|
|
29
|
+
var import_core = require("@dexto/core");
|
|
30
|
+
var import_zod = require("zod");
|
|
31
|
+
var import_dexto_accounts = require("./dexto-accounts.js");
|
|
32
|
+
var import_dexto_sign_in = require("./dexto-sign-in.js");
|
|
33
|
+
const DEXTO_CLOUD_PROJECT_HEADER = "Dexto-Cloud-Project";
|
|
34
|
+
const SIGN_IN_PLACEHOLDER_KEY = "dexto-sign-in";
|
|
35
|
+
function defaultDextoGatewayOptions() {
|
|
36
|
+
const fetch = globalThis.fetch;
|
|
37
|
+
return {
|
|
38
|
+
dir: (0, import_core.getDextoGlobalPath)("accounts"),
|
|
39
|
+
environment: process.env,
|
|
40
|
+
apiBaseUrl: (process.env.DEXTO_PUBLIC_API_URL || "https://api.dexto.ai").replace(
|
|
41
|
+
/\/+$/u,
|
|
42
|
+
""
|
|
43
|
+
),
|
|
44
|
+
fetch,
|
|
45
|
+
refresh: (login) => (0, import_dexto_sign_in.refreshSignIn)({ fetch, signal: AbortSignal.timeout(1e4) }, login)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function dextoModelAccess(options) {
|
|
49
|
+
if (nonEmpty(options.environment.DEXTO_API_KEY)) return { status: "ready" };
|
|
50
|
+
const credential = await currentCredential(options);
|
|
51
|
+
if (credential === null) return { status: "signed_out" };
|
|
52
|
+
if (credential.kind === "api_key") return { status: "ready" };
|
|
53
|
+
if (!canSpend(credential.login)) return { status: "needs_scope" };
|
|
54
|
+
if (credential.login.cloudProject === null) return { status: "needs_project" };
|
|
55
|
+
return { status: "ready" };
|
|
56
|
+
}
|
|
57
|
+
function dextoGatewayRuntimeAuth(options) {
|
|
58
|
+
if (nonEmpty(options.environment.DEXTO_API_KEY)) return null;
|
|
59
|
+
return {
|
|
60
|
+
apiKey: SIGN_IN_PLACEHOLDER_KEY,
|
|
61
|
+
baseURL: `${options.apiBaseUrl}/v1`,
|
|
62
|
+
fetch: async (input, init) => {
|
|
63
|
+
const credential = await currentCredential(options);
|
|
64
|
+
const headers = new globalThis.Headers(init?.headers);
|
|
65
|
+
if (credential === null)
|
|
66
|
+
throw new Error(
|
|
67
|
+
"Dexto models need a Dexto sign-in. Run dexto login, or choose another provider."
|
|
68
|
+
);
|
|
69
|
+
const apiBaseUrl = credential.kind === "oauth" ? credential.login.apiBaseUrl : options.apiBaseUrl;
|
|
70
|
+
if (credential.kind === "oauth") {
|
|
71
|
+
if (!canSpend(credential.login))
|
|
72
|
+
throw new Error(
|
|
73
|
+
"Dexto models spend credits, which this sign-in may not do yet. Run dexto login --scope cloud:write."
|
|
74
|
+
);
|
|
75
|
+
if (credential.login.cloudProject === null)
|
|
76
|
+
throw new Error(
|
|
77
|
+
"Your organization has no Cloud project for Dexto models to bill. Create one in Dexto, then run dexto login again."
|
|
78
|
+
);
|
|
79
|
+
headers.set(DEXTO_CLOUD_PROJECT_HEADER, credential.login.cloudProject.id);
|
|
80
|
+
}
|
|
81
|
+
headers.set("authorization", `Bearer ${credential.token}`);
|
|
82
|
+
return await options.fetch(rebase(String(input), options.apiBaseUrl, apiBaseUrl), {
|
|
83
|
+
...init,
|
|
84
|
+
headers
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const ModelListSchema = import_zod.z.object({
|
|
90
|
+
data: import_zod.z.array(import_zod.z.object({ id: import_zod.z.string(), name: import_zod.z.string(), context_window: import_zod.z.number() }))
|
|
91
|
+
});
|
|
92
|
+
const BillingSummarySchema = import_zod.z.object({
|
|
93
|
+
balance_usd: import_zod.z.number(),
|
|
94
|
+
last_30_days: import_zod.z.object({ total_cost_usd: import_zod.z.number(), total_usage_events: import_zod.z.number() }),
|
|
95
|
+
recent_model_usage: import_zod.z.array(
|
|
96
|
+
import_zod.z.object({ model: import_zod.z.string(), cost_usd: import_zod.z.number(), timestamp: import_zod.z.string() })
|
|
97
|
+
)
|
|
98
|
+
});
|
|
99
|
+
async function dextoModels(options) {
|
|
100
|
+
const body = await readDexto(options, "/v1/models");
|
|
101
|
+
if (body === null) return null;
|
|
102
|
+
return ModelListSchema.parse(body).data.map((model) => ({
|
|
103
|
+
id: model.id,
|
|
104
|
+
name: model.name,
|
|
105
|
+
contextWindow: model.context_window
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
async function dextoBillingSummary(options) {
|
|
109
|
+
const body = await readDexto(options, "/v1/billing/summary");
|
|
110
|
+
if (body === null) return null;
|
|
111
|
+
const summary = BillingSummarySchema.parse(body);
|
|
112
|
+
return {
|
|
113
|
+
balanceUsd: summary.balance_usd,
|
|
114
|
+
last30Days: {
|
|
115
|
+
costUsd: summary.last_30_days.total_cost_usd,
|
|
116
|
+
usageEvents: summary.last_30_days.total_usage_events
|
|
117
|
+
},
|
|
118
|
+
recent: summary.recent_model_usage.map((usage) => ({
|
|
119
|
+
model: usage.model,
|
|
120
|
+
costUsd: usage.cost_usd,
|
|
121
|
+
timestamp: usage.timestamp
|
|
122
|
+
}))
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
async function readDexto(options, path) {
|
|
126
|
+
const credential = await currentCredential(options);
|
|
127
|
+
if (credential === null) return null;
|
|
128
|
+
const apiBaseUrl = credential.kind === "oauth" ? credential.login.apiBaseUrl : options.apiBaseUrl;
|
|
129
|
+
const response = await options.fetch(`${apiBaseUrl}${path}`, {
|
|
130
|
+
headers: { accept: "application/json", authorization: `Bearer ${credential.token}` },
|
|
131
|
+
signal: AbortSignal.timeout(1e4)
|
|
132
|
+
});
|
|
133
|
+
if (!response.ok) throw new Error(`Dexto answered ${path} with HTTP ${response.status}.`);
|
|
134
|
+
return await response.json();
|
|
135
|
+
}
|
|
136
|
+
async function currentCredential(options) {
|
|
137
|
+
return await (0, import_dexto_accounts.resolveCredential)({
|
|
138
|
+
dir: options.dir,
|
|
139
|
+
apiKey: null,
|
|
140
|
+
profile: null,
|
|
141
|
+
environment: options.environment,
|
|
142
|
+
refresh: options.refresh
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function canSpend(login) {
|
|
146
|
+
return login.scopes.includes("cloud:write");
|
|
147
|
+
}
|
|
148
|
+
function rebase(url, from, to) {
|
|
149
|
+
return from === to || !url.startsWith(from) ? url : `${to}${url.slice(from.length)}`;
|
|
150
|
+
}
|
|
151
|
+
function nonEmpty(value) {
|
|
152
|
+
return value !== void 0 && value.trim().length > 0;
|
|
153
|
+
}
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
currentCredential,
|
|
157
|
+
defaultDextoGatewayOptions,
|
|
158
|
+
dextoBillingSummary,
|
|
159
|
+
dextoGatewayRuntimeAuth,
|
|
160
|
+
dextoModelAccess,
|
|
161
|
+
dextoModels
|
|
162
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type LlmRuntimeAuthOverrides } from '@dexto/core';
|
|
2
|
+
import { type Credential, type OAuthLogin } from './dexto-accounts.js';
|
|
3
|
+
export interface DextoGatewayOptions {
|
|
4
|
+
/** ~/.dexto/accounts */
|
|
5
|
+
readonly dir: string;
|
|
6
|
+
readonly environment: Readonly<Record<string, string | undefined>>;
|
|
7
|
+
/** The public API new sign-ins use; requests go to the one their sign-in was saved for. */
|
|
8
|
+
readonly apiBaseUrl: string;
|
|
9
|
+
readonly fetch: typeof globalThis.fetch;
|
|
10
|
+
readonly refresh: (login: OAuthLogin) => Promise<OAuthLogin>;
|
|
11
|
+
}
|
|
12
|
+
/** This machine's sign-in, Dexto's public API and the global fetch. */
|
|
13
|
+
export declare function defaultDextoGatewayOptions(): DextoGatewayOptions;
|
|
14
|
+
/** Whether Dexto models can be used now, and if not, what's missing. */
|
|
15
|
+
export type DextoModelAccess = {
|
|
16
|
+
readonly status: 'ready';
|
|
17
|
+
} | {
|
|
18
|
+
readonly status: 'signed_out';
|
|
19
|
+
} | {
|
|
20
|
+
readonly status: 'needs_scope';
|
|
21
|
+
} | {
|
|
22
|
+
readonly status: 'needs_project';
|
|
23
|
+
};
|
|
24
|
+
export declare function dextoModelAccess(options: DextoGatewayOptions): Promise<DextoModelAccess>;
|
|
25
|
+
/**
|
|
26
|
+
* The runtime auth for `dexto-nova` when DEXTO_API_KEY isn't set: the public API's gateway, with a
|
|
27
|
+
* fetch that signs each request as the current profile. Null leaves DEXTO_API_KEY to the key path.
|
|
28
|
+
*/
|
|
29
|
+
export declare function dextoGatewayRuntimeAuth(options: DextoGatewayOptions): LlmRuntimeAuthOverrides | null;
|
|
30
|
+
/** A model Dexto serves, by the id to send as `model`. */
|
|
31
|
+
export interface DextoModel {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly contextWindow: number;
|
|
35
|
+
}
|
|
36
|
+
/** The organization's credits and what was spent, as the caller may see it. */
|
|
37
|
+
export interface DextoBillingSummary {
|
|
38
|
+
readonly balanceUsd: number;
|
|
39
|
+
readonly last30Days: {
|
|
40
|
+
readonly costUsd: number;
|
|
41
|
+
readonly usageEvents: number;
|
|
42
|
+
};
|
|
43
|
+
readonly recent: readonly {
|
|
44
|
+
readonly model: string;
|
|
45
|
+
readonly costUsd: number;
|
|
46
|
+
readonly timestamp: string;
|
|
47
|
+
}[];
|
|
48
|
+
}
|
|
49
|
+
/** The models Dexto serves: `GET /v1/models`. Null when signed out. */
|
|
50
|
+
export declare function dextoModels(options: DextoGatewayOptions): Promise<DextoModel[] | null>;
|
|
51
|
+
/** The organization's credits and recent spending: `GET /v1/billing/summary`. Null when signed out. */
|
|
52
|
+
export declare function dextoBillingSummary(options: DextoGatewayOptions): Promise<DextoBillingSummary | null>;
|
|
53
|
+
/** The current profile's credential, refreshed when expiring; null when signed out. */
|
|
54
|
+
export declare function currentCredential(options: DextoGatewayOptions): Promise<Credential | null>;
|
|
55
|
+
//# sourceMappingURL=dexto-gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dexto-gateway.d.ts","sourceRoot":"","sources":["../../src/auth/dexto-gateway.ts"],"names":[],"mappings":"AAGA,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AAO1F,MAAM,WAAW,mBAAmB;IAChC,wBAAwB;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IACnE,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CAChE;AAED,uEAAuE;AACvE,wBAAgB,0BAA0B,IAAI,mBAAmB,CAYhE;AAED,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,GACtB;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GACjC;IAAE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;CAAE,GAClC;IAAE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC;AAE3C,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAQ9F;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACnC,OAAO,EAAE,mBAAmB,GAC7B,uBAAuB,GAAG,IAAI,CAgChC;AAED,0DAA0D;AAC1D,MAAM,WAAW,UAAU;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAClC;AAcD,+EAA+E;AAC/E,MAAM,WAAW,mBAAmB;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAChF,QAAQ,CAAC,MAAM,EAAE,SAAS;QACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;KAC9B,EAAE,CAAC;CACP;AAED,uEAAuE;AACvE,wBAAsB,WAAW,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAQ5F;AAED,uGAAuG;AACvG,wBAAsB,mBAAmB,CACrC,OAAO,EAAE,mBAAmB,GAC7B,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAgBrC;AAgBD,uFAAuF;AACvF,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAQhG"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { getDextoGlobalPath } from "@dexto/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { resolveCredential } from "./dexto-accounts.js";
|
|
4
|
+
import { refreshSignIn } from "./dexto-sign-in.js";
|
|
5
|
+
const DEXTO_CLOUD_PROJECT_HEADER = "Dexto-Cloud-Project";
|
|
6
|
+
const SIGN_IN_PLACEHOLDER_KEY = "dexto-sign-in";
|
|
7
|
+
function defaultDextoGatewayOptions() {
|
|
8
|
+
const fetch = globalThis.fetch;
|
|
9
|
+
return {
|
|
10
|
+
dir: getDextoGlobalPath("accounts"),
|
|
11
|
+
environment: process.env,
|
|
12
|
+
apiBaseUrl: (process.env.DEXTO_PUBLIC_API_URL || "https://api.dexto.ai").replace(
|
|
13
|
+
/\/+$/u,
|
|
14
|
+
""
|
|
15
|
+
),
|
|
16
|
+
fetch,
|
|
17
|
+
refresh: (login) => refreshSignIn({ fetch, signal: AbortSignal.timeout(1e4) }, login)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async function dextoModelAccess(options) {
|
|
21
|
+
if (nonEmpty(options.environment.DEXTO_API_KEY)) return { status: "ready" };
|
|
22
|
+
const credential = await currentCredential(options);
|
|
23
|
+
if (credential === null) return { status: "signed_out" };
|
|
24
|
+
if (credential.kind === "api_key") return { status: "ready" };
|
|
25
|
+
if (!canSpend(credential.login)) return { status: "needs_scope" };
|
|
26
|
+
if (credential.login.cloudProject === null) return { status: "needs_project" };
|
|
27
|
+
return { status: "ready" };
|
|
28
|
+
}
|
|
29
|
+
function dextoGatewayRuntimeAuth(options) {
|
|
30
|
+
if (nonEmpty(options.environment.DEXTO_API_KEY)) return null;
|
|
31
|
+
return {
|
|
32
|
+
apiKey: SIGN_IN_PLACEHOLDER_KEY,
|
|
33
|
+
baseURL: `${options.apiBaseUrl}/v1`,
|
|
34
|
+
fetch: async (input, init) => {
|
|
35
|
+
const credential = await currentCredential(options);
|
|
36
|
+
const headers = new globalThis.Headers(init?.headers);
|
|
37
|
+
if (credential === null)
|
|
38
|
+
throw new Error(
|
|
39
|
+
"Dexto models need a Dexto sign-in. Run dexto login, or choose another provider."
|
|
40
|
+
);
|
|
41
|
+
const apiBaseUrl = credential.kind === "oauth" ? credential.login.apiBaseUrl : options.apiBaseUrl;
|
|
42
|
+
if (credential.kind === "oauth") {
|
|
43
|
+
if (!canSpend(credential.login))
|
|
44
|
+
throw new Error(
|
|
45
|
+
"Dexto models spend credits, which this sign-in may not do yet. Run dexto login --scope cloud:write."
|
|
46
|
+
);
|
|
47
|
+
if (credential.login.cloudProject === null)
|
|
48
|
+
throw new Error(
|
|
49
|
+
"Your organization has no Cloud project for Dexto models to bill. Create one in Dexto, then run dexto login again."
|
|
50
|
+
);
|
|
51
|
+
headers.set(DEXTO_CLOUD_PROJECT_HEADER, credential.login.cloudProject.id);
|
|
52
|
+
}
|
|
53
|
+
headers.set("authorization", `Bearer ${credential.token}`);
|
|
54
|
+
return await options.fetch(rebase(String(input), options.apiBaseUrl, apiBaseUrl), {
|
|
55
|
+
...init,
|
|
56
|
+
headers
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const ModelListSchema = z.object({
|
|
62
|
+
data: z.array(z.object({ id: z.string(), name: z.string(), context_window: z.number() }))
|
|
63
|
+
});
|
|
64
|
+
const BillingSummarySchema = z.object({
|
|
65
|
+
balance_usd: z.number(),
|
|
66
|
+
last_30_days: z.object({ total_cost_usd: z.number(), total_usage_events: z.number() }),
|
|
67
|
+
recent_model_usage: z.array(
|
|
68
|
+
z.object({ model: z.string(), cost_usd: z.number(), timestamp: z.string() })
|
|
69
|
+
)
|
|
70
|
+
});
|
|
71
|
+
async function dextoModels(options) {
|
|
72
|
+
const body = await readDexto(options, "/v1/models");
|
|
73
|
+
if (body === null) return null;
|
|
74
|
+
return ModelListSchema.parse(body).data.map((model) => ({
|
|
75
|
+
id: model.id,
|
|
76
|
+
name: model.name,
|
|
77
|
+
contextWindow: model.context_window
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
async function dextoBillingSummary(options) {
|
|
81
|
+
const body = await readDexto(options, "/v1/billing/summary");
|
|
82
|
+
if (body === null) return null;
|
|
83
|
+
const summary = BillingSummarySchema.parse(body);
|
|
84
|
+
return {
|
|
85
|
+
balanceUsd: summary.balance_usd,
|
|
86
|
+
last30Days: {
|
|
87
|
+
costUsd: summary.last_30_days.total_cost_usd,
|
|
88
|
+
usageEvents: summary.last_30_days.total_usage_events
|
|
89
|
+
},
|
|
90
|
+
recent: summary.recent_model_usage.map((usage) => ({
|
|
91
|
+
model: usage.model,
|
|
92
|
+
costUsd: usage.cost_usd,
|
|
93
|
+
timestamp: usage.timestamp
|
|
94
|
+
}))
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async function readDexto(options, path) {
|
|
98
|
+
const credential = await currentCredential(options);
|
|
99
|
+
if (credential === null) return null;
|
|
100
|
+
const apiBaseUrl = credential.kind === "oauth" ? credential.login.apiBaseUrl : options.apiBaseUrl;
|
|
101
|
+
const response = await options.fetch(`${apiBaseUrl}${path}`, {
|
|
102
|
+
headers: { accept: "application/json", authorization: `Bearer ${credential.token}` },
|
|
103
|
+
signal: AbortSignal.timeout(1e4)
|
|
104
|
+
});
|
|
105
|
+
if (!response.ok) throw new Error(`Dexto answered ${path} with HTTP ${response.status}.`);
|
|
106
|
+
return await response.json();
|
|
107
|
+
}
|
|
108
|
+
async function currentCredential(options) {
|
|
109
|
+
return await resolveCredential({
|
|
110
|
+
dir: options.dir,
|
|
111
|
+
apiKey: null,
|
|
112
|
+
profile: null,
|
|
113
|
+
environment: options.environment,
|
|
114
|
+
refresh: options.refresh
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function canSpend(login) {
|
|
118
|
+
return login.scopes.includes("cloud:write");
|
|
119
|
+
}
|
|
120
|
+
function rebase(url, from, to) {
|
|
121
|
+
return from === to || !url.startsWith(from) ? url : `${to}${url.slice(from.length)}`;
|
|
122
|
+
}
|
|
123
|
+
function nonEmpty(value) {
|
|
124
|
+
return value !== void 0 && value.trim().length > 0;
|
|
125
|
+
}
|
|
126
|
+
export {
|
|
127
|
+
currentCredential,
|
|
128
|
+
defaultDextoGatewayOptions,
|
|
129
|
+
dextoBillingSummary,
|
|
130
|
+
dextoGatewayRuntimeAuth,
|
|
131
|
+
dextoModelAccess,
|
|
132
|
+
dextoModels
|
|
133
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
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_mcp_exports = {};
|
|
20
|
+
__export(dexto_mcp_exports, {
|
|
21
|
+
DEXTO_MCP_SERVER_NAME: () => DEXTO_MCP_SERVER_NAME,
|
|
22
|
+
dextoMcpAuthProvider: () => dextoMcpAuthProvider,
|
|
23
|
+
dextoMcpServer: () => dextoMcpServer,
|
|
24
|
+
withDextoMcpAuth: () => withDextoMcpAuth,
|
|
25
|
+
withDextoMcpServer: () => withDextoMcpServer
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(dexto_mcp_exports);
|
|
28
|
+
var import_dexto_gateway = require("./dexto-gateway.js");
|
|
29
|
+
const DEXTO_MCP_SERVER_NAME = "dexto";
|
|
30
|
+
async function dextoMcpServer(options) {
|
|
31
|
+
const credential = await (0, import_dexto_gateway.currentCredential)(options);
|
|
32
|
+
if (credential?.kind !== "oauth") return null;
|
|
33
|
+
return { type: "http", url: credential.login.resource, connectionMode: "lenient" };
|
|
34
|
+
}
|
|
35
|
+
function dextoMcpAuthProvider(options) {
|
|
36
|
+
return {
|
|
37
|
+
get redirectUrl() {
|
|
38
|
+
return void 0;
|
|
39
|
+
},
|
|
40
|
+
get clientMetadata() {
|
|
41
|
+
return { client_name: "Dexto CLI", redirect_uris: [] };
|
|
42
|
+
},
|
|
43
|
+
async clientInformation() {
|
|
44
|
+
const credential = await (0, import_dexto_gateway.currentCredential)(options);
|
|
45
|
+
return credential?.kind === "oauth" ? { client_id: credential.login.clientId } : void 0;
|
|
46
|
+
},
|
|
47
|
+
async tokens() {
|
|
48
|
+
const credential = await (0, import_dexto_gateway.currentCredential)(options);
|
|
49
|
+
return credential?.kind === "oauth" ? { access_token: credential.token, token_type: "Bearer" } : void 0;
|
|
50
|
+
},
|
|
51
|
+
saveTokens: () => void 0,
|
|
52
|
+
redirectToAuthorization: async () => {
|
|
53
|
+
throw new Error(
|
|
54
|
+
"The Dexto sign-in expired or lacks a permission this tool needs. Run dexto login, or dexto login --scope <permission>."
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
saveCodeVerifier: () => void 0,
|
|
58
|
+
codeVerifier: () => {
|
|
59
|
+
throw new Error("The Dexto MCP signs in with dexto login, not here.");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function withDextoMcpServer(servers, dexto) {
|
|
64
|
+
if (dexto === null || servers?.[DEXTO_MCP_SERVER_NAME] !== void 0) return { ...servers };
|
|
65
|
+
return { ...servers, [DEXTO_MCP_SERVER_NAME]: dexto };
|
|
66
|
+
}
|
|
67
|
+
function withDextoMcpAuth(inner, options) {
|
|
68
|
+
return (serverName, config) => serverName === DEXTO_MCP_SERVER_NAME ? dextoMcpAuthProvider(options) : inner?.(serverName, config) ?? void 0;
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
DEXTO_MCP_SERVER_NAME,
|
|
73
|
+
dextoMcpAuthProvider,
|
|
74
|
+
dextoMcpServer,
|
|
75
|
+
withDextoMcpAuth,
|
|
76
|
+
withDextoMcpServer
|
|
77
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { McpAuthProvider, McpAuthProviderFactory } from '@dexto/core';
|
|
2
|
+
import { type DextoGatewayOptions } from './dexto-gateway.js';
|
|
3
|
+
export declare const DEXTO_MCP_SERVER_NAME = "dexto";
|
|
4
|
+
export interface DextoMcpServerConfig {
|
|
5
|
+
readonly type: 'http';
|
|
6
|
+
readonly url: string;
|
|
7
|
+
/** A cloud outage leaves the server unavailable; the local turn still runs. */
|
|
8
|
+
readonly connectionMode: 'lenient';
|
|
9
|
+
}
|
|
10
|
+
/** The Dexto MCP as a server config when signed in as a person; null for a key or signed out. */
|
|
11
|
+
export declare function dextoMcpServer(options: DextoGatewayOptions): Promise<DextoMcpServerConfig | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Authorizes the Dexto MCP with the sign-in's token. It never registers a client or opens a
|
|
14
|
+
* browser: `dexto login` owns that, and the token is refreshed there. Without a refresh token in
|
|
15
|
+
* what it hands over, the MCP client asks to authorize again only when the server refuses the
|
|
16
|
+
* token, and that says how.
|
|
17
|
+
*/
|
|
18
|
+
export declare function dextoMcpAuthProvider(options: DextoGatewayOptions): McpAuthProvider;
|
|
19
|
+
/** The session's MCP servers with the Dexto MCP added, unless the person named a server dexto. */
|
|
20
|
+
export declare function withDextoMcpServer<Server>(servers: Readonly<Record<string, Server>> | undefined, dexto: DextoMcpServerConfig | null): Record<string, Server | DextoMcpServerConfig>;
|
|
21
|
+
/** Authorizes the dexto server with the sign-in and every other server as `inner` does. */
|
|
22
|
+
export declare function withDextoMcpAuth(inner: McpAuthProviderFactory | null, options: DextoGatewayOptions): McpAuthProviderFactory;
|
|
23
|
+
//# sourceMappingURL=dexto-mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dexto-mcp.d.ts","sourceRoot":"","sources":["../../src/auth/dexto-mcp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,KAAK,mBAAmB,EAAqB,MAAM,oBAAoB,CAAC;AAEjF,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,QAAQ,CAAC,cAAc,EAAE,SAAS,CAAC;CACtC;AAED,iGAAiG;AACjG,wBAAsB,cAAc,CAChC,OAAO,EAAE,mBAAmB,GAC7B,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAItC;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,eAAe,CA+BlF;AAED,kGAAkG;AAClG,wBAAgB,kBAAkB,CAAC,MAAM,EACrC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,EACrD,KAAK,EAAE,oBAAoB,GAAG,IAAI,GACnC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAAC,CAG/C;AAED,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,sBAAsB,GAAG,IAAI,EACpC,OAAO,EAAE,mBAAmB,GAC7B,sBAAsB,CAKxB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { currentCredential } from "./dexto-gateway.js";
|
|
2
|
+
const DEXTO_MCP_SERVER_NAME = "dexto";
|
|
3
|
+
async function dextoMcpServer(options) {
|
|
4
|
+
const credential = await currentCredential(options);
|
|
5
|
+
if (credential?.kind !== "oauth") return null;
|
|
6
|
+
return { type: "http", url: credential.login.resource, connectionMode: "lenient" };
|
|
7
|
+
}
|
|
8
|
+
function dextoMcpAuthProvider(options) {
|
|
9
|
+
return {
|
|
10
|
+
get redirectUrl() {
|
|
11
|
+
return void 0;
|
|
12
|
+
},
|
|
13
|
+
get clientMetadata() {
|
|
14
|
+
return { client_name: "Dexto CLI", redirect_uris: [] };
|
|
15
|
+
},
|
|
16
|
+
async clientInformation() {
|
|
17
|
+
const credential = await currentCredential(options);
|
|
18
|
+
return credential?.kind === "oauth" ? { client_id: credential.login.clientId } : void 0;
|
|
19
|
+
},
|
|
20
|
+
async tokens() {
|
|
21
|
+
const credential = await currentCredential(options);
|
|
22
|
+
return credential?.kind === "oauth" ? { access_token: credential.token, token_type: "Bearer" } : void 0;
|
|
23
|
+
},
|
|
24
|
+
saveTokens: () => void 0,
|
|
25
|
+
redirectToAuthorization: async () => {
|
|
26
|
+
throw new Error(
|
|
27
|
+
"The Dexto sign-in expired or lacks a permission this tool needs. Run dexto login, or dexto login --scope <permission>."
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
saveCodeVerifier: () => void 0,
|
|
31
|
+
codeVerifier: () => {
|
|
32
|
+
throw new Error("The Dexto MCP signs in with dexto login, not here.");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function withDextoMcpServer(servers, dexto) {
|
|
37
|
+
if (dexto === null || servers?.[DEXTO_MCP_SERVER_NAME] !== void 0) return { ...servers };
|
|
38
|
+
return { ...servers, [DEXTO_MCP_SERVER_NAME]: dexto };
|
|
39
|
+
}
|
|
40
|
+
function withDextoMcpAuth(inner, options) {
|
|
41
|
+
return (serverName, config) => serverName === DEXTO_MCP_SERVER_NAME ? dextoMcpAuthProvider(options) : inner?.(serverName, config) ?? void 0;
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
DEXTO_MCP_SERVER_NAME,
|
|
45
|
+
dextoMcpAuthProvider,
|
|
46
|
+
dextoMcpServer,
|
|
47
|
+
withDextoMcpAuth,
|
|
48
|
+
withDextoMcpServer
|
|
49
|
+
};
|