@agent-native/core 0.221.0 → 0.222.0-nightly-20261028092719
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/client/agent-chat.js +6 -1
- package/dist/client/api-path.d.ts +2 -0
- package/dist/client/api-path.js +76 -55
- package/dist/client/application-state.js +12 -6
- package/dist/client/browser-tab-id.d.ts +2 -0
- package/dist/client/browser-tab-id.js +113 -13
- package/dist/client/collab/index.d.ts +1 -1
- package/dist/client/embed-auth.js +145 -26
- package/dist/client/route-state.js +15 -4
- package/dist/client/sse-event-processor.js +3 -0
- package/dist/client/use-change-version.js +6 -1
- package/dist/client/use-db-sync.js +70 -11
- package/dist/collab/client.d.ts +34 -0
- package/dist/collab/client.js +506 -53
- package/dist/deploy/build.js +10 -0
- package/dist/mcp/embed-app.js +165 -16
- package/dist/provider-api/actions/custom-provider-registration.d.ts +3 -3
- package/dist/provider-api/actions/provider-api.d.ts +4 -4
- package/dist/server/app-origin-config.d.ts +2 -0
- package/dist/server/app-origin-config.js +10 -0
- package/dist/server/auth.d.ts +28 -2
- package/dist/server/auth.js +79 -0
- package/dist/server/credential-provider.d.ts +19 -1
- package/dist/server/credential-provider.js +71 -7
- package/dist/shared/mcp-app-widget-embed.d.ts +23 -1
- package/dist/shared/mcp-app-widget-embed.js +178 -5
- package/dist/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +41 -18
- package/package.json +4 -4
- package/src/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +41 -18
package/dist/deploy/build.js
CHANGED
|
@@ -1747,6 +1747,14 @@ function getAppOriginClientConfigScript() {
|
|
|
1747
1747
|
const workspaceAppPath =
|
|
1748
1748
|
workspaceAppMountConfig?.currentPath ??
|
|
1749
1749
|
(workspaceRuntime ? configuredWorkspaceAppPath : "");
|
|
1750
|
+
const explicitRootPath =
|
|
1751
|
+
workspaceAppMountConfig?.currentPath === "/" ||
|
|
1752
|
+
(typeof appConfig.app.basePath === "string" &&
|
|
1753
|
+
appConfig.app.basePath.trim().length > 0 &&
|
|
1754
|
+
normalizeAppBasePath(appConfig.app.basePath) === "");
|
|
1755
|
+
const frameworkRoutePrefix = (
|
|
1756
|
+
process.env.AGENT_NATIVE_CONFIG_RUNTIME_FRAMEWORK_ROUTE_PREFIX || ""
|
|
1757
|
+
).trim();
|
|
1750
1758
|
const config = {
|
|
1751
1759
|
...(appConfig.app.id ? { appId: appConfig.app.id } : {}),
|
|
1752
1760
|
...(appConfig.app.workspaceId
|
|
@@ -1764,6 +1772,8 @@ function getAppOriginClientConfigScript() {
|
|
|
1764
1772
|
...(workspaceAppMountConfig?.paths
|
|
1765
1773
|
? { workspaceAppMountPaths: workspaceAppMountConfig.paths }
|
|
1766
1774
|
: {}),
|
|
1775
|
+
...(explicitRootPath ? { explicitRootPath: true } : {}),
|
|
1776
|
+
...(frameworkRoutePrefix ? { frameworkRoutePrefix } : {}),
|
|
1767
1777
|
};
|
|
1768
1778
|
const toUnicodeEscape = (character) =>
|
|
1769
1779
|
String.fromCharCode(92) +
|
package/dist/mcp/embed-app.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MCP_APP_CHAT_BRIDGE_QUERY_PARAM } from "../shared/embed-auth.js";
|
|
2
2
|
import { MCP_APP_HOST_FILL_ATTRIBUTE, MCP_APP_PANE_FILL_MAX_HEIGHT, } from "../shared/mcp-app-display.js";
|
|
3
|
+
import { EMBED_TOKEN_STORAGE_KEY, MCP_CHAT_BRIDGE_STORAGE_KEY, resolveMcpAppEmbedBasePath, } from "../shared/mcp-app-widget-embed.js";
|
|
3
4
|
import { EXTERNAL_EMBED_WINDOW_KEY } from "../shared/route-chunk-recovery-bootstrap.js";
|
|
4
5
|
import { HIDDEN_EMBED_URL } from "./embed-redaction.js";
|
|
5
6
|
const MCP_APP_IMPORT = "https://esm.sh/@modelcontextprotocol/ext-apps@1.7.5/app-with-deps";
|
|
@@ -656,7 +657,28 @@ export function embedApp(options = {}) {
|
|
|
656
657
|
);
|
|
657
658
|
}
|
|
658
659
|
|
|
659
|
-
function
|
|
660
|
+
function appOriginConfigForDocument(parsed) {
|
|
661
|
+
const script = parsed.querySelector("script[data-agent-native-app-origin-config]");
|
|
662
|
+
if (!script) return {};
|
|
663
|
+
const source = script.textContent || "";
|
|
664
|
+
const prefix = "window.__AGENT_NATIVE_CONFIG__=Object.assign({},window.__AGENT_NATIVE_CONFIG__,";
|
|
665
|
+
const suffix = ");";
|
|
666
|
+
if (!source.startsWith(prefix) || !source.endsWith(suffix)) {
|
|
667
|
+
throw new Error("Embedded app origin config is malformed.");
|
|
668
|
+
}
|
|
669
|
+
let appConfig;
|
|
670
|
+
try {
|
|
671
|
+
appConfig = JSON.parse(source.slice(prefix.length, -suffix.length));
|
|
672
|
+
} catch (_err) {
|
|
673
|
+
throw new Error("Embedded app origin config is not valid JSON.");
|
|
674
|
+
}
|
|
675
|
+
if (!appConfig || typeof appConfig !== "object" || Array.isArray(appConfig)) {
|
|
676
|
+
throw new Error("Embedded app origin config must be an object.");
|
|
677
|
+
}
|
|
678
|
+
return appConfig;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function embedConfigForAppUrl(appUrl, appConfig) {
|
|
660
682
|
const sanitizedTarget = localPathFromUrl(appUrl, false);
|
|
661
683
|
return {
|
|
662
684
|
origin: appUrl.origin,
|
|
@@ -667,7 +689,8 @@ export function embedApp(options = {}) {
|
|
|
667
689
|
chatBridgeActive: appUrl.searchParams.get(chatBridgeParam) === "1",
|
|
668
690
|
chatBridgeParam,
|
|
669
691
|
embedTokenParam: "__an_embed_token",
|
|
670
|
-
embedTargetHeader: "x-agent-native-embed-target"
|
|
692
|
+
embedTargetHeader: "x-agent-native-embed-target",
|
|
693
|
+
appConfig
|
|
671
694
|
};
|
|
672
695
|
}
|
|
673
696
|
|
|
@@ -736,27 +759,108 @@ export function embedApp(options = {}) {
|
|
|
736
759
|
window.history.replaceState(window.history.state, "", config.target);
|
|
737
760
|
}
|
|
738
761
|
} catch (_err) {}
|
|
762
|
+
// Keep transplanted auth storage on the same mount resolver as its reader.
|
|
763
|
+
var resolveMcpAppEmbedBasePath = ${resolveMcpAppEmbedBasePath.toString()};
|
|
764
|
+
function activeConfig() {
|
|
765
|
+
return window[${JSON.stringify(EXTERNAL_EMBED_WINDOW_KEY)}] || config;
|
|
766
|
+
}
|
|
767
|
+
function workspaceMountOptions(active) {
|
|
768
|
+
var appConfig = active.appConfig || {};
|
|
769
|
+
return {
|
|
770
|
+
workspaceRuntime: true,
|
|
771
|
+
routerBasePath: window.__reactRouterContext && window.__reactRouterContext.basename,
|
|
772
|
+
workspaceAppPath: appConfig.workspaceAppPath,
|
|
773
|
+
workspaceAppMountPaths: appConfig.workspaceAppMountPaths,
|
|
774
|
+
explicitRootPath: appConfig.explicitRootPath === true,
|
|
775
|
+
frameworkRoutePrefix: appConfig.frameworkRoutePrefix
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
function embedStorageKey(key) {
|
|
779
|
+
var active = activeConfig();
|
|
780
|
+
var appConfig = active.appConfig || {};
|
|
781
|
+
if (appConfig.workspaceRuntime !== true) return key;
|
|
782
|
+
var basePath = resolveMcpAppEmbedBasePath(
|
|
783
|
+
"external-target",
|
|
784
|
+
active.target || location.pathname,
|
|
785
|
+
workspaceMountOptions(active)
|
|
786
|
+
);
|
|
787
|
+
if (typeof basePath !== "string") return undefined;
|
|
788
|
+
return key + ":" + (basePath || "/");
|
|
789
|
+
}
|
|
739
790
|
try {
|
|
740
791
|
if (config.token) {
|
|
741
|
-
|
|
792
|
+
var tokenStorageKey = embedStorageKey(${JSON.stringify(EMBED_TOKEN_STORAGE_KEY)});
|
|
793
|
+
if (tokenStorageKey) sessionStorage.setItem(tokenStorageKey, config.token);
|
|
742
794
|
}
|
|
743
795
|
if (config.chatBridgeActive && config.token) {
|
|
744
|
-
|
|
796
|
+
var bridgeStorageKey = embedStorageKey(${JSON.stringify(MCP_CHAT_BRIDGE_STORAGE_KEY)});
|
|
797
|
+
if (bridgeStorageKey) sessionStorage.setItem(bridgeStorageKey, config.token);
|
|
745
798
|
}
|
|
746
799
|
} catch (_err) {}
|
|
747
800
|
if (window.__agentNativeExternalEmbedRuntimeInstalled) return;
|
|
748
801
|
window.__agentNativeExternalEmbedRuntimeInstalled = true;
|
|
749
802
|
function appOrigin() {
|
|
750
803
|
try {
|
|
751
|
-
return new URL(
|
|
804
|
+
return new URL(activeConfig().origin).origin;
|
|
752
805
|
} catch (_err) {
|
|
753
806
|
return "";
|
|
754
807
|
}
|
|
755
808
|
}
|
|
756
809
|
function targetPath() {
|
|
757
|
-
|
|
810
|
+
var active = activeConfig();
|
|
811
|
+
return active.target || location.pathname + location.search;
|
|
812
|
+
}
|
|
813
|
+
function authorizedTargetPath() {
|
|
814
|
+
var active = activeConfig();
|
|
815
|
+
var appConfig = active.appConfig || {};
|
|
816
|
+
var target = targetPath();
|
|
817
|
+
if (appConfig.workspaceRuntime !== true) return target;
|
|
818
|
+
var options = workspaceMountOptions(active);
|
|
819
|
+
var targetMount = resolveMcpAppEmbedBasePath(
|
|
820
|
+
"external-target",
|
|
821
|
+
active.target || location.pathname,
|
|
822
|
+
options
|
|
823
|
+
);
|
|
824
|
+
var currentMount = resolveMcpAppEmbedBasePath(
|
|
825
|
+
"workspace-path",
|
|
826
|
+
location.pathname,
|
|
827
|
+
Object.assign({}, options, { preferDeclaredMounts: true })
|
|
828
|
+
);
|
|
829
|
+
if (typeof targetMount !== "string" || targetMount !== currentMount) {
|
|
830
|
+
return null;
|
|
831
|
+
}
|
|
832
|
+
return target;
|
|
833
|
+
}
|
|
834
|
+
function requestBelongsToTargetMount(value, target) {
|
|
835
|
+
var active = activeConfig();
|
|
836
|
+
var appConfig = active.appConfig || {};
|
|
837
|
+
if (appConfig.workspaceRuntime !== true) return true;
|
|
838
|
+
var options = workspaceMountOptions(active);
|
|
839
|
+
var targetMount = resolveMcpAppEmbedBasePath(
|
|
840
|
+
"external-target",
|
|
841
|
+
target,
|
|
842
|
+
options
|
|
843
|
+
);
|
|
844
|
+
if (typeof targetMount !== "string") return false;
|
|
845
|
+
var parsedUrl;
|
|
846
|
+
try {
|
|
847
|
+
parsedUrl = { url: new URL(value, location.href) };
|
|
848
|
+
} catch (error) {
|
|
849
|
+
parsedUrl = { error: error };
|
|
850
|
+
}
|
|
851
|
+
if (!("url" in parsedUrl)) return false;
|
|
852
|
+
var url = parsedUrl.url;
|
|
853
|
+
const origin = appOrigin();
|
|
854
|
+
if (url.origin !== location.origin && url.origin !== origin) return false;
|
|
855
|
+
var requestMount = resolveMcpAppEmbedBasePath(
|
|
856
|
+
"workspace-path",
|
|
857
|
+
url.pathname,
|
|
858
|
+
Object.assign({}, options, { preferDeclaredMounts: true })
|
|
859
|
+
);
|
|
860
|
+
return typeof requestMount === "string" && requestMount === targetMount;
|
|
758
861
|
}
|
|
759
862
|
function rewrittenUrl(value, appendToken) {
|
|
863
|
+
var active = activeConfig();
|
|
760
864
|
const origin = appOrigin();
|
|
761
865
|
if (!origin) return null;
|
|
762
866
|
let url;
|
|
@@ -771,20 +875,49 @@ export function embedApp(options = {}) {
|
|
|
771
875
|
url.protocol = app.protocol;
|
|
772
876
|
url.host = app.host;
|
|
773
877
|
}
|
|
774
|
-
|
|
775
|
-
|
|
878
|
+
const appConfig = active.appConfig || {};
|
|
879
|
+
var frameworkRoutePrefix = appConfig.frameworkRoutePrefix || "/_agent-native";
|
|
880
|
+
if (frameworkRoutePrefix.endsWith("/")) {
|
|
881
|
+
frameworkRoutePrefix = frameworkRoutePrefix.slice(0, -1);
|
|
882
|
+
}
|
|
883
|
+
const eventsPath = frameworkRoutePrefix + "/events";
|
|
884
|
+
const authorizedTarget = authorizedTargetPath();
|
|
885
|
+
if (
|
|
886
|
+
appendToken &&
|
|
887
|
+
authorizedTarget !== null &&
|
|
888
|
+
requestBelongsToTargetMount(value, authorizedTarget) &&
|
|
889
|
+
active.token &&
|
|
890
|
+
url.pathname.endsWith(eventsPath)
|
|
891
|
+
) {
|
|
892
|
+
url.searchParams.set(active.embedTokenParam, active.token);
|
|
776
893
|
}
|
|
777
894
|
return url.toString();
|
|
778
895
|
}
|
|
779
896
|
function authHeaders(input, init) {
|
|
897
|
+
var active = activeConfig();
|
|
898
|
+
var authorizedTarget = authorizedTargetPath();
|
|
899
|
+
var requestUrl = input instanceof Request ? input.url : input;
|
|
900
|
+
if (
|
|
901
|
+
authorizedTarget !== null &&
|
|
902
|
+
!requestBelongsToTargetMount(requestUrl, authorizedTarget)
|
|
903
|
+
) {
|
|
904
|
+
authorizedTarget = null;
|
|
905
|
+
}
|
|
780
906
|
const headers = new Headers(
|
|
781
907
|
init && init.headers ? init.headers : input instanceof Request ? input.headers : undefined
|
|
782
908
|
);
|
|
783
|
-
if (
|
|
784
|
-
|
|
909
|
+
if (
|
|
910
|
+
authorizedTarget !== null &&
|
|
911
|
+
active.token &&
|
|
912
|
+
!headers.has("Authorization")
|
|
913
|
+
) {
|
|
914
|
+
headers.set("Authorization", "Bearer " + active.token);
|
|
785
915
|
}
|
|
786
|
-
if (
|
|
787
|
-
|
|
916
|
+
if (
|
|
917
|
+
authorizedTarget !== null &&
|
|
918
|
+
!headers.has(active.embedTargetHeader)
|
|
919
|
+
) {
|
|
920
|
+
headers.set(active.embedTargetHeader, authorizedTarget);
|
|
788
921
|
}
|
|
789
922
|
return headers;
|
|
790
923
|
}
|
|
@@ -810,6 +943,7 @@ export function embedApp(options = {}) {
|
|
|
810
943
|
XMLHttpRequest.prototype.open = function(method, url) {
|
|
811
944
|
const rewritten = rewrittenUrl(url, false);
|
|
812
945
|
this.__agentNativeExternalEmbed = !!rewritten;
|
|
946
|
+
this.__agentNativeExternalEmbedUrl = url;
|
|
813
947
|
return originalOpen.call(
|
|
814
948
|
this,
|
|
815
949
|
method,
|
|
@@ -822,8 +956,20 @@ export function embedApp(options = {}) {
|
|
|
822
956
|
XMLHttpRequest.prototype.send = function(body) {
|
|
823
957
|
if (this.__agentNativeExternalEmbed) {
|
|
824
958
|
try {
|
|
825
|
-
|
|
826
|
-
|
|
959
|
+
var active = activeConfig();
|
|
960
|
+
var authorizedTarget = authorizedTargetPath();
|
|
961
|
+
if (
|
|
962
|
+
authorizedTarget !== null &&
|
|
963
|
+
requestBelongsToTargetMount(
|
|
964
|
+
this.__agentNativeExternalEmbedUrl,
|
|
965
|
+
authorizedTarget
|
|
966
|
+
)
|
|
967
|
+
) {
|
|
968
|
+
if (active.token) {
|
|
969
|
+
this.setRequestHeader("Authorization", "Bearer " + active.token);
|
|
970
|
+
}
|
|
971
|
+
this.setRequestHeader(active.embedTargetHeader, authorizedTarget);
|
|
972
|
+
}
|
|
827
973
|
} catch (_err) {}
|
|
828
974
|
}
|
|
829
975
|
return originalSend.call(this, body);
|
|
@@ -1056,12 +1202,15 @@ export function embedApp(options = {}) {
|
|
|
1056
1202
|
}
|
|
1057
1203
|
|
|
1058
1204
|
async function mountTransplantedHtml(html, appUrl) {
|
|
1059
|
-
const config = embedConfigForAppUrl(appUrl);
|
|
1060
|
-
installExternalEmbedRuntime(config);
|
|
1061
1205
|
const parsed = new DOMParser().parseFromString(
|
|
1062
1206
|
rewriteRootRelativeHtmlUrls(removeHtmlCspMeta(html), appUrl.origin),
|
|
1063
1207
|
"text/html"
|
|
1064
1208
|
);
|
|
1209
|
+
const config = embedConfigForAppUrl(
|
|
1210
|
+
appUrl,
|
|
1211
|
+
appOriginConfigForDocument(parsed)
|
|
1212
|
+
);
|
|
1213
|
+
installExternalEmbedRuntime(config);
|
|
1065
1214
|
const scripts = Array.from(parsed.querySelectorAll("script"));
|
|
1066
1215
|
copyDocumentElementAttributes(parsed.documentElement);
|
|
1067
1216
|
importHeadChildrenWithBase(parsed.head, config.baseHref);
|
|
@@ -76,8 +76,8 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
|
|
|
76
76
|
}>>;
|
|
77
77
|
}, z.core.$strip>>, {
|
|
78
78
|
id?: undefined;
|
|
79
|
-
deleted?: undefined;
|
|
80
79
|
provider?: undefined;
|
|
80
|
+
deleted?: undefined;
|
|
81
81
|
message?: undefined;
|
|
82
82
|
providers: {
|
|
83
83
|
id: string;
|
|
@@ -103,8 +103,8 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
|
|
|
103
103
|
registered?: undefined;
|
|
104
104
|
label?: undefined;
|
|
105
105
|
} | {
|
|
106
|
-
deleted?: undefined;
|
|
107
106
|
provider?: undefined;
|
|
107
|
+
deleted?: undefined;
|
|
108
108
|
count?: undefined;
|
|
109
109
|
message?: undefined;
|
|
110
110
|
providers?: undefined;
|
|
@@ -123,8 +123,8 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
|
|
|
123
123
|
registered?: undefined;
|
|
124
124
|
label?: undefined;
|
|
125
125
|
} | {
|
|
126
|
-
deleted?: undefined;
|
|
127
126
|
provider?: undefined;
|
|
127
|
+
deleted?: undefined;
|
|
128
128
|
count?: undefined;
|
|
129
129
|
providers?: undefined;
|
|
130
130
|
found?: undefined;
|
|
@@ -316,6 +316,7 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
|
|
|
316
316
|
notes?: string | undefined;
|
|
317
317
|
scope?: "org" | "user" | undefined;
|
|
318
318
|
}, {
|
|
319
|
+
message?: undefined;
|
|
319
320
|
deleted?: undefined;
|
|
320
321
|
id?: undefined;
|
|
321
322
|
providers: {
|
|
@@ -332,8 +333,8 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
|
|
|
332
333
|
found?: undefined;
|
|
333
334
|
registered?: undefined;
|
|
334
335
|
label?: undefined;
|
|
335
|
-
message?: undefined;
|
|
336
336
|
} | {
|
|
337
|
+
message?: undefined;
|
|
337
338
|
deleted?: undefined;
|
|
338
339
|
id?: undefined;
|
|
339
340
|
providers?: undefined;
|
|
@@ -342,8 +343,8 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
|
|
|
342
343
|
provider: import("../custom-registry.js").CustomProviderConfig;
|
|
343
344
|
registered?: undefined;
|
|
344
345
|
label?: undefined;
|
|
345
|
-
message?: undefined;
|
|
346
346
|
} | {
|
|
347
|
+
message?: undefined;
|
|
347
348
|
deleted?: undefined;
|
|
348
349
|
providers?: undefined;
|
|
349
350
|
count?: undefined;
|
|
@@ -352,8 +353,8 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
|
|
|
352
353
|
id: string;
|
|
353
354
|
registered?: undefined;
|
|
354
355
|
label?: undefined;
|
|
355
|
-
message?: undefined;
|
|
356
356
|
} | {
|
|
357
|
+
message?: undefined;
|
|
357
358
|
providers?: undefined;
|
|
358
359
|
count?: undefined;
|
|
359
360
|
provider?: undefined;
|
|
@@ -362,7 +363,6 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
|
|
|
362
363
|
id: string;
|
|
363
364
|
registered?: undefined;
|
|
364
365
|
label?: undefined;
|
|
365
|
-
message?: undefined;
|
|
366
366
|
} | {
|
|
367
367
|
deleted?: undefined;
|
|
368
368
|
providers?: undefined;
|
|
@@ -8,5 +8,7 @@ export declare function resolvePublicAppOriginConfig(): {
|
|
|
8
8
|
workspaceOAuthOrigin?: string;
|
|
9
9
|
workspaceRuntime?: boolean;
|
|
10
10
|
workspaceAppMountPaths?: string[];
|
|
11
|
+
frameworkRoutePrefix?: string;
|
|
12
|
+
explicitRootPath?: boolean;
|
|
11
13
|
} | null;
|
|
12
14
|
export declare function getAppOriginClientConfigScript(): string | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getAppConfig, resolveAppHomePath } from "../app-config/index.js";
|
|
2
2
|
import { safeJsonForHtml } from "../shared/agent-readable-resource.js";
|
|
3
3
|
import { normalizeAppBasePath } from "./app-base-path.js";
|
|
4
|
+
import { FRAMEWORK_INTERNAL_ROUTE_PREFIX, getFrameworkRoutePrefix, } from "./framework-route-prefix.js";
|
|
4
5
|
function workspaceAppMountConfigFromJson(value, workspaceAppId) {
|
|
5
6
|
if (!value?.trim())
|
|
6
7
|
return undefined;
|
|
@@ -50,6 +51,7 @@ function workspaceAppMountConfigFromJson(value, workspaceAppId) {
|
|
|
50
51
|
}
|
|
51
52
|
export function resolvePublicAppOriginConfig() {
|
|
52
53
|
const config = getAppConfig();
|
|
54
|
+
const frameworkRoutePrefix = getFrameworkRoutePrefix();
|
|
53
55
|
const workspaceRuntime = config.workspace.isWorkspace === true ||
|
|
54
56
|
typeof config.workspace.appsJson === "string";
|
|
55
57
|
const workspaceAppMountConfig = workspaceAppMountConfigFromJson(config.workspace.appsJson, config.app.workspaceId);
|
|
@@ -58,6 +60,10 @@ export function resolvePublicAppOriginConfig() {
|
|
|
58
60
|
: undefined;
|
|
59
61
|
const workspaceAppPath = workspaceAppMountConfig?.currentPath ??
|
|
60
62
|
(workspaceRuntime ? configuredWorkspaceAppPath : undefined);
|
|
63
|
+
const explicitRootPath = workspaceAppMountConfig?.currentPath === "/" ||
|
|
64
|
+
(typeof config.app.basePath === "string" &&
|
|
65
|
+
config.app.basePath.trim().length > 0 &&
|
|
66
|
+
normalizeAppBasePath(config.app.basePath) === "");
|
|
61
67
|
const resolved = {
|
|
62
68
|
...(config.app.id ? { appId: config.app.id } : {}),
|
|
63
69
|
...(config.app.workspaceId
|
|
@@ -76,6 +82,10 @@ export function resolvePublicAppOriginConfig() {
|
|
|
76
82
|
...(workspaceAppMountConfig?.paths
|
|
77
83
|
? { workspaceAppMountPaths: workspaceAppMountConfig.paths }
|
|
78
84
|
: {}),
|
|
85
|
+
...(explicitRootPath ? { explicitRootPath: true } : {}),
|
|
86
|
+
...(frameworkRoutePrefix !== FRAMEWORK_INTERNAL_ROUTE_PREFIX
|
|
87
|
+
? { frameworkRoutePrefix }
|
|
88
|
+
: {}),
|
|
79
89
|
};
|
|
80
90
|
return Object.keys(resolved).length > 0 ? resolved : null;
|
|
81
91
|
}
|
package/dist/server/auth.d.ts
CHANGED
|
@@ -38,8 +38,34 @@ export interface AuthOptions {
|
|
|
38
38
|
*/
|
|
39
39
|
getBrowserSession?: (event: H3Event) => Promise<AuthSession | null>;
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* An extra identity source, consulted before the built-in sessions. Unlike
|
|
42
|
+
* `getSession`, it does not replace them: a request it does not recognize
|
|
43
|
+
* (returns `null`) resolves exactly as it would without it, and the built-in
|
|
44
|
+
* sign-in routes stay mounted. Use it to let a host product vouch for its
|
|
45
|
+
* own users on a deployment that also serves everyone else. If it throws, the
|
|
46
|
+
* request is refused as session-unavailable (503) rather than falling
|
|
47
|
+
* through, so a browser holding two identities cannot silently become the
|
|
48
|
+
* other one. Ignored when `getSession` is set, which already takes over every
|
|
49
|
+
* session.
|
|
50
|
+
*/
|
|
51
|
+
getAdditionalSession?: (event: H3Event) => Promise<AuthSession | null>;
|
|
52
|
+
/**
|
|
53
|
+
* The cookie-only counterpart of `getAdditionalSession`, for browser UI
|
|
54
|
+
* capabilities and approvals. Never accept bearer tokens, query tokens, or
|
|
55
|
+
* other request headers here.
|
|
56
|
+
*/
|
|
57
|
+
getAdditionalBrowserSession?: (event: H3Event) => Promise<AuthSession | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Called on sign-out to end the additional provider's own session (clear its
|
|
60
|
+
* cookie, drop any server-side state), which the built-in sign-out knows
|
|
61
|
+
* nothing about. Without it a user would still resolve as signed in on the
|
|
62
|
+
* next request.
|
|
63
|
+
*/
|
|
64
|
+
clearAdditionalSession?: (event: H3Event) => void | Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Set only when the custom provider (`getSession` or
|
|
67
|
+
* `getAdditionalSession`) independently verifies email ownership. Without
|
|
68
|
+
* this opt-in, an omitted `emailVerified` value remains unknown.
|
|
43
69
|
*/
|
|
44
70
|
trustCustomEmailVerification?: boolean;
|
|
45
71
|
publicPaths?: string[];
|
package/dist/server/auth.js
CHANGED
|
@@ -1572,6 +1572,17 @@ async function performLogout(event, getAuth) {
|
|
|
1572
1572
|
clearIdentityGoogleAuthCookie(event);
|
|
1573
1573
|
clearFirstRunOnboardingCookie(event);
|
|
1574
1574
|
optOutOfAuthDisabledSession(event);
|
|
1575
|
+
if (additionalClearSession) {
|
|
1576
|
+
try {
|
|
1577
|
+
await additionalClearSession(event);
|
|
1578
|
+
}
|
|
1579
|
+
catch (error) {
|
|
1580
|
+
// The user would still resolve as signed in through the additional
|
|
1581
|
+
// provider, so sign-out has not worked.
|
|
1582
|
+
revocationFailed = true;
|
|
1583
|
+
captureAuthError(error, { route: "logout" });
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1575
1586
|
if (auth) {
|
|
1576
1587
|
try {
|
|
1577
1588
|
const result = await auth.api.signOut({
|
|
@@ -1700,6 +1711,9 @@ async function mapLegacySession(email, token) {
|
|
|
1700
1711
|
}
|
|
1701
1712
|
let customGetSession = null;
|
|
1702
1713
|
let customGetBrowserSession = null;
|
|
1714
|
+
let additionalGetSession = null;
|
|
1715
|
+
let additionalGetBrowserSession = null;
|
|
1716
|
+
let additionalClearSession = null;
|
|
1703
1717
|
let warnedMissingBrowserSession = false;
|
|
1704
1718
|
let trustCustomEmailVerification = false;
|
|
1705
1719
|
let _authGuardConfig = null;
|
|
@@ -3575,7 +3589,38 @@ export function getBrowserSessionConfigurationError() {
|
|
|
3575
3589
|
}
|
|
3576
3590
|
return undefined;
|
|
3577
3591
|
}
|
|
3592
|
+
/** The additional provider could not answer; the request must not resolve at all. */
|
|
3593
|
+
const ADDITIONAL_SESSION_FAILED = Symbol("additional-session-failed");
|
|
3594
|
+
/**
|
|
3595
|
+
* The additional provider's verdict: a session, null to fall through to the
|
|
3596
|
+
* built-in sessions, or a failure. A provider that cannot answer (a store
|
|
3597
|
+
* outage, unreadable state) is not "no session": falling through would let a
|
|
3598
|
+
* browser holding two identities silently become the other one, so the
|
|
3599
|
+
* request is marked unavailable (503) instead.
|
|
3600
|
+
*/
|
|
3601
|
+
async function resolveAdditionalSession(event, resolve) {
|
|
3602
|
+
if (!resolve || customGetSession)
|
|
3603
|
+
return null;
|
|
3604
|
+
try {
|
|
3605
|
+
const session = await resolve(event);
|
|
3606
|
+
return session ? normalizeCustomSession(session) : null;
|
|
3607
|
+
}
|
|
3608
|
+
catch (error) {
|
|
3609
|
+
markSessionResolutionUnavailable(event, "additional-session", error);
|
|
3610
|
+
return ADDITIONAL_SESSION_FAILED;
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
function hasBearerAuthorization(event) {
|
|
3614
|
+
return /^bearer\s/i.test(getHeader(event, "authorization") ?? "");
|
|
3615
|
+
}
|
|
3578
3616
|
async function resolveBrowserCookieSession(event) {
|
|
3617
|
+
if (additionalGetBrowserSession && getHeader(event, "cookie")) {
|
|
3618
|
+
const additional = await resolveAdditionalSession(event, additionalGetBrowserSession);
|
|
3619
|
+
if (additional === ADDITIONAL_SESSION_FAILED)
|
|
3620
|
+
return null;
|
|
3621
|
+
if (additional)
|
|
3622
|
+
return additional;
|
|
3623
|
+
}
|
|
3579
3624
|
if (customGetSession) {
|
|
3580
3625
|
if (!customGetBrowserSession) {
|
|
3581
3626
|
if (!warnedMissingBrowserSession) {
|
|
@@ -3632,6 +3677,17 @@ async function resolveSessionUncached(event, options = {}) {
|
|
|
3632
3677
|
};
|
|
3633
3678
|
}
|
|
3634
3679
|
}
|
|
3680
|
+
// First, like the browser-cookie resolver, so a request carrying both an
|
|
3681
|
+
// additional-provider session and a legacy cookie resolves to the same owner
|
|
3682
|
+
// in every check. Not when the request names an explicit bearer credential:
|
|
3683
|
+
// that is the caller's choice and wins over a cookie.
|
|
3684
|
+
const additionalSession = hasBearerAuthorization(event)
|
|
3685
|
+
? null
|
|
3686
|
+
: await resolveAdditionalSession(event, additionalGetSession);
|
|
3687
|
+
if (additionalSession === ADDITIONAL_SESSION_FAILED)
|
|
3688
|
+
return null;
|
|
3689
|
+
if (additionalSession)
|
|
3690
|
+
return additionalSession;
|
|
3635
3691
|
const accessTokens = getAccessTokens();
|
|
3636
3692
|
if (accessTokens.length > 0) {
|
|
3637
3693
|
const cookieSession = await getLegacyCookieSessionSafely(event);
|
|
@@ -5481,6 +5537,9 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
5481
5537
|
});
|
|
5482
5538
|
}
|
|
5483
5539
|
});
|
|
5540
|
+
// The additional provider's own session ends with the rest.
|
|
5541
|
+
if (additionalClearSession)
|
|
5542
|
+
await additionalClearSession(event);
|
|
5484
5543
|
clearFrameworkSessionCookies(event);
|
|
5485
5544
|
clearFirstRunOnboardingCookie(event);
|
|
5486
5545
|
optOutOfAuthDisabledSession(event);
|
|
@@ -5660,6 +5719,13 @@ export async function autoMountAuth(app, options = {}) {
|
|
|
5660
5719
|
trustCustomEmailVerification =
|
|
5661
5720
|
options.trustCustomEmailVerification === true;
|
|
5662
5721
|
}
|
|
5722
|
+
if (options.getAdditionalSession) {
|
|
5723
|
+
additionalGetSession = options.getAdditionalSession;
|
|
5724
|
+
additionalGetBrowserSession = options.getAdditionalBrowserSession ?? null;
|
|
5725
|
+
additionalClearSession = options.clearAdditionalSession ?? null;
|
|
5726
|
+
trustCustomEmailVerification =
|
|
5727
|
+
options.trustCustomEmailVerification === true;
|
|
5728
|
+
}
|
|
5663
5729
|
if (_authGuardConfig) {
|
|
5664
5730
|
if (options.googleOnly ||
|
|
5665
5731
|
options.loginHtml ||
|
|
@@ -5716,6 +5782,9 @@ export async function autoMountAuth(app, options = {}) {
|
|
|
5716
5782
|
if (isDevEnvironment()) {
|
|
5717
5783
|
customGetSession = null;
|
|
5718
5784
|
customGetBrowserSession = null;
|
|
5785
|
+
additionalGetSession = null;
|
|
5786
|
+
additionalGetBrowserSession = null;
|
|
5787
|
+
additionalClearSession = null;
|
|
5719
5788
|
trustCustomEmailVerification = false;
|
|
5720
5789
|
return false;
|
|
5721
5790
|
}
|
|
@@ -5723,6 +5792,9 @@ export async function autoMountAuth(app, options = {}) {
|
|
|
5723
5792
|
}
|
|
5724
5793
|
customGetSession = null;
|
|
5725
5794
|
customGetBrowserSession = null;
|
|
5795
|
+
additionalGetSession = null;
|
|
5796
|
+
additionalGetBrowserSession = null;
|
|
5797
|
+
additionalClearSession = null;
|
|
5726
5798
|
trustCustomEmailVerification = false;
|
|
5727
5799
|
sessionMaxAge = options.maxAge ?? DEFAULT_MAX_AGE;
|
|
5728
5800
|
const publicPaths = resolveAuthPublicPaths(options.publicPaths);
|
|
@@ -5743,6 +5815,13 @@ export async function autoMountAuth(app, options = {}) {
|
|
|
5743
5815
|
trustCustomEmailVerification =
|
|
5744
5816
|
options.trustCustomEmailVerification === true;
|
|
5745
5817
|
}
|
|
5818
|
+
else if (options.getAdditionalSession) {
|
|
5819
|
+
additionalGetSession = options.getAdditionalSession;
|
|
5820
|
+
additionalGetBrowserSession = options.getAdditionalBrowserSession ?? null;
|
|
5821
|
+
additionalClearSession = options.clearAdditionalSession ?? null;
|
|
5822
|
+
trustCustomEmailVerification =
|
|
5823
|
+
options.trustCustomEmailVerification === true;
|
|
5824
|
+
}
|
|
5746
5825
|
if (customGetSession) {
|
|
5747
5826
|
app.use("/_agent-native/auth/session", authSessionHandler);
|
|
5748
5827
|
app.use("/_agent-native/auth/login", defineEventHandler(() => ({ ok: true })));
|
|
@@ -76,7 +76,23 @@ export interface DelegatedBuilderCredentials {
|
|
|
76
76
|
spaceId: string;
|
|
77
77
|
userId?: string;
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
/**
|
|
80
|
+
* What a host's provider says about a user:
|
|
81
|
+
* - credentials: the caller's own Builder credential, used for every Builder
|
|
82
|
+
* feature;
|
|
83
|
+
* - `null`: not a host-managed user, so ordinary stored credentials apply;
|
|
84
|
+
* - `"none"`: a host-managed user with no usable credential right now (it
|
|
85
|
+
* expired, or was never exchanged). Lookup stops: a shared or stored
|
|
86
|
+
* credential must never stand in for the user's own, and the host asks them
|
|
87
|
+
* to sign in again.
|
|
88
|
+
* A provider that throws is an outage, reported as a failed lookup rather than
|
|
89
|
+
* as the absence of a credential.
|
|
90
|
+
* It may answer asynchronously, so a host on serverless can keep the
|
|
91
|
+
* credential in shared storage rather than per-instance memory.
|
|
92
|
+
*/
|
|
93
|
+
export type DelegatedBuilderCredentialsResult = DelegatedBuilderCredentials | null | "none";
|
|
94
|
+
type DelegatedBuilderCredentialsProvider = (email: string) => DelegatedBuilderCredentialsResult | Promise<DelegatedBuilderCredentialsResult>;
|
|
95
|
+
export declare function registerDelegatedBuilderCredentials(provider: DelegatedBuilderCredentialsProvider | null): void;
|
|
80
96
|
export interface BuilderCredentialLookupIdentity {
|
|
81
97
|
userEmail?: string | null;
|
|
82
98
|
orgId?: string | null;
|
|
@@ -110,6 +126,8 @@ export interface BuilderCredentialsDetailed {
|
|
|
110
126
|
/** Optional Builder profile metadata failed after the required key pair was read. */
|
|
111
127
|
optionalMetadataLookupFailure?: "unreadable" | "unavailable";
|
|
112
128
|
cause?: unknown;
|
|
129
|
+
/** A host-managed user with no credential: no fallback may stand in. */
|
|
130
|
+
hostManagedWithoutCredential?: boolean;
|
|
113
131
|
}
|
|
114
132
|
export declare function resolveBuilderCredentialsDetailed(identity?: BuilderCredentialLookupIdentity): Promise<BuilderCredentialsDetailed>;
|
|
115
133
|
export declare function resolveBuilderCredentials(identity?: BuilderCredentialLookupIdentity): Promise<{
|