@agent-native/dispatch 0.43.7 → 0.43.8

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +12 -8
  2. package/dist/actions/execute-action-suggestion.js +6 -3
  3. package/dist/actions/execute-action-suggestion.js.map +1 -1
  4. package/dist/components/workspace-app-host.d.ts.map +1 -1
  5. package/dist/components/workspace-app-host.js +17 -16
  6. package/dist/components/workspace-app-host.js.map +1 -1
  7. package/dist/lib/workspace-apps.d.ts +1 -1
  8. package/dist/lib/workspace-apps.d.ts.map +1 -1
  9. package/dist/lib/workspace-apps.js +16 -114
  10. package/dist/lib/workspace-apps.js.map +1 -1
  11. package/dist/lib/workspace-apps.test.js +7 -9
  12. package/dist/lib/workspace-apps.test.js.map +1 -1
  13. package/dist/server/lib/app-creation-store.d.ts.map +1 -1
  14. package/dist/server/lib/app-creation-store.js +38 -69
  15. package/dist/server/lib/app-creation-store.js.map +1 -1
  16. package/dist/server/lib/mcp-gateway.d.ts +1 -1
  17. package/dist/server/lib/mcp-gateway.d.ts.map +1 -1
  18. package/dist/server/lib/mcp-gateway.js +36 -93
  19. package/dist/server/lib/mcp-gateway.js.map +1 -1
  20. package/dist/shared/workspace-app-route.d.ts +0 -1
  21. package/dist/shared/workspace-app-route.d.ts.map +1 -1
  22. package/dist/shared/workspace-app-route.js +0 -3
  23. package/dist/shared/workspace-app-route.js.map +1 -1
  24. package/package.json +5 -5
  25. package/src/actions/action-suggestions.spec.ts +2 -1
  26. package/src/actions/execute-action-suggestion.ts +7 -5
  27. package/src/components/layout/workspace-apps-rail.spec.tsx +1 -1
  28. package/src/components/workspace-app-card.spec.tsx +4 -4
  29. package/src/components/workspace-app-host.spec.tsx +20 -16
  30. package/src/components/workspace-app-host.tsx +19 -16
  31. package/src/lib/workspace-apps.spec.ts +22 -30
  32. package/src/lib/workspace-apps.test.ts +8 -15
  33. package/src/lib/workspace-apps.ts +19 -128
  34. package/src/server/lib/app-creation-store.spec.ts +55 -7
  35. package/src/server/lib/app-creation-store.ts +42 -82
  36. package/src/server/lib/mcp-gateway.spec.ts +57 -113
  37. package/src/server/lib/mcp-gateway.ts +63 -94
  38. package/src/shared/workspace-app-route.spec.ts +5 -17
  39. package/src/shared/workspace-app-route.ts +0 -4
@@ -892,7 +892,12 @@ describe("Dispatch MCP gateway app discovery", () => {
892
892
  requestOrigin: "https://beta.dispatch.agent-native.com",
893
893
  };
894
894
  mocks.discoverAgents.mockResolvedValue([
895
- { ...analyticsAgent, id, url: `${url}/dispatch/apps/${id}` },
895
+ {
896
+ ...analyticsAgent,
897
+ id,
898
+ url: `${url}/actual-mount`,
899
+ source: "workspace",
900
+ },
896
901
  ]);
897
902
  mocks.listWorkspaceApps.mockResolvedValue([
898
903
  { id, path: "/actual-mount", url: `${url}/actual-mount` },
@@ -998,15 +1003,16 @@ describe("Dispatch MCP gateway app discovery", () => {
998
1003
  ]);
999
1004
  });
1000
1005
 
1001
- it("refuses a Workspace app on its Dispatch page URL while the mounted lookup is unavailable", async () => {
1006
+ it("refuses a Workspace-sourced app while the mounted lookup is unavailable", async () => {
1002
1007
  mocks.listWorkspaceApps.mockRejectedValue({ status: 503 });
1003
1008
  mocks.discoverAgents.mockResolvedValue([
1004
1009
  {
1005
1010
  id: "customer-ticket-triage",
1006
1011
  name: "Customer Ticket Triage",
1007
1012
  description: "Triage customer tickets",
1008
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1013
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1009
1014
  color: "#6366F1",
1015
+ source: "workspace",
1010
1016
  },
1011
1017
  ]);
1012
1018
 
@@ -1023,15 +1029,17 @@ describe("Dispatch MCP gateway app discovery", () => {
1023
1029
  );
1024
1030
  });
1025
1031
 
1026
- it("keeps Dispatch-page apps out of the granted list while the mounted lookup is unavailable", async () => {
1032
+ // oracle-change: page-url base-path test removed; registry urls are addresses now.
1033
+ it("keeps Workspace-sourced apps out of the granted list while the mounted lookup is unavailable", async () => {
1027
1034
  mocks.listWorkspaceApps.mockRejectedValue({ status: 503 });
1028
1035
  mocks.discoverAgents.mockResolvedValue([
1029
1036
  {
1030
1037
  id: "customer-ticket-triage",
1031
1038
  name: "Customer Ticket Triage",
1032
1039
  description: "Triage customer tickets",
1033
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1040
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1034
1041
  color: "#6366F1",
1042
+ source: "workspace",
1035
1043
  },
1036
1044
  ]);
1037
1045
 
@@ -1046,14 +1054,15 @@ describe("Dispatch MCP gateway app discovery", () => {
1046
1054
  expect(apps.map((app) => app.id)).toEqual(["dispatch"]);
1047
1055
  });
1048
1056
 
1049
- it("refuses a Dispatch-page app whose mounted path is invalid", async () => {
1057
+ it("refuses a Workspace app whose registry address is invalid", async () => {
1050
1058
  mocks.discoverAgents.mockResolvedValue([
1051
1059
  {
1052
1060
  id: "customer-ticket-triage",
1053
1061
  name: "Customer Ticket Triage",
1054
1062
  description: "Triage customer tickets",
1055
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1063
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1056
1064
  color: "#6366F1",
1065
+ source: "workspace",
1057
1066
  },
1058
1067
  ]);
1059
1068
  mocks.listWorkspaceApps.mockResolvedValue([
@@ -1061,8 +1070,8 @@ describe("Dispatch MCP gateway app discovery", () => {
1061
1070
  id: "customer-ticket-triage",
1062
1071
  name: "Customer Ticket Triage",
1063
1072
  description: "Triage customer tickets",
1064
- path: "//evil.example",
1065
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1073
+ path: "/customer-ticket-triage",
1074
+ url: "javascript:alert(1)",
1066
1075
  isDispatch: false,
1067
1076
  },
1068
1077
  ]);
@@ -1086,8 +1095,9 @@ describe("Dispatch MCP gateway app discovery", () => {
1086
1095
  id: "customer-ticket-triage",
1087
1096
  name: "Customer Ticket Triage",
1088
1097
  description: "Triage customer tickets",
1089
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1098
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1090
1099
  color: "#6366F1",
1100
+ source: "workspace",
1091
1101
  },
1092
1102
  ]);
1093
1103
  mocks.listWorkspaceApps.mockResolvedValue([
@@ -1096,7 +1106,7 @@ describe("Dispatch MCP gateway app discovery", () => {
1096
1106
  name: "Customer Ticket Triage",
1097
1107
  description: "Triage customer tickets",
1098
1108
  path: "/customer-ticket-triage",
1099
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1109
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1100
1110
  isDispatch: false,
1101
1111
  },
1102
1112
  ]);
@@ -1124,8 +1134,9 @@ describe("Dispatch MCP gateway app discovery", () => {
1124
1134
  id: "customer-ticket-triage",
1125
1135
  name: "Customer Ticket Triage",
1126
1136
  description: "Triage customer tickets",
1127
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1137
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1128
1138
  color: "#6366F1",
1139
+ source: "workspace",
1129
1140
  },
1130
1141
  ]);
1131
1142
  mocks.listWorkspaceApps.mockResolvedValue([
@@ -1134,7 +1145,7 @@ describe("Dispatch MCP gateway app discovery", () => {
1134
1145
  name: "Customer Ticket Triage",
1135
1146
  description: "Triage customer tickets",
1136
1147
  path: "/customer-ticket-triage",
1137
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1148
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1138
1149
  isDispatch: false,
1139
1150
  },
1140
1151
  ]);
@@ -1152,14 +1163,15 @@ describe("Dispatch MCP gateway app discovery", () => {
1152
1163
  );
1153
1164
  });
1154
1165
 
1155
- it("keeps Dispatch-page apps out of the granted list when the registry omits them", async () => {
1166
+ it("keeps Workspace-sourced apps out of the granted list when the registry omits them", async () => {
1156
1167
  mocks.discoverAgents.mockResolvedValue([
1157
1168
  {
1158
1169
  id: "customer-ticket-triage",
1159
1170
  name: "Customer Ticket Triage",
1160
1171
  description: "Triage customer tickets",
1161
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1172
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1162
1173
  color: "#6366F1",
1174
+ source: "workspace",
1163
1175
  },
1164
1176
  ]);
1165
1177
  mocks.listWorkspaceApps.mockResolvedValue([]);
@@ -1175,51 +1187,16 @@ describe("Dispatch MCP gateway app discovery", () => {
1175
1187
  expect(apps.map((app) => app.id)).toEqual(["dispatch"]);
1176
1188
  });
1177
1189
 
1178
- it("does not route Workspace chat to a Dispatch-page app with an invalid mounted path", async () => {
1190
+ // oracle-change: the Workspace-chat "invalid mounted path" case was removed.
1191
+ it("refuses a Workspace app whose mount is on a different origin", async () => {
1179
1192
  mocks.discoverAgents.mockResolvedValue([
1180
1193
  {
1181
1194
  id: "customer-ticket-triage",
1182
1195
  name: "Customer Ticket Triage",
1183
1196
  description: "Triage customer tickets",
1184
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1185
- color: "#6366F1",
1186
- },
1187
- ]);
1188
- mocks.listWorkspaceApps.mockResolvedValue([
1189
- {
1190
- id: "customer-ticket-triage",
1191
- name: "Customer Ticket Triage",
1192
- description: "Triage customer tickets",
1193
- path: "//evil.example",
1194
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1195
- isDispatch: false,
1196
- },
1197
- ]);
1198
-
1199
- await expect(
1200
- runWithRequestContext(
1201
- {
1202
- userEmail: "owner@example.test",
1203
- identityAuthenticatedAtMs: Date.now() - 1000,
1204
- requestOrigin: "https://beta.dispatch.agent-native.com",
1205
- },
1206
- () =>
1207
- createWorkspaceSsoEmbedSessionForWorkspaceAppChat(
1208
- "customer-ticket-triage",
1209
- ),
1210
- ),
1211
- ).rejects.toThrow();
1212
- expect(mocks.managerCallTool).not.toHaveBeenCalled();
1213
- });
1214
-
1215
- it("refuses a Dispatch-page app whose mount is on a different origin", async () => {
1216
- mocks.discoverAgents.mockResolvedValue([
1217
- {
1218
- id: "customer-ticket-triage",
1219
- name: "Customer Ticket Triage",
1220
- description: "Triage customer tickets",
1221
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1197
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1222
1198
  color: "#6366F1",
1199
+ source: "workspace",
1223
1200
  },
1224
1201
  ]);
1225
1202
  mocks.listWorkspaceApps.mockResolvedValue([
@@ -1228,7 +1205,7 @@ describe("Dispatch MCP gateway app discovery", () => {
1228
1205
  name: "Customer Ticket Triage",
1229
1206
  description: "Triage customer tickets",
1230
1207
  path: "/customer-ticket-triage",
1231
- url: "https://other.example.test/dispatch/apps/customer-ticket-triage",
1208
+ url: "https://other.example.test/customer-ticket-triage",
1232
1209
  isDispatch: false,
1233
1210
  },
1234
1211
  ]);
@@ -1252,7 +1229,7 @@ describe("Dispatch MCP gateway app discovery", () => {
1252
1229
  id: "customer-ticket-triage",
1253
1230
  name: "Customer Ticket Triage",
1254
1231
  description: "Triage customer tickets",
1255
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1232
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1256
1233
  color: "#6366F1",
1257
1234
  },
1258
1235
  ]);
@@ -1262,7 +1239,7 @@ describe("Dispatch MCP gateway app discovery", () => {
1262
1239
  name: "Customer Ticket Triage",
1263
1240
  description: "Triage customer tickets",
1264
1241
  path: "/customer-ticket-triage",
1265
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
1242
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
1266
1243
  isDispatch: false,
1267
1244
  },
1268
1245
  ]);
@@ -1283,36 +1260,6 @@ describe("Dispatch MCP gateway app discovery", () => {
1283
1260
  expect(mocks.listWorkspaceApps).toHaveBeenCalledTimes(1);
1284
1261
  });
1285
1262
 
1286
- it("keeps a prefixed Dispatch app page out of the granted list when a base path is configured", async () => {
1287
- const previous = process.env.APP_BASE_PATH;
1288
- process.env.APP_BASE_PATH = "/prefix";
1289
- try {
1290
- mocks.discoverAgents.mockResolvedValue([
1291
- {
1292
- id: "customer-ticket-triage",
1293
- name: "Customer Ticket Triage",
1294
- description: "Triage customer tickets",
1295
- url: "https://beta.agent-workspace.builder.io/prefix/dispatch/apps/customer-ticket-triage",
1296
- color: "#6366F1",
1297
- },
1298
- ]);
1299
- mocks.listWorkspaceApps.mockRejectedValue({ status: 503 });
1300
-
1301
- const apps = await runWithRequestContext(
1302
- {
1303
- userEmail: "owner@example.test",
1304
- requestOrigin: "https://beta.dispatch.agent-native.com",
1305
- },
1306
- () => listGrantedDispatchMcpApps(),
1307
- );
1308
-
1309
- expect(apps.map((app) => app.id)).toEqual(["dispatch"]);
1310
- } finally {
1311
- if (previous === undefined) delete process.env.APP_BASE_PATH;
1312
- else process.env.APP_BASE_PATH = previous;
1313
- }
1314
- });
1315
-
1316
1263
  it("defaults to exposing every discovered app", async () => {
1317
1264
  mocks.getUserSetting.mockResolvedValue(null);
1318
1265
  const apps = await runWithRequestContext(
@@ -3619,7 +3566,7 @@ describe("createGrantedDispatchMcpEmbedSession", () => {
3619
3566
  },
3620
3567
  );
3621
3568
 
3622
- it("keeps mounted document and explicit chat grants separate when the registry URL is a Dispatch page", async () => {
3569
+ it("keeps mounted document and explicit chat grants separate for a mounted Workspace app", async () => {
3623
3570
  vi.stubEnv("A2A_SECRET", "test-a2a-secret");
3624
3571
  vi.stubEnv(
3625
3572
  "WORKSPACE_GATEWAY_URL",
@@ -3646,7 +3593,7 @@ describe("createGrantedDispatchMcpEmbedSession", () => {
3646
3593
  name: "Customer Ticket Triage",
3647
3594
  description: "Triage customer tickets",
3648
3595
  path: "/customer-ticket-triage",
3649
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
3596
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
3650
3597
  isDispatch: false,
3651
3598
  },
3652
3599
  ]);
@@ -3798,9 +3745,9 @@ describe("createGrantedDispatchMcpEmbedSession", () => {
3798
3745
  {
3799
3746
  id: "malformed-app",
3800
3747
  name: "Malformed app",
3801
- description: "Invalid mounted path",
3802
- path: "//invalid",
3803
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/malformed-app",
3748
+ description: "Invalid mounted address",
3749
+ path: "/malformed-app",
3750
+ url: "not-a-url",
3804
3751
  isDispatch: false,
3805
3752
  },
3806
3753
  {
@@ -3808,7 +3755,7 @@ describe("createGrantedDispatchMcpEmbedSession", () => {
3808
3755
  name: "Customer Ticket Triage",
3809
3756
  description: "Triage customer tickets",
3810
3757
  path: "/customer-ticket-triage",
3811
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
3758
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
3812
3759
  isDispatch: false,
3813
3760
  },
3814
3761
  ];
@@ -3921,7 +3868,7 @@ describe("createGrantedDispatchMcpEmbedSession", () => {
3921
3868
  name: "Customer Ticket Triage",
3922
3869
  description: "Triage customer tickets",
3923
3870
  path: "/customer-ticket-triage",
3924
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
3871
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
3925
3872
  isDispatch: false,
3926
3873
  };
3927
3874
  mocks.listWorkspaceApps.mockResolvedValue([workspaceApp]);
@@ -3996,7 +3943,7 @@ describe("createGrantedDispatchMcpEmbedSession", () => {
3996
3943
  mocks.managerCallTool.mockResolvedValueOnce({
3997
3944
  structuredContent: {
3998
3945
  startUrl:
3999
- "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage/_agent-native/embed/start?ticket=sibling",
3946
+ "https://beta.agent-workspace.builder.io/customer-ticket-triage/_agent-native/embed/start?ticket=sibling",
4000
3947
  },
4001
3948
  });
4002
3949
  await expect(
@@ -4224,7 +4171,7 @@ describe("createGrantedDispatchMcpEmbedSession", () => {
4224
4171
  name: "Customer Ticket Triage",
4225
4172
  description: "Triage customer tickets",
4226
4173
  path: "/customer-ticket-triage",
4227
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
4174
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
4228
4175
  isDispatch: false,
4229
4176
  },
4230
4177
  ]);
@@ -4259,7 +4206,7 @@ describe("createGrantedDispatchMcpEmbedSession", () => {
4259
4206
  name: "Customer Ticket Triage",
4260
4207
  description: "Triage customer tickets",
4261
4208
  path: "/customer-ticket-triage",
4262
- url: "https://beta.agent-workspace.builder.io/dispatch/apps/customer-ticket-triage",
4209
+ url: "https://beta.agent-workspace.builder.io/customer-ticket-triage",
4263
4210
  isDispatch: false,
4264
4211
  };
4265
4212
  mocks.listWorkspaceApps.mockResolvedValue([workspaceApp]);
@@ -5627,23 +5574,20 @@ describe("A2A tab/viewport propagation, double-prefix prevention, and manifest v
5627
5574
  );
5628
5575
  });
5629
5576
 
5630
- it("prevents /<app>/<app> double base-path prefixing in appHomeBaseUrl, joinAppBaseUrlAndPath, and open_app", async () => {
5631
- expect(
5632
- appHomeBaseUrl({
5633
- url: "https://workspace.example.test/decks-2/decks-2",
5634
- }),
5635
- ).toBe("https://workspace.example.test/decks-2");
5636
- expect(
5637
- joinAppBaseUrlAndPath(
5638
- "https://workspace.example.test/decks-2",
5639
- "/decks-2",
5640
- ),
5641
- ).toBe("https://workspace.example.test/decks-2/");
5577
+ it("strips the app mount once from in-app paths in appHomeBaseUrl, joinAppBaseUrlAndPath, and open_app", async () => {
5578
+ // oracle-change: doubled registry addresses can no longer be produced, so the collapse case is gone.
5579
+ const decks = {
5580
+ id: "decks-2",
5581
+ url: "https://workspace.example.test/decks-2",
5582
+ };
5583
+ expect(appHomeBaseUrl(decks)).toBe(
5584
+ "https://workspace.example.test/decks-2",
5585
+ );
5586
+ expect(joinAppBaseUrlAndPath(decks.url, "/decks-2")).toBe(
5587
+ "https://workspace.example.test/decks-2/",
5588
+ );
5642
5589
  expect(
5643
- joinAppBaseUrlAndPath(
5644
- "https://workspace.example.test/decks-2",
5645
- "/decks-2/docs/deck-1?slide=2",
5646
- ),
5590
+ joinAppBaseUrlAndPath(decks.url, "/decks-2/docs/deck-1?slide=2"),
5647
5591
  ).toBe("https://workspace.example.test/decks-2/docs/deck-1?slide=2");
5648
5592
 
5649
5593
  mocks.discoverAgents.mockResolvedValue([
@@ -56,6 +56,7 @@ import {
56
56
  type DiscoveredAgent,
57
57
  } from "@agent-native/core/server/agent-discovery";
58
58
  import { EMBED_START_PATH } from "@agent-native/core/shared";
59
+ import { resolveWorkspaceLink } from "@agent-native/core/shared/workspace-links";
59
60
 
60
61
  import { matchDispatchAppCandidates } from "../../lib/dispatch-app-identity.js";
61
62
  import { DISPATCH_CHILD_BROWSER_TAB_PARAM } from "../../shared/chat-first-pane.js";
@@ -922,32 +923,37 @@ function safeAppOrigin(
922
923
  }
923
924
  }
924
925
 
925
- function isDispatchAppPageUrl(url: string): boolean {
926
- if (safeAppOrigin({ url }) === null) return false;
927
- const { pathname } = new URL(url);
928
- const basePath = getConfiguredAppBasePath();
929
- return (
930
- pathname.startsWith("/dispatch/apps/") ||
931
- (basePath !== "" && pathname.startsWith(`${basePath}/dispatch/apps/`))
932
- );
933
- }
934
-
935
926
  function mountedWorkspaceAppHomeUrl(app: {
927
+ id: string;
936
928
  path: string;
937
929
  url: string | null;
938
930
  }): string | null {
939
- const appUrl = app.url;
940
- const origin = appUrl ? safeAppOrigin({ url: appUrl }) : null;
941
- const path = safeAppPath(app.path);
942
- if (!origin || !path) return null;
943
- const url = new URL(path, `${origin}/`);
944
- url.search = "";
945
- url.hash = "";
946
- return url.toString().replace(/\/+$/, "");
931
+ const resolved = resolveWorkspaceLink(
932
+ { apps: [app] },
933
+ { kind: "app-base", appId: app.id },
934
+ );
935
+ return resolved.ok ? resolved.url : null;
936
+ }
937
+
938
+ function resolveAppAddressLink(
939
+ appId: string,
940
+ address: string,
941
+ kind: "app-base" | "app-mcp",
942
+ ): string {
943
+ const resolved = resolveWorkspaceLink(
944
+ { apps: [{ id: appId, url: address }] },
945
+ { kind, appId },
946
+ );
947
+ if (!resolved.ok) {
948
+ throw new Error(
949
+ `Cannot build the ${kind} link for app "${appId}": ${resolved.reason}.`,
950
+ );
951
+ }
952
+ return resolved.url;
947
953
  }
948
954
 
949
955
  function appBaseUrl(app: DispatchMcpAccessibleApp): string {
950
- return app.url.replace(/\/+$/, "");
956
+ return resolveAppAddressLink(app.id, app.url, "app-base");
951
957
  }
952
958
 
953
959
  // The owner-bound bearer for a cross-app session goes to this endpoint, so it
@@ -970,87 +976,53 @@ function targetEndpointKeepsCredentialsPrivate(endpoint: string): boolean {
970
976
  }
971
977
  }
972
978
 
973
- function collapseRepeatedLeadingPathSegment(pathname: string): string {
974
- const segments = pathname.split("/").filter(Boolean);
975
- if (segments.length < 2) return pathname;
976
- let start = 0;
977
- while (start + 1 < segments.length) {
978
- const current = segments[start];
979
- const next = segments[start + 1];
980
- if (!current || !next || current.toLowerCase() !== next.toLowerCase()) {
981
- break;
982
- }
983
- start += 1;
984
- }
985
- if (start === 0) return pathname;
986
- return `/${segments.slice(start).join("/")}`;
979
+ function appHomeAddress(
980
+ app: Pick<DispatchMcpAccessibleApp, "url" | "homeUrl">,
981
+ ): string {
982
+ const configured = app.homeUrl?.trim();
983
+ return configured && safeAppOrigin({ url: configured })
984
+ ? configured
985
+ : app.url;
987
986
  }
988
987
 
989
988
  export function appHomeBaseUrl(
990
- app: Pick<DispatchMcpAccessibleApp, "url" | "homeUrl">,
989
+ app: Pick<DispatchMcpAccessibleApp, "id" | "url" | "homeUrl">,
991
990
  ): string {
992
- const normalize = (raw: string): string => {
993
- const parsed = new URL(raw);
994
- parsed.pathname = collapseRepeatedLeadingPathSegment(parsed.pathname);
995
- return parsed.toString().replace(/\/+$/, "");
996
- };
997
- const configured = app.homeUrl?.trim();
998
- if (configured) {
999
- try {
1000
- const url = new URL(configured);
1001
- if (url.protocol === "http:" || url.protocol === "https:") {
1002
- return normalize(configured);
1003
- }
1004
- } catch {
1005
- // coercion-ok: invalid optional home URL falls back to endpoint.
1006
- }
1007
- }
1008
- try {
1009
- return normalize(app.url);
1010
- } catch {
1011
- // coercion-ok: fallback preserves pre-validated app base URL string.
1012
- return app.url.replace(/\/+$/, "");
1013
- }
991
+ return resolveAppAddressLink(app.id, appHomeAddress(app), "app-base");
992
+ }
993
+
994
+ function appHomeMcpUrl(
995
+ app: Pick<DispatchMcpAccessibleApp, "id" | "url" | "homeUrl">,
996
+ ): string {
997
+ return resolveAppAddressLink(app.id, appHomeAddress(app), "app-mcp");
1014
998
  }
1015
999
 
1016
1000
  export function joinAppBaseUrlAndPath(
1017
1001
  baseUrl: string,
1018
1002
  relPath: string,
1019
1003
  ): string {
1020
- const cleanBase = baseUrl.replace(/\/+$/, "");
1021
- let parsedBase: URL;
1022
- let parsedRel: URL;
1023
- try {
1024
- parsedBase = new URL(cleanBase);
1025
- parsedRel = new URL(relPath, "https://agent-native.invalid");
1026
- } catch {
1027
- // coercion-ok: fallback preserves direct concatenation for non-URL test inputs.
1028
- return `${cleanBase}${relPath}`;
1029
- }
1030
- const basePath = collapseRepeatedLeadingPathSegment(
1031
- parsedBase.pathname.replace(/\/+$/, "") || "/",
1004
+ const apps = [{ id: "app", url: baseUrl }];
1005
+ const base = resolveWorkspaceLink(
1006
+ { apps },
1007
+ { kind: "app-base", appId: "app" },
1032
1008
  );
1033
- const relPathname = collapseRepeatedLeadingPathSegment(
1034
- parsedRel.pathname || "/",
1009
+ const joined = resolveWorkspaceLink(
1010
+ { apps },
1011
+ {
1012
+ kind: "app-path",
1013
+ appId: "app",
1014
+ path: relPath.startsWith("/") ? relPath : `/${relPath}`,
1015
+ },
1035
1016
  );
1036
- const normalizedBasePath = basePath === "/" ? "" : basePath;
1037
- const suffix = `${parsedRel.search}${parsedRel.hash}`;
1038
- if (!normalizedBasePath) {
1039
- return `${parsedBase.origin}${relPathname}${suffix}`;
1040
- }
1041
- const lowerBase = normalizedBasePath.toLowerCase();
1042
- const lowerRel = relPathname.toLowerCase();
1043
- const effectiveRel =
1044
- lowerRel === lowerBase
1045
- ? "/"
1046
- : lowerRel.startsWith(`${lowerBase}/`)
1047
- ? relPathname.slice(normalizedBasePath.length)
1048
- : relPathname;
1049
- const joinedPath =
1050
- effectiveRel === "/"
1051
- ? `${normalizedBasePath}/`
1052
- : `${normalizedBasePath}${effectiveRel.startsWith("/") ? effectiveRel : `/${effectiveRel}`}`;
1053
- return `${parsedBase.origin}${joinedPath}${suffix}`;
1017
+ if (!base.ok) {
1018
+ throw new Error(`Cannot use app URL "${baseUrl}" (${base.reason}).`);
1019
+ }
1020
+ if (!joined.ok) {
1021
+ throw new Error(
1022
+ `Cannot join "${relPath}" onto "${baseUrl}" (${joined.reason}).`,
1023
+ );
1024
+ }
1025
+ return joined.url === base.url ? `${joined.url}/` : joined.url;
1054
1026
  }
1055
1027
 
1056
1028
  function workspaceGatewayMcpUrl(appUrl: string): string | undefined {
@@ -1102,7 +1074,7 @@ function appMcpUrl(app: DispatchMcpAccessibleApp): string {
1102
1074
  return (
1103
1075
  explicit?.replace(/\/+$/, "") ??
1104
1076
  workspaceGatewayMcpUrl(app.url) ??
1105
- `${appHomeBaseUrl(app)}/mcp`
1077
+ appHomeMcpUrl(app)
1106
1078
  );
1107
1079
  }
1108
1080
 
@@ -1248,8 +1220,7 @@ export async function listDispatchMcpApps(): Promise<{
1248
1220
  ? mountedWorkspaceAppHomeUrl(mountedApp)
1249
1221
  : null;
1250
1222
  if (homeUrl) return { ...accessible, homeUrl, workspaceMount: true };
1251
- return agent.source === "workspace" ||
1252
- isDispatchAppPageUrl(accessible.url)
1223
+ return agent.source === "workspace"
1253
1224
  ? { ...accessible, mountedPathUnavailable: true }
1254
1225
  : accessible;
1255
1226
  }),
@@ -1345,8 +1316,6 @@ async function listWorkspaceSsoApps(): Promise<DispatchMcpAccessibleApp[]> {
1345
1316
  mode: "all-apps",
1346
1317
  selectedAppIds: [],
1347
1318
  });
1348
- // A Dispatch app-page URL is only routable through a verified mount.
1349
- if (isDispatchAppPageUrl(accessible.url)) continue;
1350
1319
  candidatesById.set(agent.id, {
1351
1320
  ...accessible,
1352
1321
  homeUrl: defaultWorkspaceSsoHomeUrl(accessible, builtinHomeUrls),
@@ -2937,7 +2906,7 @@ async function createEmbedSessionForResolvedApp(input: {
2937
2906
 
2938
2907
  const targetMcpUrl =
2939
2908
  input.runtime && target.app.workspaceMount
2940
- ? `${appHomeBaseUrl(target.app)}/mcp`
2909
+ ? appHomeMcpUrl(target.app)
2941
2910
  : appMcpUrl(target.app);
2942
2911
  const firstPartyMcp = isWorkspaceSsoAppUrl(
2943
2912
  { id: target.app.id, url: targetMcpUrl },
@@ -1,25 +1,13 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
 
3
- import {
4
- workspaceAppCatalogRoute,
5
- workspaceAppRoute,
6
- } from "./workspace-app-route";
3
+ import { workspaceAppRoute } from "./workspace-app-route";
7
4
 
8
- describe("workspace app catalog destinations", () => {
9
- it("links the control plane to its own mount instead of embedding itself", () => {
10
- expect(workspaceAppCatalogRoute("dispatch")).toBe("/dispatch");
11
- });
12
-
13
- it.each(["notes", "sales ops", "nested/path"])(
5
+ describe("workspace app routes", () => {
6
+ // oracle-change: workspaceAppCatalogRoute was deleted along with its last caller.
7
+ it.each(["notes", "sales ops", "nested/path", "dispatch"])(
14
8
  "keeps %s on its encoded app route",
15
9
  (id) => {
16
- expect(workspaceAppCatalogRoute(id)).toBe(
17
- `/apps/${encodeURIComponent(id)}`,
18
- );
10
+ expect(workspaceAppRoute(id)).toBe(`/apps/${encodeURIComponent(id)}`);
19
11
  },
20
12
  );
21
-
22
- it("preserves explicit embed route construction", () => {
23
- expect(workspaceAppRoute("dispatch")).toBe("/apps/dispatch");
24
- });
25
13
  });
@@ -1,7 +1,3 @@
1
1
  export function workspaceAppRoute(appId: string): string {
2
2
  return `/apps/${encodeURIComponent(appId)}`;
3
3
  }
4
-
5
- export function workspaceAppCatalogRoute(appId: string): string {
6
- return appId === "dispatch" ? "/dispatch" : workspaceAppRoute(appId);
7
- }