@agent-native/dispatch 0.40.40 → 0.40.41-beta-embedded-chat-20261025-20261025150325
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/CHANGELOG.md +31 -0
- package/dist/actions/create-workspace-resource.d.ts +13 -13
- package/dist/actions/delete-workspace-resource.d.ts +13 -13
- package/dist/actions/import-agent.d.ts +13 -13
- package/dist/actions/provider-api-register.d.ts +11 -11
- package/dist/lib/workspace-apps.d.ts +1 -2
- package/dist/lib/workspace-apps.d.ts.map +1 -1
- package/dist/lib/workspace-apps.js +2 -3
- package/dist/lib/workspace-apps.js.map +1 -1
- package/dist/server/lib/app-creation-store.d.ts.map +1 -1
- package/dist/server/lib/app-creation-store.js +172 -47
- package/dist/server/lib/app-creation-store.js.map +1 -1
- package/dist/server/lib/mcp-gateway.d.ts +1 -0
- package/dist/server/lib/mcp-gateway.d.ts.map +1 -1
- package/dist/server/lib/mcp-gateway.js +59 -5
- package/dist/server/lib/mcp-gateway.js.map +1 -1
- package/dist/shared/workspace-app-route.d.ts +2 -0
- package/dist/shared/workspace-app-route.d.ts.map +1 -0
- package/dist/shared/workspace-app-route.js +4 -0
- package/dist/shared/workspace-app-route.js.map +1 -0
- package/package.json +4 -4
- package/src/lib/workspace-apps.ts +3 -4
- package/src/server/lib/app-creation-store.spec.ts +502 -11
- package/src/server/lib/app-creation-store.ts +197 -49
- package/src/server/lib/mcp-gateway.spec.ts +222 -0
- package/src/server/lib/mcp-gateway.ts +69 -4
- package/src/shared/workspace-app-route.ts +3 -0
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type A2APersistedMutationReceipt,
|
|
10
10
|
type Task,
|
|
11
11
|
} from "@agent-native/core/a2a";
|
|
12
|
+
import { getAppConfig } from "@agent-native/core/app-config";
|
|
12
13
|
import { isFeatureFlagEnabled } from "@agent-native/core/feature-flags";
|
|
13
14
|
import {
|
|
14
15
|
buildMcpToolName,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
buildDeepLink,
|
|
20
21
|
buildEmbedStartPath,
|
|
21
22
|
createEmbedSessionTicket,
|
|
23
|
+
getConfiguredAppBasePath,
|
|
22
24
|
getRequestContext,
|
|
23
25
|
getRequestOrgId,
|
|
24
26
|
getRequestUserEmail,
|
|
@@ -28,6 +30,7 @@ import {
|
|
|
28
30
|
getBuiltinAgents,
|
|
29
31
|
type DiscoveredAgent,
|
|
30
32
|
} from "@agent-native/core/server/agent-discovery";
|
|
33
|
+
import { EMBED_START_PATH } from "@agent-native/core/shared";
|
|
31
34
|
|
|
32
35
|
import { DESKTOP_WORKSPACE_SSO_FLAG } from "../../shared/feature-flags.js";
|
|
33
36
|
import {
|
|
@@ -79,6 +82,7 @@ export interface DispatchMcpAccessibleApp {
|
|
|
79
82
|
description: string;
|
|
80
83
|
url: string;
|
|
81
84
|
homeUrl?: string;
|
|
85
|
+
mcpUrl?: string;
|
|
82
86
|
color: string;
|
|
83
87
|
granted: boolean;
|
|
84
88
|
}
|
|
@@ -581,14 +585,73 @@ function appHomeBaseUrl(app: DispatchMcpAccessibleApp): string {
|
|
|
581
585
|
return appBaseUrl(app);
|
|
582
586
|
}
|
|
583
587
|
|
|
588
|
+
function workspaceGatewayMcpUrl(appUrl: string): string | undefined {
|
|
589
|
+
const configuredGateway = getAppConfig().workspace.gatewayUrl?.trim();
|
|
590
|
+
if (!configuredGateway) return undefined;
|
|
591
|
+
|
|
592
|
+
let configuredUrl: URL;
|
|
593
|
+
try {
|
|
594
|
+
configuredUrl = new URL(configuredGateway);
|
|
595
|
+
} catch {
|
|
596
|
+
throw new Error(
|
|
597
|
+
"WORKSPACE_GATEWAY_URL must be a valid absolute HTTP(S) URL.",
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
if (
|
|
601
|
+
configuredUrl.protocol !== "http:" &&
|
|
602
|
+
configuredUrl.protocol !== "https:"
|
|
603
|
+
) {
|
|
604
|
+
throw new Error("WORKSPACE_GATEWAY_URL must use http or https.");
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const gateway = new URL(projectEnvironmentUrl(configuredUrl.toString()));
|
|
608
|
+
if (gateway.protocol !== "http:" && gateway.protocol !== "https:") {
|
|
609
|
+
throw new Error("WORKSPACE_GATEWAY_URL must use http or https.");
|
|
610
|
+
}
|
|
611
|
+
const target = new URL(appUrl);
|
|
612
|
+
if (gateway.origin !== target.origin) return undefined;
|
|
613
|
+
const configuredBasePath = getConfiguredAppBasePath();
|
|
614
|
+
const gatewayPath = gateway.pathname.replace(/\/+$/, "");
|
|
615
|
+
const basePath =
|
|
616
|
+
configuredBasePath &&
|
|
617
|
+
gatewayPath !== configuredBasePath &&
|
|
618
|
+
!gatewayPath.startsWith(`${configuredBasePath}/`)
|
|
619
|
+
? `${configuredBasePath}${gatewayPath}`
|
|
620
|
+
: gatewayPath;
|
|
621
|
+
gateway.pathname = `${basePath}/mcp` || "/mcp";
|
|
622
|
+
gateway.search = "";
|
|
623
|
+
gateway.hash = "";
|
|
624
|
+
return gateway.toString().replace(/\/$/, "");
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function appMcpUrl(app: DispatchMcpAccessibleApp): string {
|
|
628
|
+
const explicit = app.mcpUrl?.trim();
|
|
629
|
+
return (
|
|
630
|
+
explicit?.replace(/\/+$/, "") ??
|
|
631
|
+
workspaceGatewayMcpUrl(app.url) ??
|
|
632
|
+
`${appHomeBaseUrl(app)}/mcp`
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function appMcpBaseUrl(app: DispatchMcpAccessibleApp): string {
|
|
637
|
+
const url = new URL(appMcpUrl(app));
|
|
638
|
+
url.pathname = url.pathname.replace(/\/mcp\/?$/, "") || "/";
|
|
639
|
+
url.search = "";
|
|
640
|
+
url.hash = "";
|
|
641
|
+
return url.toString().replace(/\/$/, "");
|
|
642
|
+
}
|
|
643
|
+
|
|
584
644
|
function resolveGrantedAppEmbedStartUrl(
|
|
585
645
|
app: DispatchMcpAccessibleApp,
|
|
586
646
|
startUrl: string,
|
|
587
647
|
): string {
|
|
588
648
|
try {
|
|
589
|
-
const baseUrl =
|
|
649
|
+
const baseUrl = appMcpBaseUrl(app);
|
|
590
650
|
const resolved = new URL(startUrl, `${baseUrl}/`);
|
|
591
|
-
|
|
651
|
+
const base = new URL(baseUrl);
|
|
652
|
+
const basePath = base.pathname.replace(/\/+$/, "");
|
|
653
|
+
const expectedPath = `${basePath}${EMBED_START_PATH}`;
|
|
654
|
+
if (resolved.origin !== base.origin || resolved.pathname !== expectedPath) {
|
|
592
655
|
throw new Error(
|
|
593
656
|
"Target app returned an embed start URL outside the granted app.",
|
|
594
657
|
);
|
|
@@ -763,11 +826,13 @@ async function listWorkspaceSsoApps(): Promise<DispatchMcpAccessibleApp[]> {
|
|
|
763
826
|
}
|
|
764
827
|
for (const app of mountedApps) {
|
|
765
828
|
if (app.isDispatch || !app.url) continue;
|
|
829
|
+
const mcpUrl = workspaceGatewayMcpUrl(app.url);
|
|
766
830
|
candidatesById.set(app.id, {
|
|
767
831
|
id: app.id,
|
|
768
832
|
name: app.name,
|
|
769
833
|
description: app.description,
|
|
770
834
|
url: app.url,
|
|
835
|
+
...(mcpUrl ? { mcpUrl } : {}),
|
|
771
836
|
color: DISPATCH_COLOR,
|
|
772
837
|
granted: true,
|
|
773
838
|
});
|
|
@@ -1152,7 +1217,7 @@ async function callTargetCreateEmbedSession(input: {
|
|
|
1152
1217
|
servers: {
|
|
1153
1218
|
[serverId]: {
|
|
1154
1219
|
type: "http",
|
|
1155
|
-
url:
|
|
1220
|
+
url: appMcpUrl(input.app),
|
|
1156
1221
|
headers: {
|
|
1157
1222
|
Authorization: `Bearer ${input.token}`,
|
|
1158
1223
|
},
|
|
@@ -1197,7 +1262,7 @@ async function createTargetMcpUserToken(input: {
|
|
|
1197
1262
|
"Cross-app embed sessions require A2A_SECRET to preserve the authenticated user identity; an organization-only A2A credential cannot create a user-owned session.",
|
|
1198
1263
|
);
|
|
1199
1264
|
}
|
|
1200
|
-
const audience = canonicalA2AAudience(
|
|
1265
|
+
const audience = canonicalA2AAudience(appMcpUrl(input.target));
|
|
1201
1266
|
return signA2AToken(input.ownerEmail, undefined, undefined, {
|
|
1202
1267
|
expiresIn: "5m",
|
|
1203
1268
|
audience,
|