@tangle-network/agent-app 0.50.31 → 0.50.33
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/VaultPane-RHLY4DR5.js +7 -0
- package/dist/agent-enrollment/application.d.ts +25 -5
- package/dist/agent-enrollment/drizzle.d.ts +63 -0
- package/dist/agent-enrollment/drizzle.js +160 -0
- package/dist/agent-enrollment/drizzle.js.map +1 -0
- package/dist/agent-enrollment/index.d.ts +1 -1
- package/dist/agent-enrollment/index.js +5 -199
- package/dist/agent-enrollment/index.js.map +1 -1
- package/dist/app-oauth/index.d.ts +101 -0
- package/dist/app-oauth/index.js +231 -0
- package/dist/app-oauth/index.js.map +1 -0
- package/dist/assistant/index.js +1 -1
- package/dist/chat-routes/index.js +4 -4
- package/dist/{chunk-LDCR7MRU.js → chunk-2PDKWV2S.js} +2 -2
- package/dist/{chunk-2ZNU55YJ.js → chunk-3IATFW4U.js} +5 -5
- package/dist/chunk-3IATFW4U.js.map +1 -0
- package/dist/chunk-C3JSO2CB.js +232 -0
- package/dist/chunk-C3JSO2CB.js.map +1 -0
- package/dist/{chunk-CNI46COH.js → chunk-CBRYWGUO.js} +2 -2
- package/dist/{chunk-CNI46COH.js.map → chunk-CBRYWGUO.js.map} +1 -1
- package/dist/{chunk-BATKJP3P.js → chunk-E4AY62T2.js} +24 -7
- package/dist/chunk-E4AY62T2.js.map +1 -0
- package/dist/{chunk-5KFRCVAO.js → chunk-IYLPQKAH.js} +2 -2
- package/dist/{chunk-5TOV7EDF.js → chunk-PF3AZD5G.js} +4 -4
- package/dist/{chunk-ACFM2GFL.js → chunk-SYIV74NB.js} +1 -1
- package/dist/design-canvas-react/index.js +4 -4
- package/dist/design-canvas-react/lazy.js +1 -1
- package/dist/hosted-agent/react/SharedLineAppNotice.d.ts +16 -0
- package/dist/hosted-agent/react/index.d.ts +1 -0
- package/dist/hosted-agent/react/index.js +46 -1
- package/dist/hosted-agent/react/index.js.map +1 -1
- package/dist/hosted-agent/react/lines.css +92 -2
- package/dist/integrations-react/callback.d.ts +6 -0
- package/dist/integrations-react/client.d.ts +34 -0
- package/dist/integrations-react/index.d.ts +6 -0
- package/dist/integrations-react/index.js +830 -0
- package/dist/integrations-react/index.js.map +1 -0
- package/dist/integrations-react/panel.d.ts +22 -0
- package/dist/integrations-react/popup.d.ts +19 -0
- package/dist/integrations-react/projection.d.ts +25 -0
- package/dist/integrations-react/use-hub-integrations.d.ts +102 -0
- package/dist/preset-cloudflare/index.js +2 -2
- package/dist/sandbox/index.js +4 -4
- package/dist/studio-react/index.js +91 -56
- package/dist/studio-react/index.js.map +1 -1
- package/dist/teams-react/index.js +3 -3
- package/dist/theme/tokens.css +3 -1
- package/dist/tools/index.js +4 -4
- package/dist/vault/index.js +1 -1
- package/dist/vault/lazy.js +1 -1
- package/dist/web-react/index.js +4 -4
- package/dist/web-react/sandbox-terminal.d.ts +2 -0
- package/dist/web-react/terminal.js +1 -1
- package/dist/work-product/index.js +2 -2
- package/dist/workspace-react/companion.d.ts +31 -0
- package/dist/workspace-react/index.d.ts +1 -1
- package/dist/workspace-react/index.js +140 -2
- package/dist/workspace-react/index.js.map +1 -1
- package/package.json +35 -5
- package/dist/VaultPane-OTUP5AEX.js +0 -7
- package/dist/chunk-2ZNU55YJ.js.map +0 -1
- package/dist/chunk-BATKJP3P.js.map +0 -1
- /package/dist/{VaultPane-OTUP5AEX.js.map → VaultPane-RHLY4DR5.js.map} +0 -0
- /package/dist/{chunk-LDCR7MRU.js.map → chunk-2PDKWV2S.js.map} +0 -0
- /package/dist/{chunk-5KFRCVAO.js.map → chunk-IYLPQKAH.js.map} +0 -0
- /package/dist/{chunk-5TOV7EDF.js.map → chunk-PF3AZD5G.js.map} +0 -0
- /package/dist/{chunk-ACFM2GFL.js.map → chunk-SYIV74NB.js.map} +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** OAuth for an application's MCP resource. The host owns identity, tables and grants. */
|
|
2
|
+
import { oauthProvider } from '@better-auth/oauth-provider';
|
|
3
|
+
import { oauthProviderResourceClient } from '@better-auth/oauth-provider/resource-client';
|
|
4
|
+
import { verifyJwsAccessToken } from 'better-auth/oauth2';
|
|
5
|
+
export interface AppOAuthConsent {
|
|
6
|
+
id: string;
|
|
7
|
+
/** JSON string or string array, as returned by the host's persistence adapter. */
|
|
8
|
+
scopes: string | readonly string[] | null;
|
|
9
|
+
resources: string | readonly string[] | null;
|
|
10
|
+
}
|
|
11
|
+
/** The issuer reads current consent before minting a token. A lookup outage must throw. */
|
|
12
|
+
export interface AppOAuthConsentAuthority {
|
|
13
|
+
findConsents(clientId: string, userId: string): Promise<readonly AppOAuthConsent[]>;
|
|
14
|
+
}
|
|
15
|
+
/** Each callback reads current host authority. A lookup outage must throw. */
|
|
16
|
+
export interface AppOAuthAuthority extends AppOAuthConsentAuthority {
|
|
17
|
+
clientActive(clientId: string): Promise<boolean>;
|
|
18
|
+
resourceActive(resource: string): Promise<boolean>;
|
|
19
|
+
clientResourceLinked(clientId: string, resource: string): Promise<boolean>;
|
|
20
|
+
sessionActive(sessionId: string, userId: string): Promise<boolean>;
|
|
21
|
+
userActive(userId: string): Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
export interface AppOAuthAuthoritySnapshotInput {
|
|
24
|
+
clientId: string;
|
|
25
|
+
userId: string;
|
|
26
|
+
sessionId: string;
|
|
27
|
+
consentId: string;
|
|
28
|
+
resource: string;
|
|
29
|
+
scopes: readonly string[];
|
|
30
|
+
/** Claims from a verified JWS. The host can forward its own grant generation. */
|
|
31
|
+
claims: Readonly<Record<string, unknown>>;
|
|
32
|
+
}
|
|
33
|
+
export interface AppOAuthAuthoritySnapshot {
|
|
34
|
+
active: boolean;
|
|
35
|
+
clientActive: boolean;
|
|
36
|
+
resourceActive: boolean;
|
|
37
|
+
clientResourceLinked: boolean;
|
|
38
|
+
consents: readonly AppOAuthConsent[];
|
|
39
|
+
sessionActive: boolean;
|
|
40
|
+
userActive: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Read one uncached, current authority view after JWS verification. */
|
|
43
|
+
export interface AppOAuthSnapshotAuthority {
|
|
44
|
+
readSnapshot(input: AppOAuthAuthoritySnapshotInput): Promise<AppOAuthAuthoritySnapshot>;
|
|
45
|
+
}
|
|
46
|
+
export interface AppOAuthConfig {
|
|
47
|
+
/** Exact RFC 8707 audience. The host owns the URL and its route. */
|
|
48
|
+
resource: string;
|
|
49
|
+
/** Exact issuer, including Better Auth's /api/auth base path. */
|
|
50
|
+
issuer: string;
|
|
51
|
+
/** OAuth permissions the application offers for this resource. */
|
|
52
|
+
scopes: readonly string[];
|
|
53
|
+
/** Scope granted to a dynamically registered client by default. */
|
|
54
|
+
defaultClientScope: string;
|
|
55
|
+
/** Claim containing the current consent row ID. */
|
|
56
|
+
consentClaim: string;
|
|
57
|
+
}
|
|
58
|
+
export type AppOAuthIssuerConfig = AppOAuthConfig & {
|
|
59
|
+
authority: AppOAuthConsentAuthority;
|
|
60
|
+
};
|
|
61
|
+
export type AppOAuthResourceConfig = AppOAuthConfig & {
|
|
62
|
+
authority: AppOAuthAuthority | AppOAuthSnapshotAuthority;
|
|
63
|
+
};
|
|
64
|
+
export type AppOAuthJwksFetch = Extract<Parameters<typeof verifyJwsAccessToken>[1]['jwksFetch'], (...args: never[]) => unknown>;
|
|
65
|
+
export declare function activeAppOAuthConsent(config: AppOAuthIssuerConfig, clientId: string, userId: string, scopes: readonly string[]): Promise<AppOAuthConsent | null>;
|
|
66
|
+
/** Compose the maintained Better Auth provider with one host's live authority. */
|
|
67
|
+
export declare function createAppOAuthProvider(config: AppOAuthIssuerConfig & {
|
|
68
|
+
loginPage: string;
|
|
69
|
+
consentPage: string;
|
|
70
|
+
/** The host must reject deleted, disabled or unverified users at token mint. */
|
|
71
|
+
humanUserEligible(userId: string): Promise<boolean>;
|
|
72
|
+
}): ReturnType<typeof oauthProvider>;
|
|
73
|
+
export interface AppOAuthRefreshToken {
|
|
74
|
+
id: string;
|
|
75
|
+
clientId: string;
|
|
76
|
+
userId: string;
|
|
77
|
+
referenceId: string | null;
|
|
78
|
+
}
|
|
79
|
+
export interface AppOAuthRefreshStore {
|
|
80
|
+
findByHash(hash: string): Promise<AppOAuthRefreshToken | null>;
|
|
81
|
+
/** Atomically set referenceId only when it is NULL. */
|
|
82
|
+
bindIfUnbound(id: string, consentId: string): Promise<boolean>;
|
|
83
|
+
}
|
|
84
|
+
/** Bind refresh rows to the current consent before their secret leaves the host. */
|
|
85
|
+
export declare function appOAuthTokenResponse(request: Request, config: AppOAuthIssuerConfig & {
|
|
86
|
+
handler(request: Request): Promise<Response>;
|
|
87
|
+
refreshStore: AppOAuthRefreshStore;
|
|
88
|
+
}): Promise<Response>;
|
|
89
|
+
export interface AppOAuthPrincipal {
|
|
90
|
+
userId: string;
|
|
91
|
+
clientId: string;
|
|
92
|
+
scopes: readonly string[];
|
|
93
|
+
}
|
|
94
|
+
/** Verify bearer tokens and current host grants before any private tool is listed. */
|
|
95
|
+
export declare function createAppOAuthResourceVerifier(config: AppOAuthResourceConfig & {
|
|
96
|
+
jwksFetch: AppOAuthJwksFetch;
|
|
97
|
+
}): (request: Request) => Promise<AppOAuthPrincipal | null>;
|
|
98
|
+
/** Strip unsupported DPoP advertisement from Better Auth's issuer metadata. */
|
|
99
|
+
export declare function appOAuthMetadataResponse(request: Request, handler: (request: Request) => Promise<Response>): Promise<Response>;
|
|
100
|
+
/** RFC 9728 metadata for an issuer-hosted or separate protected resource. */
|
|
101
|
+
export declare function appOAuthProtectedResourceMetadata(config: AppOAuthConfig, auth?: NonNullable<Parameters<typeof oauthProviderResourceClient>[0]>): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// src/app-oauth/index.ts
|
|
2
|
+
import { oauthProvider } from "@better-auth/oauth-provider";
|
|
3
|
+
import { oauthProviderResourceClient } from "@better-auth/oauth-provider/resource-client";
|
|
4
|
+
import { APIError } from "better-auth/api";
|
|
5
|
+
import { verifyJwsAccessToken } from "better-auth/oauth2";
|
|
6
|
+
var ASYMMETRIC_ALGORITHMS = ["EdDSA", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "RS256", "RS384", "RS512"];
|
|
7
|
+
var OPERATIONAL_ERROR = /* @__PURE__ */ Symbol("appOAuthOperational");
|
|
8
|
+
var RESERVED_CONSENT_CLAIMS = /* @__PURE__ */ new Set([
|
|
9
|
+
"iss",
|
|
10
|
+
"sub",
|
|
11
|
+
"aud",
|
|
12
|
+
"exp",
|
|
13
|
+
"iat",
|
|
14
|
+
"jti",
|
|
15
|
+
"client_id",
|
|
16
|
+
"scope",
|
|
17
|
+
"auth_time",
|
|
18
|
+
"acr",
|
|
19
|
+
"amr",
|
|
20
|
+
"cnf",
|
|
21
|
+
"sid",
|
|
22
|
+
"nbf",
|
|
23
|
+
"azp"
|
|
24
|
+
]);
|
|
25
|
+
var STANDARD_SCOPES = ["openid", "profile", "email", "offline_access"];
|
|
26
|
+
function list(value) {
|
|
27
|
+
if (Array.isArray(value)) return value.every((item) => typeof item === "string") ? [...value] : null;
|
|
28
|
+
if (typeof value !== "string") return null;
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(value);
|
|
31
|
+
return Array.isArray(parsed) && parsed.every((item) => typeof item === "string") ? parsed : null;
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function validate(config) {
|
|
37
|
+
const issuer = new URL(config.issuer);
|
|
38
|
+
const resource = new URL(config.resource);
|
|
39
|
+
if (!config.issuer || !config.resource || !/^[a-z][a-z0-9_]*$/.test(config.consentClaim) || RESERVED_CONSENT_CLAIMS.has(config.consentClaim) || !config.scopes.length || !config.scopes.includes(config.defaultClientScope) || issuer.hash || issuer.search || resource.hash || resource.search || issuer.username || issuer.password || resource.username || resource.password || !["https:", "http:"].includes(issuer.protocol) || !["https:", "http:"].includes(resource.protocol) || issuer.protocol === "http:" && !["localhost", "127.0.0.1", "[::1]"].includes(issuer.hostname) || resource.protocol === "http:" && !["localhost", "127.0.0.1", "[::1]"].includes(resource.hostname)) {
|
|
40
|
+
throw new Error("app-oauth: invalid issuer, resource, scopes or consent claim");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function consentFromRows(config, rows, scopes) {
|
|
44
|
+
if (!Array.isArray(rows)) return null;
|
|
45
|
+
if (rows.length !== 1) return null;
|
|
46
|
+
const consent = rows[0];
|
|
47
|
+
if (!consent?.id) return null;
|
|
48
|
+
const resources = list(consent.resources);
|
|
49
|
+
const granted = list(consent.scopes);
|
|
50
|
+
if (!resources?.includes(config.resource) || !granted) return null;
|
|
51
|
+
return scopes.every((scope) => granted.includes(scope)) ? consent : null;
|
|
52
|
+
}
|
|
53
|
+
async function activeAppOAuthConsent(config, clientId, userId, scopes) {
|
|
54
|
+
return consentFromRows(config, await config.authority.findConsents(clientId, userId), scopes);
|
|
55
|
+
}
|
|
56
|
+
function invalidGrant(description) {
|
|
57
|
+
throw new APIError("BAD_REQUEST", { error: "invalid_grant", error_description: description });
|
|
58
|
+
}
|
|
59
|
+
function createAppOAuthProvider(config) {
|
|
60
|
+
validate(config);
|
|
61
|
+
return oauthProvider({
|
|
62
|
+
loginPage: config.loginPage,
|
|
63
|
+
consentPage: config.consentPage,
|
|
64
|
+
accessTokenExpiresIn: 900,
|
|
65
|
+
refreshTokenExpiresIn: 604800,
|
|
66
|
+
codeExpiresIn: 600,
|
|
67
|
+
grantTypes: ["authorization_code", "refresh_token"],
|
|
68
|
+
dpop: { signingAlgorithms: [] },
|
|
69
|
+
scopes: [...STANDARD_SCOPES, ...config.scopes],
|
|
70
|
+
defaultScope: "openid profile email",
|
|
71
|
+
allowPublicClientPrelogin: true,
|
|
72
|
+
allowDynamicClientRegistration: true,
|
|
73
|
+
allowUnauthenticatedClientRegistration: true,
|
|
74
|
+
clientRegistrationDefaultScopes: [config.defaultClientScope],
|
|
75
|
+
clientRegistrationAllowedScopes: [...STANDARD_SCOPES, ...config.scopes],
|
|
76
|
+
clientRegistrationDefaultResources: [config.resource],
|
|
77
|
+
clientRegistrationAllowedResources: [config.resource],
|
|
78
|
+
resources: [{ identifier: config.resource, accessTokenTtl: 900, allowedScopes: [...config.scopes] }],
|
|
79
|
+
resourceSeedMode: "insertOnly",
|
|
80
|
+
enforcePerClientResources: true,
|
|
81
|
+
extensions: [{ claims: { accessToken: async ({ user, client, scopes, resources, grantType, referenceId }) => {
|
|
82
|
+
if (!user?.id || !resources?.includes(config.resource)) invalidGrant("Resource consent is required");
|
|
83
|
+
const consent = await activeAppOAuthConsent(config, client.clientId, user.id, scopes);
|
|
84
|
+
if (!consent || grantType === "refresh_token" && referenceId !== consent.id) {
|
|
85
|
+
invalidGrant("Resource consent changed");
|
|
86
|
+
}
|
|
87
|
+
return { [config.consentClaim]: consent.id };
|
|
88
|
+
} } }],
|
|
89
|
+
customTokenResponseFields: async ({ grantType, user }) => {
|
|
90
|
+
if (grantType === "client_credentials" || !user?.id) invalidGrant("Human identity is required");
|
|
91
|
+
if (!await config.humanUserEligible(user.id)) invalidGrant("Verified identity is required");
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function refreshHash(token) {
|
|
97
|
+
const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(token)));
|
|
98
|
+
return btoa(String.fromCharCode(...bytes)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
99
|
+
}
|
|
100
|
+
function issuedClaims(token) {
|
|
101
|
+
const payload = token.split(".")[1];
|
|
102
|
+
if (!payload) return null;
|
|
103
|
+
try {
|
|
104
|
+
const decoded = JSON.parse(atob(payload.replaceAll("-", "+").replaceAll("_", "/")));
|
|
105
|
+
return decoded && typeof decoded === "object" && !Array.isArray(decoded) ? decoded : null;
|
|
106
|
+
} catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function rejectedTokenResponse() {
|
|
111
|
+
return Response.json({ error: "invalid_grant" }, { status: 400, headers: { "cache-control": "no-store" } });
|
|
112
|
+
}
|
|
113
|
+
async function appOAuthTokenResponse(request, config) {
|
|
114
|
+
validate(config);
|
|
115
|
+
let grantType = null;
|
|
116
|
+
try {
|
|
117
|
+
grantType = String((await request.clone().formData()).get("grant_type") ?? "");
|
|
118
|
+
} catch {
|
|
119
|
+
}
|
|
120
|
+
const response = await config.handler(request);
|
|
121
|
+
if (!response.ok) return response;
|
|
122
|
+
if (grantType !== "authorization_code" && grantType !== "refresh_token") return rejectedTokenResponse();
|
|
123
|
+
const issued = await response.clone().json();
|
|
124
|
+
const claims = typeof issued.access_token === "string" ? issuedClaims(issued.access_token) : null;
|
|
125
|
+
if (!claims || typeof claims.sub !== "string" || typeof claims.client_id !== "string" || typeof claims[config.consentClaim] !== "string") return rejectedTokenResponse();
|
|
126
|
+
const scopes = typeof claims.scope === "string" ? claims.scope.split(" ").filter(Boolean) : [];
|
|
127
|
+
const consent = await activeAppOAuthConsent(config, claims.client_id, claims.sub, scopes);
|
|
128
|
+
if (!consent || consent.id !== claims[config.consentClaim]) return rejectedTokenResponse();
|
|
129
|
+
if (typeof issued.refresh_token === "string") {
|
|
130
|
+
const row = await config.refreshStore.findByHash(await refreshHash(issued.refresh_token));
|
|
131
|
+
if (!row || row.clientId !== claims.client_id || row.userId !== claims.sub) return rejectedTokenResponse();
|
|
132
|
+
if (grantType === "authorization_code") {
|
|
133
|
+
if (!await config.refreshStore.bindIfUnbound(row.id, consent.id)) return rejectedTokenResponse();
|
|
134
|
+
} else if (row.referenceId !== consent.id) return rejectedTokenResponse();
|
|
135
|
+
}
|
|
136
|
+
return response;
|
|
137
|
+
}
|
|
138
|
+
function createAppOAuthResourceVerifier(config) {
|
|
139
|
+
validate(config);
|
|
140
|
+
const jwksCacheKey = {};
|
|
141
|
+
return async (request) => {
|
|
142
|
+
if (request.headers.has("dpop")) return null;
|
|
143
|
+
const token = /^Bearer ([^\s]+)$/i.exec(request.headers.get("authorization") ?? "")?.[1];
|
|
144
|
+
if (!token || /^(sk-|gak_|svc_)/.test(token)) return null;
|
|
145
|
+
let claims;
|
|
146
|
+
try {
|
|
147
|
+
claims = await verifyJwsAccessToken(token, {
|
|
148
|
+
jwksCacheKey,
|
|
149
|
+
jwksFetch: async () => {
|
|
150
|
+
try {
|
|
151
|
+
const jwks = await config.jwksFetch();
|
|
152
|
+
if (!jwks || !Array.isArray(jwks.keys)) throw new Error("Invalid JWKS response");
|
|
153
|
+
return jwks;
|
|
154
|
+
} catch (cause) {
|
|
155
|
+
const error = new Error("App OAuth JWKS unavailable", { cause });
|
|
156
|
+
Object.defineProperty(error, OPERATIONAL_ERROR, { value: true });
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
verifyOptions: {
|
|
161
|
+
issuer: config.issuer,
|
|
162
|
+
audience: config.resource,
|
|
163
|
+
algorithms: ASYMMETRIC_ALGORITHMS,
|
|
164
|
+
requiredClaims: ["exp"]
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (typeof error === "object" && error !== null && error[OPERATIONAL_ERROR]) throw error;
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
if (!claims || typeof claims.sub !== "string" || !claims.sub || claims.cnf !== void 0 || typeof claims.client_id !== "string" || !claims.client_id || typeof claims.sid !== "string" || !claims.sid) return null;
|
|
172
|
+
const consentId = claims[config.consentClaim];
|
|
173
|
+
if (typeof consentId !== "string" || !consentId) return null;
|
|
174
|
+
const clientId = claims.client_id;
|
|
175
|
+
const userId = claims.sub;
|
|
176
|
+
const tokenScopes = typeof claims.scope === "string" ? claims.scope.split(" ").filter(Boolean) : [];
|
|
177
|
+
const authority = config.authority;
|
|
178
|
+
if ("readSnapshot" in authority) {
|
|
179
|
+
const snapshot = await authority.readSnapshot({
|
|
180
|
+
clientId,
|
|
181
|
+
userId,
|
|
182
|
+
sessionId: claims.sid,
|
|
183
|
+
consentId,
|
|
184
|
+
resource: config.resource,
|
|
185
|
+
scopes: tokenScopes,
|
|
186
|
+
claims: { ...claims }
|
|
187
|
+
});
|
|
188
|
+
if (!snapshot?.active || !snapshot.clientActive || !snapshot.resourceActive || !snapshot.clientResourceLinked || !snapshot.sessionActive || !snapshot.userActive || consentFromRows(config, snapshot.consents, tokenScopes)?.id !== consentId) return null;
|
|
189
|
+
} else {
|
|
190
|
+
if (!await authority.clientActive(clientId) || !await authority.resourceActive(config.resource) || !await authority.clientResourceLinked(clientId, config.resource)) return null;
|
|
191
|
+
const consent = await activeAppOAuthConsent({ ...config, authority }, clientId, userId, tokenScopes);
|
|
192
|
+
if (!consent || consent.id !== consentId) return null;
|
|
193
|
+
if (!await authority.sessionActive(claims.sid, userId) || !await authority.userActive(userId)) return null;
|
|
194
|
+
}
|
|
195
|
+
return { userId, clientId, scopes: tokenScopes.filter((scope) => config.scopes.includes(scope)) };
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function withoutDpop(metadata) {
|
|
199
|
+
const bearerOnly = { ...metadata };
|
|
200
|
+
delete bearerOnly.dpop_signing_alg_values_supported;
|
|
201
|
+
return bearerOnly;
|
|
202
|
+
}
|
|
203
|
+
async function appOAuthMetadataResponse(request, handler) {
|
|
204
|
+
const response = await handler(request);
|
|
205
|
+
if (!response.ok) return response;
|
|
206
|
+
const metadata = await response.json();
|
|
207
|
+
const headers = new Headers(response.headers);
|
|
208
|
+
headers.delete("content-length");
|
|
209
|
+
return Response.json(withoutDpop(metadata), { status: response.status, headers });
|
|
210
|
+
}
|
|
211
|
+
async function appOAuthProtectedResourceMetadata(config, auth) {
|
|
212
|
+
validate(config);
|
|
213
|
+
const overrides = {
|
|
214
|
+
resource: config.resource,
|
|
215
|
+
authorization_servers: [config.issuer],
|
|
216
|
+
scopes_supported: [...config.scopes, "offline_access"]
|
|
217
|
+
};
|
|
218
|
+
const metadata = auth ? await oauthProviderResourceClient(auth).getActions().getProtectedResourceMetadata(overrides) : await oauthProviderResourceClient().getActions().getProtectedResourceMetadata(overrides, {
|
|
219
|
+
externalScopes: overrides.scopes_supported
|
|
220
|
+
});
|
|
221
|
+
return withoutDpop(metadata);
|
|
222
|
+
}
|
|
223
|
+
export {
|
|
224
|
+
activeAppOAuthConsent,
|
|
225
|
+
appOAuthMetadataResponse,
|
|
226
|
+
appOAuthProtectedResourceMetadata,
|
|
227
|
+
appOAuthTokenResponse,
|
|
228
|
+
createAppOAuthProvider,
|
|
229
|
+
createAppOAuthResourceVerifier
|
|
230
|
+
};
|
|
231
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/app-oauth/index.ts"],"sourcesContent":["/** OAuth for an application's MCP resource. The host owns identity, tables and grants. */\nimport { oauthProvider } from '@better-auth/oauth-provider'\nimport { oauthProviderResourceClient } from '@better-auth/oauth-provider/resource-client'\nimport { APIError } from 'better-auth/api'\nimport { verifyJwsAccessToken } from 'better-auth/oauth2'\n\nconst ASYMMETRIC_ALGORITHMS = ['EdDSA', 'ES256', 'ES384', 'ES512', 'PS256', 'PS384', 'PS512', 'RS256', 'RS384', 'RS512']\nconst OPERATIONAL_ERROR = Symbol('appOAuthOperational')\n// Better Auth 1.7.2 strips these AS-owned access-token claims at issuance.\nconst RESERVED_CONSENT_CLAIMS = new Set(['iss', 'sub', 'aud', 'exp', 'iat', 'jti', 'client_id', 'scope',\n 'auth_time', 'acr', 'amr', 'cnf', 'sid', 'nbf', 'azp'])\nconst STANDARD_SCOPES = ['openid', 'profile', 'email', 'offline_access']\n\nexport interface AppOAuthConsent {\n id: string\n /** JSON string or string array, as returned by the host's persistence adapter. */\n scopes: string | readonly string[] | null\n resources: string | readonly string[] | null\n}\n\n/** The issuer reads current consent before minting a token. A lookup outage must throw. */\nexport interface AppOAuthConsentAuthority {\n findConsents(clientId: string, userId: string): Promise<readonly AppOAuthConsent[]>\n}\n\n/** Each callback reads current host authority. A lookup outage must throw. */\nexport interface AppOAuthAuthority extends AppOAuthConsentAuthority {\n clientActive(clientId: string): Promise<boolean>\n resourceActive(resource: string): Promise<boolean>\n clientResourceLinked(clientId: string, resource: string): Promise<boolean>\n sessionActive(sessionId: string, userId: string): Promise<boolean>\n userActive(userId: string): Promise<boolean>\n}\n\nexport interface AppOAuthAuthoritySnapshotInput {\n clientId: string\n userId: string\n sessionId: string\n consentId: string\n resource: string\n scopes: readonly string[]\n /** Claims from a verified JWS. The host can forward its own grant generation. */\n claims: Readonly<Record<string, unknown>>\n}\n\nexport interface AppOAuthAuthoritySnapshot {\n active: boolean\n clientActive: boolean\n resourceActive: boolean\n clientResourceLinked: boolean\n consents: readonly AppOAuthConsent[]\n sessionActive: boolean\n userActive: boolean\n}\n\n/** Read one uncached, current authority view after JWS verification. */\nexport interface AppOAuthSnapshotAuthority {\n readSnapshot(input: AppOAuthAuthoritySnapshotInput): Promise<AppOAuthAuthoritySnapshot>\n}\n\nexport interface AppOAuthConfig {\n /** Exact RFC 8707 audience. The host owns the URL and its route. */\n resource: string\n /** Exact issuer, including Better Auth's /api/auth base path. */\n issuer: string\n /** OAuth permissions the application offers for this resource. */\n scopes: readonly string[]\n /** Scope granted to a dynamically registered client by default. */\n defaultClientScope: string\n /** Claim containing the current consent row ID. */\n consentClaim: string\n}\n\nexport type AppOAuthIssuerConfig = AppOAuthConfig & { authority: AppOAuthConsentAuthority }\nexport type AppOAuthResourceConfig = AppOAuthConfig & {\n authority: AppOAuthAuthority | AppOAuthSnapshotAuthority\n}\n\nexport type AppOAuthJwksFetch = Extract<Parameters<typeof verifyJwsAccessToken>[1]['jwksFetch'], (...args: never[]) => unknown>\n\nfunction list(value: AppOAuthConsent['scopes']): string[] | null {\n if (Array.isArray(value)) return value.every(item => typeof item === 'string') ? [...value] : null\n if (typeof value !== 'string') return null\n try {\n const parsed: unknown = JSON.parse(value)\n return Array.isArray(parsed) && parsed.every(item => typeof item === 'string') ? parsed : null\n } catch { return null }\n}\n\nfunction validate(config: AppOAuthConfig): void {\n const issuer = new URL(config.issuer)\n const resource = new URL(config.resource)\n if (!config.issuer || !config.resource || !/^[a-z][a-z0-9_]*$/.test(config.consentClaim)\n || RESERVED_CONSENT_CLAIMS.has(config.consentClaim)\n || !config.scopes.length\n || !config.scopes.includes(config.defaultClientScope)\n || issuer.hash || issuer.search || resource.hash || resource.search\n || issuer.username || issuer.password || resource.username || resource.password\n || !['https:', 'http:'].includes(issuer.protocol) || !['https:', 'http:'].includes(resource.protocol)\n || (issuer.protocol === 'http:' && !['localhost', '127.0.0.1', '[::1]'].includes(issuer.hostname))\n || (resource.protocol === 'http:' && !['localhost', '127.0.0.1', '[::1]'].includes(resource.hostname))) {\n throw new Error('app-oauth: invalid issuer, resource, scopes or consent claim')\n }\n}\n\n/** Require exactly one current consent; malformed grants cannot widen authority. */\nfunction consentFromRows(config: AppOAuthConfig, rows: readonly AppOAuthConsent[],\n scopes: readonly string[]): AppOAuthConsent | null {\n if (!Array.isArray(rows)) return null\n if (rows.length !== 1) return null\n const consent = rows[0]\n if (!consent?.id) return null\n const resources = list(consent.resources)\n const granted = list(consent.scopes)\n if (!resources?.includes(config.resource) || !granted) return null\n return scopes.every(scope => granted.includes(scope)) ? consent : null\n}\n\nexport async function activeAppOAuthConsent(config: AppOAuthIssuerConfig, clientId: string, userId: string,\n scopes: readonly string[]): Promise<AppOAuthConsent | null> {\n return consentFromRows(config, await config.authority.findConsents(clientId, userId), scopes)\n}\n\nfunction invalidGrant(description: string): never {\n throw new APIError('BAD_REQUEST', { error: 'invalid_grant', error_description: description })\n}\n\n/** Compose the maintained Better Auth provider with one host's live authority. */\nexport function createAppOAuthProvider(config: AppOAuthIssuerConfig & {\n loginPage: string\n consentPage: string\n /** The host must reject deleted, disabled or unverified users at token mint. */\n humanUserEligible(userId: string): Promise<boolean>\n}): ReturnType<typeof oauthProvider> {\n validate(config)\n return oauthProvider({\n loginPage: config.loginPage,\n consentPage: config.consentPage,\n accessTokenExpiresIn: 900,\n refreshTokenExpiresIn: 604800,\n codeExpiresIn: 600,\n grantTypes: ['authorization_code', 'refresh_token'],\n dpop: { signingAlgorithms: [] },\n scopes: [...STANDARD_SCOPES, ...config.scopes],\n defaultScope: 'openid profile email',\n allowPublicClientPrelogin: true,\n allowDynamicClientRegistration: true,\n allowUnauthenticatedClientRegistration: true,\n clientRegistrationDefaultScopes: [config.defaultClientScope],\n clientRegistrationAllowedScopes: [...STANDARD_SCOPES, ...config.scopes],\n clientRegistrationDefaultResources: [config.resource],\n clientRegistrationAllowedResources: [config.resource],\n resources: [{ identifier: config.resource, accessTokenTtl: 900, allowedScopes: [...config.scopes] }],\n resourceSeedMode: 'insertOnly',\n enforcePerClientResources: true,\n extensions: [{ claims: { accessToken: async ({ user, client, scopes, resources, grantType, referenceId }) => {\n if (!user?.id || !resources?.includes(config.resource)) invalidGrant('Resource consent is required')\n const consent = await activeAppOAuthConsent(config, client.clientId, user.id, scopes)\n if (!consent || (grantType === 'refresh_token' && referenceId !== consent.id)) {\n invalidGrant('Resource consent changed')\n }\n return { [config.consentClaim]: consent.id }\n } } }],\n customTokenResponseFields: async ({ grantType, user }) => {\n if (grantType === 'client_credentials' || !user?.id) invalidGrant('Human identity is required')\n if (!await config.humanUserEligible(user.id)) invalidGrant('Verified identity is required')\n return {}\n },\n })\n}\n\nexport interface AppOAuthRefreshToken {\n id: string\n clientId: string\n userId: string\n referenceId: string | null\n}\n\nexport interface AppOAuthRefreshStore {\n findByHash(hash: string): Promise<AppOAuthRefreshToken | null>\n /** Atomically set referenceId only when it is NULL. */\n bindIfUnbound(id: string, consentId: string): Promise<boolean>\n}\n\nasync function refreshHash(token: string): Promise<string> {\n const bytes = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(token)))\n return btoa(String.fromCharCode(...bytes)).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/, '')\n}\n\nfunction issuedClaims(token: string): Record<string, unknown> | null {\n const payload = token.split('.')[1]\n if (!payload) return null\n try {\n const decoded: unknown = JSON.parse(atob(payload.replaceAll('-', '+').replaceAll('_', '/')))\n return decoded && typeof decoded === 'object' && !Array.isArray(decoded)\n ? decoded as Record<string, unknown> : null\n } catch { return null }\n}\n\nfunction rejectedTokenResponse(): Response {\n return Response.json({ error: 'invalid_grant' }, { status: 400, headers: { 'cache-control': 'no-store' } })\n}\n\n/** Bind refresh rows to the current consent before their secret leaves the host. */\nexport async function appOAuthTokenResponse(request: Request, config: AppOAuthIssuerConfig & {\n handler(request: Request): Promise<Response>\n refreshStore: AppOAuthRefreshStore\n}): Promise<Response> {\n validate(config)\n let grantType: string | null = null\n try { grantType = String((await request.clone().formData()).get('grant_type') ?? '') }\n catch { /* The provider owns malformed-request responses. */ }\n const response = await config.handler(request)\n if (!response.ok) return response\n if (grantType !== 'authorization_code' && grantType !== 'refresh_token') return rejectedTokenResponse()\n const issued = await response.clone().json() as { access_token?: unknown; refresh_token?: unknown }\n const claims = typeof issued.access_token === 'string' ? issuedClaims(issued.access_token) : null\n if (!claims || typeof claims.sub !== 'string' || typeof claims.client_id !== 'string'\n || typeof claims[config.consentClaim] !== 'string') return rejectedTokenResponse()\n const scopes = typeof claims.scope === 'string' ? claims.scope.split(' ').filter(Boolean) : []\n const consent = await activeAppOAuthConsent(config, claims.client_id, claims.sub, scopes)\n if (!consent || consent.id !== claims[config.consentClaim]) return rejectedTokenResponse()\n if (typeof issued.refresh_token === 'string') {\n const row = await config.refreshStore.findByHash(await refreshHash(issued.refresh_token))\n if (!row || row.clientId !== claims.client_id || row.userId !== claims.sub) return rejectedTokenResponse()\n if (grantType === 'authorization_code') {\n if (!await config.refreshStore.bindIfUnbound(row.id, consent.id)) return rejectedTokenResponse()\n } else if (row.referenceId !== consent.id) return rejectedTokenResponse()\n }\n return response\n}\n\nexport interface AppOAuthPrincipal {\n userId: string\n clientId: string\n scopes: readonly string[]\n}\n\n/** Verify bearer tokens and current host grants before any private tool is listed. */\nexport function createAppOAuthResourceVerifier(config: AppOAuthResourceConfig & {\n jwksFetch: AppOAuthJwksFetch\n}) {\n validate(config)\n const jwksCacheKey = {}\n return async (request: Request): Promise<AppOAuthPrincipal | null> => {\n if (request.headers.has('dpop')) return null\n const token = /^Bearer ([^\\s]+)$/i.exec(request.headers.get('authorization') ?? '')?.[1]\n if (!token || /^(sk-|gak_|svc_)/.test(token)) return null\n let claims: Awaited<ReturnType<typeof verifyJwsAccessToken>>\n try {\n claims = await verifyJwsAccessToken(token, {\n jwksCacheKey,\n jwksFetch: async () => {\n try {\n const jwks = await config.jwksFetch()\n if (!jwks || !Array.isArray(jwks.keys)) throw new Error('Invalid JWKS response')\n return jwks\n }\n catch (cause) {\n const error = new Error('App OAuth JWKS unavailable', { cause })\n Object.defineProperty(error, OPERATIONAL_ERROR, { value: true })\n throw error\n }\n },\n verifyOptions: { issuer: config.issuer, audience: config.resource,\n algorithms: ASYMMETRIC_ALGORITHMS, requiredClaims: ['exp'] },\n })\n } catch (error) {\n if (typeof error === 'object' && error !== null && (error as Record<PropertyKey, unknown>)[OPERATIONAL_ERROR]) throw error\n return null\n }\n if (!claims || typeof claims.sub !== 'string' || !claims.sub || claims.cnf !== undefined\n || typeof claims.client_id !== 'string' || !claims.client_id\n || typeof claims.sid !== 'string' || !claims.sid) return null\n const consentId = claims[config.consentClaim]\n if (typeof consentId !== 'string' || !consentId) return null\n const clientId = claims.client_id\n const userId = claims.sub\n const tokenScopes = typeof claims.scope === 'string' ? claims.scope.split(' ').filter(Boolean) : []\n const authority = config.authority\n if ('readSnapshot' in authority) {\n const snapshot = await authority.readSnapshot({ clientId, userId, sessionId: claims.sid,\n consentId, resource: config.resource, scopes: tokenScopes, claims: { ...claims } })\n if (!snapshot?.active || !snapshot.clientActive || !snapshot.resourceActive\n || !snapshot.clientResourceLinked || !snapshot.sessionActive || !snapshot.userActive\n || consentFromRows(config, snapshot.consents, tokenScopes)?.id !== consentId) return null\n } else {\n if (!await authority.clientActive(clientId)\n || !await authority.resourceActive(config.resource)\n || !await authority.clientResourceLinked(clientId, config.resource)) return null\n const consent = await activeAppOAuthConsent({ ...config, authority }, clientId, userId, tokenScopes)\n if (!consent || consent.id !== consentId) return null\n if (!await authority.sessionActive(claims.sid, userId)\n || !await authority.userActive(userId)) return null\n }\n return { userId, clientId, scopes: tokenScopes.filter(scope => config.scopes.includes(scope)) }\n }\n}\n\nfunction withoutDpop(metadata: object): Record<string, unknown> {\n const bearerOnly = { ...metadata } as Record<string, unknown>\n delete bearerOnly.dpop_signing_alg_values_supported\n return bearerOnly\n}\n\n/** Strip unsupported DPoP advertisement from Better Auth's issuer metadata. */\nexport async function appOAuthMetadataResponse(request: Request, handler: (request: Request) => Promise<Response>): Promise<Response> {\n const response = await handler(request)\n if (!response.ok) return response\n const metadata = await response.json() as Record<string, unknown>\n const headers = new Headers(response.headers)\n headers.delete('content-length')\n return Response.json(withoutDpop(metadata), { status: response.status, headers })\n}\n\n/** RFC 9728 metadata for an issuer-hosted or separate protected resource. */\nexport async function appOAuthProtectedResourceMetadata(\n config: AppOAuthConfig, auth?: NonNullable<Parameters<typeof oauthProviderResourceClient>[0]>,\n) {\n validate(config)\n const overrides = {\n resource: config.resource,\n authorization_servers: [config.issuer],\n scopes_supported: [...config.scopes, 'offline_access'],\n }\n const metadata = auth\n ? await oauthProviderResourceClient(auth).getActions().getProtectedResourceMetadata(overrides)\n : await oauthProviderResourceClient().getActions().getProtectedResourceMetadata(overrides, {\n externalScopes: overrides.scopes_supported,\n })\n return withoutDpop(metadata)\n}\n"],"mappings":";AACA,SAAS,qBAAqB;AAC9B,SAAS,mCAAmC;AAC5C,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AAErC,IAAM,wBAAwB,CAAC,SAAS,SAAS,SAAS,SAAS,SAAS,SAAS,SAAS,SAAS,SAAS,OAAO;AACvH,IAAM,oBAAoB,uBAAO,qBAAqB;AAEtD,IAAM,0BAA0B,oBAAI,IAAI;AAAA,EAAC;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA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AM,UAAU,cAAc,OAAO,KAAK,MAAM,KAChD,CAAC,MAAM,UAAU,WAAW,MAAM,EAAG,QAAO;AAAA,IACnD;AACA,WAAO,EAAE,QAAQ,UAAU,QAAQ,YAAY,OAAO,WAAS,OAAO,OAAO,SAAS,KAAK,CAAC,EAAE;AAAA,EAChG;AACF;AAEA,SAAS,YAAY,UAA2C;AAC9D,QAAM,aAAa,EAAE,GAAG,SAAS;AACjC,SAAO,WAAW;AAClB,SAAO;AACT;AAGA,eAAsB,yBAAyB,SAAkB,SAAqE;AACpI,QAAM,WAAW,MAAM,QAAQ,OAAO;AACtC,MAAI,CAAC,SAAS,GAAI,QAAO;AACzB,QAAM,WAAW,MAAM,SAAS,KAAK;AACrC,QAAM,UAAU,IAAI,QAAQ,SAAS,OAAO;AAC5C,UAAQ,OAAO,gBAAgB;AAC/B,SAAO,SAAS,KAAK,YAAY,QAAQ,GAAG,EAAE,QAAQ,SAAS,QAAQ,QAAQ,CAAC;AAClF;AAGA,eAAsB,kCACpB,QAAwB,MACxB;AACA,WAAS,MAAM;AACf,QAAM,YAAY;AAAA,IAChB,UAAU,OAAO;AAAA,IACjB,uBAAuB,CAAC,OAAO,MAAM;AAAA,IACrC,kBAAkB,CAAC,GAAG,OAAO,QAAQ,gBAAgB;AAAA,EACvD;AACA,QAAM,WAAW,OACb,MAAM,4BAA4B,IAAI,EAAE,WAAW,EAAE,6BAA6B,SAAS,IAC3F,MAAM,4BAA4B,EAAE,WAAW,EAAE,6BAA6B,WAAW;AAAA,IACzF,gBAAgB,UAAU;AAAA,EAC5B,CAAC;AACH,SAAO,YAAY,QAAQ;AAC7B;","names":[]}
|
package/dist/assistant/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from "../chunk-UNXMIWPK.js";
|
|
5
5
|
import "../chunk-42FA6YQH.js";
|
|
6
6
|
import "../chunk-3HUFJ5LO.js";
|
|
7
|
+
import "../chunk-E4AY62T2.js";
|
|
7
8
|
import "../chunk-FBVLEGEG.js";
|
|
8
9
|
import "../chunk-ENLRJYVW.js";
|
|
9
10
|
import "../chunk-GEYACSFW.js";
|
|
@@ -14,7 +15,6 @@ import "../chunk-L7MB2LLM.js";
|
|
|
14
15
|
import {
|
|
15
16
|
ModelPicker
|
|
16
17
|
} from "../chunk-XF6ZRY56.js";
|
|
17
|
-
import "../chunk-BATKJP3P.js";
|
|
18
18
|
import "../chunk-SJWIZT7B.js";
|
|
19
19
|
import {
|
|
20
20
|
AsyncView
|
|
@@ -45,13 +45,13 @@ import {
|
|
|
45
45
|
} from "../chunk-2TZLCQ5U.js";
|
|
46
46
|
import "../chunk-MCYJON3F.js";
|
|
47
47
|
import "../chunk-LWSJK546.js";
|
|
48
|
-
import "../chunk-
|
|
48
|
+
import "../chunk-PF3AZD5G.js";
|
|
49
49
|
import "../chunk-6A7MYOUI.js";
|
|
50
|
-
import "../chunk-
|
|
50
|
+
import "../chunk-2PDKWV2S.js";
|
|
51
51
|
import "../chunk-UGWQLQDS.js";
|
|
52
52
|
import "../chunk-S5SRJJQG.js";
|
|
53
|
-
import "../chunk-
|
|
54
|
-
import "../chunk-
|
|
53
|
+
import "../chunk-IYLPQKAH.js";
|
|
54
|
+
import "../chunk-CBRYWGUO.js";
|
|
55
55
|
import {
|
|
56
56
|
ProtectedModelSettlementError
|
|
57
57
|
} from "../chunk-KHRIPDW5.js";
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
OPENUI_NODE_JSON_SCHEMA,
|
|
6
6
|
OPENUI_NODE_TYPES
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-CBRYWGUO.js";
|
|
8
8
|
|
|
9
9
|
// src/tools/openai.ts
|
|
10
10
|
var APP_TOOL_NAMES = ["submit_proposal", "schedule_followup", "render_ui", "add_citation"];
|
|
@@ -112,4 +112,4 @@ export {
|
|
|
112
112
|
customToolToOpenAI,
|
|
113
113
|
findCustomTool
|
|
114
114
|
};
|
|
115
|
-
//# sourceMappingURL=chunk-
|
|
115
|
+
//# sourceMappingURL=chunk-2PDKWV2S.js.map
|
|
@@ -273,7 +273,7 @@ function OperationErrorAlert({
|
|
|
273
273
|
"div",
|
|
274
274
|
{
|
|
275
275
|
role: "alert",
|
|
276
|
-
className: "flex shrink-0 items-center justify-between gap-3 border-b border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-
|
|
276
|
+
className: "flex shrink-0 items-center justify-between gap-3 border-b border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-[var(--surface-danger-text)]",
|
|
277
277
|
children: [
|
|
278
278
|
/* @__PURE__ */ jsx2("span", { className: "min-w-0 flex-1", children: message }),
|
|
279
279
|
/* @__PURE__ */ jsxs2("div", { className: "flex shrink-0 items-center gap-3", children: [
|
|
@@ -904,7 +904,7 @@ var VaultPane = forwardRef(function VaultPane2(props, ref) {
|
|
|
904
904
|
setDeleteError(null);
|
|
905
905
|
setDeleteOpen(true);
|
|
906
906
|
},
|
|
907
|
-
className: "inline-flex h-7 w-7 items-center justify-center rounded text-
|
|
907
|
+
className: "inline-flex h-7 w-7 items-center justify-center rounded text-[var(--surface-danger-text)] transition-colors hover:bg-destructive/10",
|
|
908
908
|
children: /* @__PURE__ */ jsx2(Trash2, { className: "h-4 w-4" })
|
|
909
909
|
}
|
|
910
910
|
)
|
|
@@ -985,7 +985,7 @@ var VaultPane = forwardRef(function VaultPane2(props, ref) {
|
|
|
985
985
|
className: "h-9 w-full rounded-md border border-border bg-background px-3 text-sm text-foreground placeholder:text-muted-foreground"
|
|
986
986
|
}
|
|
987
987
|
),
|
|
988
|
-
createError && /* @__PURE__ */ jsx2("p", { role: "alert", className: "text-xs text-
|
|
988
|
+
createError && /* @__PURE__ */ jsx2("p", { role: "alert", className: "text-xs text-[var(--surface-danger-text)]", children: createError.message })
|
|
989
989
|
] })
|
|
990
990
|
}
|
|
991
991
|
),
|
|
@@ -1003,7 +1003,7 @@ var VaultPane = forwardRef(function VaultPane2(props, ref) {
|
|
|
1003
1003
|
setDeleteOpen(false);
|
|
1004
1004
|
setDeleteError(null);
|
|
1005
1005
|
},
|
|
1006
|
-
children: deleteError && /* @__PURE__ */ jsx2("p", { role: "alert", className: "text-xs text-
|
|
1006
|
+
children: deleteError && /* @__PURE__ */ jsx2("p", { role: "alert", className: "text-xs text-[var(--surface-danger-text)]", children: deleteError.message })
|
|
1007
1007
|
}
|
|
1008
1008
|
),
|
|
1009
1009
|
/* @__PURE__ */ jsx2(
|
|
@@ -1065,4 +1065,4 @@ export {
|
|
|
1065
1065
|
ConfirmDialog,
|
|
1066
1066
|
VaultPane
|
|
1067
1067
|
};
|
|
1068
|
-
//# sourceMappingURL=chunk-
|
|
1068
|
+
//# sourceMappingURL=chunk-3IATFW4U.js.map
|