@tangle-network/agent-app 0.50.32 → 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/agent-enrollment/application.d.ts +25 -5
- package/dist/agent-enrollment/drizzle.js +1 -1
- package/dist/agent-enrollment/index.d.ts +1 -1
- package/dist/agent-enrollment/index.js +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-NLXY7TFB.js → chunk-C3JSO2CB.js} +43 -18
- 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/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/theme/tokens.css +3 -1
- package/dist/tools/index.js +4 -4
- 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 +25 -5
- package/dist/chunk-BATKJP3P.js.map +0 -1
- package/dist/chunk-NLXY7TFB.js.map +0 -1
- /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
|
@@ -5,6 +5,8 @@ import type { ResolvedAgentEnrollment } from './index';
|
|
|
5
5
|
export interface AuthenticatedSharedLinePrincipal<Principal> {
|
|
6
6
|
principal: Principal;
|
|
7
7
|
binding: string;
|
|
8
|
+
/** Identity of the verified binding-scoped bearer, checked again at the task write. */
|
|
9
|
+
callbackCredentialId: string;
|
|
8
10
|
}
|
|
9
11
|
/** Current host-owned app, customer and member grant for one Hub subject. */
|
|
10
12
|
export interface LiveSharedEnrollmentMember {
|
|
@@ -16,6 +18,8 @@ export interface LiveSharedEnrollmentMember {
|
|
|
16
18
|
memberId: string;
|
|
17
19
|
/** Changes on every grant, consent, or target remap, including revoke and regrant. */
|
|
18
20
|
grantRevision: string;
|
|
21
|
+
/** Fresh Hub member.updatedAt, independent of the application's grant revision. */
|
|
22
|
+
memberRevision: string;
|
|
19
23
|
ownerUserId: string;
|
|
20
24
|
senderAddress: string;
|
|
21
25
|
enrollmentId: string;
|
|
@@ -23,20 +27,36 @@ export interface LiveSharedEnrollmentMember {
|
|
|
23
27
|
workspaceId: string;
|
|
24
28
|
threadId: string;
|
|
25
29
|
}
|
|
30
|
+
/** Signed Hub fields required for every shared Line observation. */
|
|
31
|
+
export interface ObservedSharedLineApplicationRequest extends LineApplicationRequest {
|
|
32
|
+
subjectId: string;
|
|
33
|
+
memberRevision: string;
|
|
34
|
+
dispatchFence?: string;
|
|
35
|
+
dispatchDeadline?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Lease fields required before a shared Line can admit new work. */
|
|
38
|
+
export interface SignedSharedLineApplicationRequest extends ObservedSharedLineApplicationRequest {
|
|
39
|
+
dispatchFence: string;
|
|
40
|
+
/** Canonical UTC timestamp with milliseconds when this attempt loses admission authority. */
|
|
41
|
+
dispatchDeadline: string;
|
|
42
|
+
}
|
|
26
43
|
export interface EnrolledApplicationLineOptions<Principal> {
|
|
27
|
-
/** Verify the
|
|
44
|
+
/** Verify the callback bearer and return its current credential identity. */
|
|
28
45
|
authenticate(request: Request): Promise<AuthenticatedSharedLinePrincipal<Principal>>;
|
|
29
46
|
/** Select an intended app from durable policy. Message text is intent, never a grant. */
|
|
30
47
|
selectApp(authenticated: AuthenticatedSharedLinePrincipal<Principal>, input: Readonly<LineApplicationRequest>): Promise<string>;
|
|
31
|
-
/** Re-read live app,
|
|
48
|
+
/** Re-read live app, consent, grant and Hub member.updatedAt for the selected app. */
|
|
32
49
|
lookup(principal: Principal, binding: string, subjectId: string, appId: string): Promise<LiveSharedEnrollmentMember | null>;
|
|
33
50
|
enrollment: {
|
|
34
51
|
resolve(principal: Principal, enrollmentId: string): Promise<ResolvedAgentEnrollment>;
|
|
35
52
|
};
|
|
36
53
|
/** Read through the application's existing durable output store using the pinned grant. */
|
|
37
|
-
read(resolved: ResolvedAgentEnrollment, input: Readonly<
|
|
38
|
-
/**
|
|
39
|
-
|
|
54
|
+
read(resolved: ResolvedAgentEnrollment, input: Readonly<ObservedSharedLineApplicationRequest>, member: Readonly<LiveSharedEnrollmentMember>): Promise<ApplicationLineObservation>;
|
|
55
|
+
/**
|
|
56
|
+
* At the durable write, atomically compare the live grant, Hub member revision,
|
|
57
|
+
* callback credential, dispatch fence and deadline. Deduplicate by messageId.
|
|
58
|
+
*/
|
|
59
|
+
admit(resolved: ResolvedAgentEnrollment, input: Readonly<SignedSharedLineApplicationRequest>, member: Readonly<LiveSharedEnrollmentMember>, authenticated: Readonly<AuthenticatedSharedLinePrincipal<Principal>>): Promise<void>;
|
|
40
60
|
}
|
|
41
61
|
/** Bind a signed shared Line member to the same native target used by web and ChatGPT. */
|
|
42
62
|
export declare function createEnrolledApplicationLineHandler<Principal>(options: EnrolledApplicationLineOptions<Principal>): (request: Request) => Promise<Response>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EnsureInstanceOptions, Sandbox, SandboxInstance } from '@tangle-network/sandbox/core';
|
|
2
2
|
export { createEnrolledApplicationLineHandler } from './application';
|
|
3
|
-
export type { AuthenticatedSharedLinePrincipal, LiveSharedEnrollmentMember, EnrolledApplicationLineOptions } from './application';
|
|
3
|
+
export type { AuthenticatedSharedLinePrincipal, LiveSharedEnrollmentMember, EnrolledApplicationLineOptions, ObservedSharedLineApplicationRequest, SignedSharedLineApplicationRequest } from './application';
|
|
4
4
|
/** An application's durable pointer to one private agent's native SDK session. */
|
|
5
5
|
export interface AgentEnrollmentTarget {
|
|
6
6
|
enrollmentId: string;
|
|
@@ -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,EAAO;AAAA,EAAO;AAAA,EAAa;AAAA,EAC9F;AAAA,EAAa;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAK,CAAC;AACxD,IAAM,kBAAkB,CAAC,UAAU,WAAW,SAAS,gBAAgB;AAqEvE,SAAS,KAAK,OAAmD;AAC/D,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,MAAM,UAAQ,OAAO,SAAS,QAAQ,IAAI,CAAC,GAAG,KAAK,IAAI;AAC9F,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,MAAI;AACF,UAAM,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I,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";
|
|
@@ -15,7 +16,6 @@ import {
|
|
|
15
16
|
ModelPicker
|
|
16
17
|
} from "../chunk-XF6ZRY56.js";
|
|
17
18
|
import "../chunk-SJWIZT7B.js";
|
|
18
|
-
import "../chunk-BATKJP3P.js";
|
|
19
19
|
import {
|
|
20
20
|
AsyncView
|
|
21
21
|
} from "../chunk-Q3ZHNN5X.js";
|
|
@@ -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
|
|
@@ -9,15 +9,27 @@ function forbidden() {
|
|
|
9
9
|
{ status: 403, headers: { "cache-control": "no-store" } }
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
function utcMillis(value) {
|
|
13
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value)) return null;
|
|
14
|
+
const parsed = Date.parse(value);
|
|
15
|
+
return Number.isFinite(parsed) && new Date(parsed).toISOString() === value ? parsed : null;
|
|
16
|
+
}
|
|
17
|
+
function signedInput(input) {
|
|
18
|
+
const value = input;
|
|
19
|
+
if (typeof value.subjectId !== "string" || !value.subjectId || utcMillis(value.memberRevision) === null) return null;
|
|
20
|
+
if (value.dispatchFence === void 0 && value.dispatchDeadline === void 0)
|
|
21
|
+
return value.acceptedExecutionId === void 0 ? null : value;
|
|
22
|
+
if (typeof value.dispatchFence !== "string" || !value.dispatchFence || utcMillis(value.dispatchDeadline) === null) return null;
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function admissionInput(input) {
|
|
26
|
+
return input.dispatchFence !== void 0 && input.dispatchDeadline !== void 0 ? input : null;
|
|
15
27
|
}
|
|
16
28
|
function matches(input, member) {
|
|
17
|
-
return !!member.enrollmentId && !!member.grantRevision && member.binding === input.binding && member.subjectId === subjectId
|
|
29
|
+
return !!member.enrollmentId && !!member.grantRevision && !!member.memberRevision && member.binding === input.binding && member.subjectId === input.subjectId && member.memberRevision === input.memberRevision && member.lineId === input.lineId && member.attachmentId === input.attachmentId && member.memberId === input.memberId && member.ownerUserId === input.ownerUserId && member.senderAddress === input.sender.address;
|
|
18
30
|
}
|
|
19
31
|
function sameMember(left, right) {
|
|
20
|
-
return left.binding === right.binding && left.subjectId === right.subjectId && left.appId === right.appId && left.grantRevision === right.grantRevision && left.enrollmentId === right.enrollmentId && left.agentId === right.agentId && left.workspaceId === right.workspaceId && left.threadId === right.threadId && left.lineId === right.lineId && left.attachmentId === right.attachmentId && left.memberId === right.memberId && left.ownerUserId === right.ownerUserId && left.senderAddress === right.senderAddress;
|
|
32
|
+
return left.binding === right.binding && left.subjectId === right.subjectId && left.appId === right.appId && left.grantRevision === right.grantRevision && left.memberRevision === right.memberRevision && left.enrollmentId === right.enrollmentId && left.agentId === right.agentId && left.workspaceId === right.workspaceId && left.threadId === right.threadId && left.lineId === right.lineId && left.attachmentId === right.attachmentId && left.memberId === right.memberId && left.ownerUserId === right.ownerUserId && left.senderAddress === right.senderAddress;
|
|
21
33
|
}
|
|
22
34
|
function matchesTarget(member, target) {
|
|
23
35
|
return member.enrollmentId === target.enrollmentId && member.agentId === target.agentId && member.workspaceId === target.workspaceId && member.threadId === target.threadId;
|
|
@@ -27,39 +39,52 @@ function sameTarget(left, right) {
|
|
|
27
39
|
}
|
|
28
40
|
function createEnrolledApplicationLineHandler(options) {
|
|
29
41
|
async function resolve(authenticated, input) {
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
32
|
-
const appId = await options.selectApp(authenticated,
|
|
42
|
+
const signed = signedInput(input);
|
|
43
|
+
if (!signed) throw forbidden();
|
|
44
|
+
const appId = await options.selectApp(authenticated, signed);
|
|
33
45
|
if (!appId || authenticated.selectedAppId && authenticated.selectedAppId !== appId) throw forbidden();
|
|
34
46
|
authenticated.selectedAppId = appId;
|
|
35
|
-
const observedMember = await options.lookup(authenticated.principal, authenticated.binding,
|
|
47
|
+
const observedMember = await options.lookup(authenticated.principal, authenticated.binding, signed.subjectId, appId);
|
|
36
48
|
if (!observedMember) throw forbidden();
|
|
37
49
|
const member = Object.freeze({ ...observedMember });
|
|
38
|
-
if (member.appId !== appId || !matches(
|
|
50
|
+
if (member.appId !== appId || !matches(signed, member) || authenticated.pinned && !sameMember(authenticated.pinned.member, member)) throw forbidden();
|
|
39
51
|
const resolved = await options.enrollment.resolve(authenticated.principal, member.enrollmentId);
|
|
40
52
|
const target = Object.freeze({ ...resolved.target });
|
|
41
53
|
if (!matchesTarget(member, target) || authenticated.pinned && !sameTarget(authenticated.pinned.target, target)) throw forbidden();
|
|
42
|
-
const current = await options.lookup(authenticated.principal, authenticated.binding,
|
|
54
|
+
const current = await options.lookup(authenticated.principal, authenticated.binding, signed.subjectId, appId);
|
|
43
55
|
if (!current || !sameMember(current, member)) throw forbidden();
|
|
44
56
|
authenticated.pinned ??= Object.freeze({ member, target });
|
|
45
|
-
return { resolved: { ...resolved, target }, member: authenticated.pinned.member };
|
|
57
|
+
return { resolved: { ...resolved, target }, member: authenticated.pinned.member, signed };
|
|
46
58
|
}
|
|
47
59
|
return createApplicationLineHandler({
|
|
48
60
|
authenticate: async (request) => {
|
|
49
61
|
const target = await options.authenticate(request);
|
|
50
|
-
if (!target.binding) throw forbidden();
|
|
62
|
+
if (!target.binding || !target.callbackCredentialId) throw forbidden();
|
|
51
63
|
return { binding: target.binding, target: { ...target, selectedAppId: void 0, pinned: void 0 } };
|
|
52
64
|
},
|
|
53
65
|
authorize: async (target, input) => {
|
|
54
66
|
await resolve(target, input);
|
|
55
67
|
},
|
|
56
68
|
read: async (target, input) => {
|
|
57
|
-
const { resolved, member } = await resolve(target, input);
|
|
58
|
-
return options.read(resolved,
|
|
69
|
+
const { resolved, member, signed } = await resolve(target, input);
|
|
70
|
+
return options.read(resolved, signed, member);
|
|
59
71
|
},
|
|
60
72
|
admit: async (target, input) => {
|
|
61
|
-
const { resolved, member } = await resolve(target, input);
|
|
62
|
-
|
|
73
|
+
const { resolved, member, signed } = await resolve(target, input);
|
|
74
|
+
const admission = admissionInput(signed);
|
|
75
|
+
if (!admission) throw forbidden();
|
|
76
|
+
const remaining = Date.parse(admission.dispatchDeadline) - Date.now();
|
|
77
|
+
if (remaining <= 0 || remaining > 6e4) throw forbidden();
|
|
78
|
+
return options.admit(
|
|
79
|
+
resolved,
|
|
80
|
+
admission,
|
|
81
|
+
member,
|
|
82
|
+
Object.freeze({
|
|
83
|
+
principal: target.principal,
|
|
84
|
+
binding: target.binding,
|
|
85
|
+
callbackCredentialId: target.callbackCredentialId
|
|
86
|
+
})
|
|
87
|
+
);
|
|
63
88
|
}
|
|
64
89
|
});
|
|
65
90
|
}
|
|
@@ -204,4 +229,4 @@ export {
|
|
|
204
229
|
EnrollmentTargetError,
|
|
205
230
|
createAgentEnrollment
|
|
206
231
|
};
|
|
207
|
-
//# sourceMappingURL=chunk-
|
|
232
|
+
//# sourceMappingURL=chunk-C3JSO2CB.js.map
|