@agent-native/dispatch 0.43.0-nightly-20261120212328 → 0.43.7
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 +194 -174
- package/dist/actions/ask_app.d.ts +3 -0
- package/dist/actions/ask_app.js +7 -2
- package/dist/actions/ask_app.js.map +1 -1
- package/dist/actions/ask_app_status.d.ts +3 -0
- package/dist/actions/ask_app_status.js +5 -1
- package/dist/actions/ask_app_status.js.map +1 -1
- package/dist/actions/call_app_action.d.ts +1 -0
- package/dist/actions/call_app_action.js +21 -5
- package/dist/actions/call_app_action.js.map +1 -1
- package/dist/actions/create_embed_session.d.ts +3 -2
- package/dist/actions/create_embed_session.js +4 -2
- package/dist/actions/create_embed_session.js.map +1 -1
- package/dist/actions/create_workspace_app_embed_session.d.ts +3 -2
- package/dist/actions/create_workspace_app_embed_session.js +3 -1
- package/dist/actions/create_workspace_app_embed_session.js.map +1 -1
- package/dist/actions/delete-destination.d.ts +12 -12
- package/dist/actions/execute-action-suggestion.d.ts +44 -0
- package/dist/actions/execute-action-suggestion.d.ts.map +1 -0
- package/dist/actions/execute-action-suggestion.js +148 -0
- package/dist/actions/execute-action-suggestion.js.map +1 -0
- package/dist/actions/import-agent.d.ts +13 -13
- package/dist/actions/index.d.ts.map +1 -1
- package/dist/actions/index.js +5 -1
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/list-connected-agents.js +3 -2
- package/dist/actions/list-connected-agents.js.map +1 -1
- package/dist/actions/list-workspace-connections.d.ts +1 -0
- package/dist/actions/list-workspace-connections.d.ts.map +1 -1
- package/dist/actions/list_app_actions.js +1 -1
- package/dist/actions/list_app_actions.js.map +1 -1
- package/dist/actions/list_apps.d.ts +2 -0
- package/dist/actions/list_apps.js +11 -3
- package/dist/actions/list_apps.js.map +1 -1
- package/dist/actions/navigate.js +1 -0
- package/dist/actions/navigate.js.map +1 -1
- package/dist/actions/open_app.d.ts +4 -0
- package/dist/actions/open_app.js +14 -6
- package/dist/actions/open_app.js.map +1 -1
- package/dist/actions/propose-action-suggestions.d.ts +45 -0
- package/dist/actions/propose-action-suggestions.d.ts.map +1 -0
- package/dist/actions/propose-action-suggestions.js +32 -0
- package/dist/actions/propose-action-suggestions.js.map +1 -0
- package/dist/actions/provider-api-register.d.ts +12 -12
- package/dist/actions/read_view.js +1 -1
- package/dist/actions/read_view.js.map +1 -1
- package/dist/actions/remember-pointer.js +1 -1
- package/dist/actions/remember-pointer.js.map +1 -1
- package/dist/actions/resolve-pointer.js +1 -1
- package/dist/actions/resolve-pointer.js.map +1 -1
- package/dist/actions/route-app-intent.d.ts +6 -0
- package/dist/actions/route-app-intent.js +79 -5
- package/dist/actions/route-app-intent.js.map +1 -1
- package/dist/actions/send-code-agent-remote-command.js +4 -0
- package/dist/actions/send-code-agent-remote-command.js.map +1 -1
- package/dist/actions/start-workspace-app-creation.js +1 -1
- package/dist/actions/start-workspace-app-creation.js.map +1 -1
- package/dist/actions/upsert-destination.d.ts +12 -12
- package/dist/actions/view-screen.d.ts +12 -1
- package/dist/actions/view-screen.js +53 -5
- package/dist/actions/view-screen.js.map +1 -1
- package/dist/components/chat-action-suggestions.d.ts +8 -0
- package/dist/components/chat-action-suggestions.d.ts.map +1 -0
- package/dist/components/chat-action-suggestions.js +191 -0
- package/dist/components/chat-action-suggestions.js.map +1 -0
- package/dist/components/chat-home-apps.d.ts.map +1 -1
- package/dist/components/chat-home-apps.js +1 -1
- package/dist/components/chat-home-apps.js.map +1 -1
- package/dist/components/google-broker-settings-group.d.ts +2 -0
- package/dist/components/google-broker-settings-group.d.ts.map +1 -0
- package/dist/components/google-broker-settings-group.js +53 -0
- package/dist/components/google-broker-settings-group.js.map +1 -0
- package/dist/components/layout/Layout.d.ts +4 -1
- package/dist/components/layout/Layout.d.ts.map +1 -1
- package/dist/components/layout/Layout.js +246 -69
- package/dist/components/layout/Layout.js.map +1 -1
- package/dist/components/messaging-setup-panel.d.ts.map +1 -1
- package/dist/components/messaging-setup-panel.js +47 -15
- package/dist/components/messaging-setup-panel.js.map +1 -1
- package/dist/components/workspace-app-host.d.ts +27 -4
- package/dist/components/workspace-app-host.d.ts.map +1 -1
- package/dist/components/workspace-app-host.js +355 -74
- package/dist/components/workspace-app-host.js.map +1 -1
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/db/google-broker-admission.d.ts +36 -0
- package/dist/db/google-broker-admission.d.ts.map +1 -0
- package/dist/db/google-broker-admission.js +129 -0
- package/dist/db/google-broker-admission.js.map +1 -0
- package/dist/db/migrations.d.ts +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +42 -0
- package/dist/db/migrations.js.map +1 -1
- package/dist/lib/action-suggestions.d.ts +20 -0
- package/dist/lib/action-suggestions.d.ts.map +1 -0
- package/dist/lib/action-suggestions.js +219 -0
- package/dist/lib/action-suggestions.js.map +1 -0
- package/dist/lib/chat-first-app-route.d.ts +11 -5
- package/dist/lib/chat-first-app-route.d.ts.map +1 -1
- package/dist/lib/chat-first-app-route.js +9 -5
- package/dist/lib/chat-first-app-route.js.map +1 -1
- package/dist/lib/chat-first-pane.d.ts +25 -1
- package/dist/lib/chat-first-pane.d.ts.map +1 -1
- package/dist/lib/chat-first-pane.js +67 -1
- package/dist/lib/chat-first-pane.js.map +1 -1
- package/dist/lib/data-intent.d.ts +3 -0
- package/dist/lib/data-intent.d.ts.map +1 -0
- package/dist/lib/data-intent.js +14 -0
- package/dist/lib/data-intent.js.map +1 -0
- package/dist/lib/dispatch-app-identity.d.ts +10 -0
- package/dist/lib/dispatch-app-identity.d.ts.map +1 -0
- package/dist/lib/dispatch-app-identity.js +18 -0
- package/dist/lib/dispatch-app-identity.js.map +1 -0
- package/dist/lib/other-apps.d.ts +15 -0
- package/dist/lib/other-apps.d.ts.map +1 -1
- package/dist/lib/other-apps.js +31 -0
- package/dist/lib/other-apps.js.map +1 -1
- package/dist/lib/workspace-app-frame-view.d.ts +15 -0
- package/dist/lib/workspace-app-frame-view.d.ts.map +1 -0
- package/dist/lib/workspace-app-frame-view.js +72 -0
- package/dist/lib/workspace-app-frame-view.js.map +1 -0
- package/dist/lib/workspace-apps.d.ts +5 -0
- package/dist/lib/workspace-apps.d.ts.map +1 -1
- package/dist/lib/workspace-apps.js +85 -23
- package/dist/lib/workspace-apps.js.map +1 -1
- package/dist/lib/workspace-apps.test.js +6 -0
- package/dist/lib/workspace-apps.test.js.map +1 -1
- package/dist/routes/pages/_index.d.ts +2 -2
- package/dist/routes/pages/chat.d.ts.map +1 -1
- package/dist/routes/pages/chat.js +33 -2
- package/dist/routes/pages/chat.js.map +1 -1
- package/dist/routes/pages/settings-page.d.ts +1 -1
- package/dist/routes/pages/settings-page.d.ts.map +1 -1
- package/dist/routes/pages/settings-page.js +3 -2
- package/dist/routes/pages/settings-page.js.map +1 -1
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +5 -5
- package/dist/server/index.js.map +1 -1
- package/dist/server/lib/action-suggestions.d.ts +41 -0
- package/dist/server/lib/action-suggestions.d.ts.map +1 -0
- package/dist/server/lib/action-suggestions.js +94 -0
- package/dist/server/lib/action-suggestions.js.map +1 -0
- package/dist/server/lib/app-action-result.d.ts +5 -0
- package/dist/server/lib/app-action-result.d.ts.map +1 -1
- package/dist/server/lib/app-action-result.js +7 -0
- package/dist/server/lib/app-action-result.js.map +1 -1
- package/dist/server/lib/app-creation-store.d.ts.map +1 -1
- package/dist/server/lib/app-creation-store.js +63 -13
- package/dist/server/lib/app-creation-store.js.map +1 -1
- package/dist/server/lib/curated-workspace-templates.d.ts.map +1 -1
- package/dist/server/lib/curated-workspace-templates.js +3 -0
- package/dist/server/lib/curated-workspace-templates.js.map +1 -1
- package/dist/server/lib/dispatch-config.d.ts +5 -0
- package/dist/server/lib/dispatch-config.d.ts.map +1 -0
- package/dist/server/lib/dispatch-config.js +11 -0
- package/dist/server/lib/dispatch-config.js.map +1 -0
- package/dist/server/lib/dispatch-pane-context.d.ts +11 -0
- package/dist/server/lib/dispatch-pane-context.d.ts.map +1 -0
- package/dist/server/lib/dispatch-pane-context.js +35 -0
- package/dist/server/lib/dispatch-pane-context.js.map +1 -0
- package/dist/server/lib/google-broker-provider.d.ts +41 -0
- package/dist/server/lib/google-broker-provider.d.ts.map +1 -0
- package/dist/server/lib/google-broker-provider.js +96 -0
- package/dist/server/lib/google-broker-provider.js.map +1 -0
- package/dist/server/lib/google-broker-rpc.d.ts +26 -0
- package/dist/server/lib/google-broker-rpc.d.ts.map +1 -0
- package/dist/server/lib/google-broker-rpc.js +52 -0
- package/dist/server/lib/google-broker-rpc.js.map +1 -0
- package/dist/server/lib/hosted-apps-settings.d.ts.map +1 -1
- package/dist/server/lib/hosted-apps-settings.js +4 -0
- package/dist/server/lib/hosted-apps-settings.js.map +1 -1
- package/dist/server/lib/mcp-app-discovery.d.ts +17 -0
- package/dist/server/lib/mcp-app-discovery.d.ts.map +1 -0
- package/dist/server/lib/mcp-app-discovery.js +231 -0
- package/dist/server/lib/mcp-app-discovery.js.map +1 -0
- package/dist/server/lib/mcp-gateway.d.ts +64 -21
- package/dist/server/lib/mcp-gateway.d.ts.map +1 -1
- package/dist/server/lib/mcp-gateway.js +730 -88
- package/dist/server/lib/mcp-gateway.js.map +1 -1
- package/dist/server/plugins/agent-chat.js +9 -7
- package/dist/server/plugins/agent-chat.js.map +1 -1
- package/dist/server/plugins/auth.d.ts.map +1 -1
- package/dist/server/plugins/auth.js +1 -0
- package/dist/server/plugins/auth.js.map +1 -1
- package/dist/server/plugins/db.d.ts.map +1 -1
- package/dist/server/plugins/db.js +0 -46
- package/dist/server/plugins/db.js.map +1 -1
- package/dist/server/plugins/integrations.d.ts.map +1 -1
- package/dist/server/plugins/integrations.js +4 -1
- package/dist/server/plugins/integrations.js.map +1 -1
- package/dist/shared/chat-first-pane.d.ts +24 -0
- package/dist/shared/chat-first-pane.d.ts.map +1 -1
- package/dist/shared/chat-first-pane.js +34 -0
- package/dist/shared/chat-first-pane.js.map +1 -1
- package/dist/shared/labs.d.ts +1 -0
- package/dist/shared/labs.d.ts.map +1 -1
- package/dist/shared/labs.js +7 -0
- package/dist/shared/labs.js.map +1 -1
- package/package.json +7 -6
- package/src/actions/action-suggestions.spec.ts +342 -0
- package/src/actions/app_actions.spec.ts +103 -0
- package/src/actions/ask_app.ts +9 -2
- package/src/actions/ask_app_status.ts +12 -1
- package/src/actions/call_app_action.ts +28 -8
- package/src/actions/create_embed_session.ts +8 -2
- package/src/actions/create_workspace_app_embed_session.ts +6 -1
- package/src/actions/execute-action-suggestion.ts +177 -0
- package/src/actions/index.spec.ts +6 -3
- package/src/actions/index.ts +5 -1
- package/src/actions/list-connected-agents.spec.ts +26 -1
- package/src/actions/list-connected-agents.ts +7 -4
- package/src/actions/list_app_actions.ts +1 -1
- package/src/actions/list_apps.spec.ts +58 -22
- package/src/actions/list_apps.ts +12 -5
- package/src/actions/navigate.ts +1 -0
- package/src/actions/open_app.spec.ts +17 -1
- package/src/actions/open_app.ts +21 -8
- package/src/actions/propose-action-suggestions.ts +42 -0
- package/src/actions/read_view.ts +1 -1
- package/src/actions/remember-pointer.ts +1 -1
- package/src/actions/resolve-pointer.ts +1 -1
- package/src/actions/route-app-intent.spec.ts +234 -5
- package/src/actions/route-app-intent.ts +89 -4
- package/src/actions/send-code-agent-remote-command.spec.ts +40 -0
- package/src/actions/send-code-agent-remote-command.ts +5 -0
- package/src/actions/start-workspace-app-creation.ts +1 -1
- package/src/actions/view-screen.bundle.spec.ts +15 -2
- package/src/actions/view-screen.spec.ts +81 -3
- package/src/actions/view-screen.ts +60 -4
- package/src/components/chat-action-suggestions.spec.tsx +362 -0
- package/src/components/chat-action-suggestions.tsx +432 -0
- package/src/components/chat-home-apps.spec.tsx +19 -0
- package/src/components/chat-home-apps.tsx +0 -1
- package/src/components/google-broker-settings-group.tsx +186 -0
- package/src/components/layout/Layout.spec.tsx +419 -28
- package/src/components/layout/Layout.tsx +304 -66
- package/src/components/messaging-setup-panel.spec.tsx +278 -4
- package/src/components/messaging-setup-panel.tsx +82 -19
- package/src/components/workspace-app-card.spec.tsx +79 -10
- package/src/components/workspace-app-chat-rail.spec.tsx +81 -3
- package/src/components/workspace-app-host.spec.tsx +269 -16
- package/src/components/workspace-app-host.tsx +464 -87
- package/src/config.ts +5 -0
- package/src/db/google-broker-admission.ts +160 -0
- package/src/db/migrations.spec.ts +165 -2
- package/src/db/migrations.ts +43 -1
- package/src/lib/action-suggestions.ts +267 -0
- package/src/lib/chat-first-app-route.spec.ts +15 -2
- package/src/lib/chat-first-app-route.ts +19 -7
- package/src/lib/chat-first-pane.spec.ts +71 -0
- package/src/lib/chat-first-pane.ts +101 -4
- package/src/lib/data-intent.spec.ts +21 -0
- package/src/lib/data-intent.ts +13 -0
- package/src/lib/dispatch-app-identity.ts +40 -0
- package/src/lib/other-apps.spec.ts +110 -1
- package/src/lib/other-apps.ts +41 -0
- package/src/lib/workspace-app-frame-view.spec.ts +13 -0
- package/src/lib/workspace-app-frame-view.ts +98 -0
- package/src/lib/workspace-apps.spec.ts +101 -0
- package/src/lib/workspace-apps.test.ts +18 -0
- package/src/lib/workspace-apps.ts +102 -24
- package/src/routes/pages/chat.spec.tsx +92 -1
- package/src/routes/pages/chat.tsx +41 -2
- package/src/routes/pages/settings-page.tsx +22 -17
- package/src/routes/pages/settings.spec.tsx +4 -0
- package/src/server/index.ts +6 -6
- package/src/server/lib/action-suggestions.ts +122 -0
- package/src/server/lib/app-action-result.ts +8 -0
- package/src/server/lib/app-creation-store.spec.ts +251 -0
- package/src/server/lib/app-creation-store.ts +72 -12
- package/src/server/lib/community-apps.spec.ts +19 -1
- package/src/server/lib/curated-workspace-templates.spec.ts +12 -0
- package/src/server/lib/curated-workspace-templates.ts +2 -0
- package/src/server/lib/dispatch-config.ts +15 -0
- package/src/server/lib/dispatch-pane-context.spec.ts +54 -0
- package/src/server/lib/dispatch-pane-context.ts +54 -0
- package/src/server/lib/google-broker-provider.ts +121 -0
- package/src/server/lib/google-broker-rpc.spec.ts +95 -0
- package/src/server/lib/google-broker-rpc.ts +107 -0
- package/src/server/lib/hosted-apps-settings.ts +4 -0
- package/src/server/lib/mcp-app-discovery.ts +318 -0
- package/src/server/lib/mcp-gateway.spec.ts +2252 -524
- package/src/server/lib/mcp-gateway.ts +1044 -181
- package/src/server/plugins/agent-chat.direct-mcp.spec.ts +84 -5
- package/src/server/plugins/agent-chat.ts +9 -7
- package/src/server/plugins/auth.spec.ts +5 -1
- package/src/server/plugins/auth.ts +1 -0
- package/src/server/plugins/db.ts +0 -51
- package/src/server/plugins/integrations.ts +4 -1
- package/src/shared/chat-first-pane.spec.ts +36 -0
- package/src/shared/chat-first-pane.ts +55 -0
- package/src/shared/labs.ts +8 -0
- package/src/server/plugins/agent-chat.spec.ts +0 -206
- package/src/server/plugins/integrations.spec.ts +0 -60
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getConfiguredAppBasePath,
|
|
3
|
+
getRequestContext,
|
|
4
|
+
getRequestOrgId,
|
|
5
|
+
getRequestUserEmail,
|
|
6
|
+
} from "@agent-native/core/server";
|
|
7
|
+
import {
|
|
8
|
+
discoverAgentsWithDirectoryStatus,
|
|
9
|
+
getBuiltinAgents,
|
|
10
|
+
type DiscoveredAgent,
|
|
11
|
+
} from "@agent-native/core/server/agent-discovery";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
listWorkspaceApps,
|
|
15
|
+
type WorkspaceAppSummary,
|
|
16
|
+
} from "./app-creation-store.js";
|
|
17
|
+
import {
|
|
18
|
+
projectEnvironmentUrl,
|
|
19
|
+
requestEnvironmentLane,
|
|
20
|
+
} from "./environment-lane.js";
|
|
21
|
+
|
|
22
|
+
const CACHE_TTL_MS = 5 * 60_000;
|
|
23
|
+
const MAX_SCOPES = 64;
|
|
24
|
+
|
|
25
|
+
export interface DispatchMcpDegradedSource {
|
|
26
|
+
source: "connected-apps" | "workspace-directory" | "workspace-mounts";
|
|
27
|
+
status: "unavailable" | "forbidden";
|
|
28
|
+
usingCache: boolean;
|
|
29
|
+
httpStatus?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type WorkspaceMount = Pick<WorkspaceAppSummary, "id" | "url" | "path">;
|
|
33
|
+
type AgentManifest = Pick<
|
|
34
|
+
DiscoveredAgent,
|
|
35
|
+
"id" | "name" | "description" | "url" | "color" | "source" | "aliases"
|
|
36
|
+
>;
|
|
37
|
+
type Snapshot<T> = { started: number; expiresAt: number; entries: T[] };
|
|
38
|
+
type Cache<T> = Map<string, Snapshot<T>>;
|
|
39
|
+
const manifests: Cache<AgentManifest> = new Map();
|
|
40
|
+
let nextRead = 0;
|
|
41
|
+
|
|
42
|
+
function scopeKey(ownerEmail: string, orgId: string | undefined) {
|
|
43
|
+
const context = getRequestContext();
|
|
44
|
+
if (context?.authCapability || context?.verifiedServiceIdentity) return null;
|
|
45
|
+
return JSON.stringify([
|
|
46
|
+
ownerEmail.toLowerCase(),
|
|
47
|
+
orgId,
|
|
48
|
+
context?.requestOrigin,
|
|
49
|
+
context?.a2aIdentityAssurance,
|
|
50
|
+
context?.credentialScope,
|
|
51
|
+
requestEnvironmentLane(),
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function readSnapshot<T>(cache: Cache<T>, scope: string | null): T[] {
|
|
56
|
+
if (!scope) return [];
|
|
57
|
+
const snapshot = cache.get(scope);
|
|
58
|
+
return snapshot && snapshot.expiresAt > Date.now() ? snapshot.entries : [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function saveSnapshot<T>(
|
|
62
|
+
cache: Cache<T>,
|
|
63
|
+
scope: string | null,
|
|
64
|
+
started: number,
|
|
65
|
+
entries: T[],
|
|
66
|
+
) {
|
|
67
|
+
if (!scope || (cache.get(scope)?.started ?? 0) > started) return;
|
|
68
|
+
cache.delete(scope);
|
|
69
|
+
cache.set(scope, { started, expiresAt: Date.now() + CACHE_TTL_MS, entries });
|
|
70
|
+
if (cache.size > MAX_SCOPES) {
|
|
71
|
+
const oldest = cache.keys().next().value;
|
|
72
|
+
if (oldest !== undefined) cache.delete(oldest);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function toManifest(agent: DiscoveredAgent): AgentManifest {
|
|
77
|
+
return {
|
|
78
|
+
id: agent.id,
|
|
79
|
+
name: agent.name,
|
|
80
|
+
description: agent.description,
|
|
81
|
+
url: agent.url,
|
|
82
|
+
color: agent.color,
|
|
83
|
+
...(agent.source ? { source: agent.source } : {}),
|
|
84
|
+
...(agent.aliases?.length ? { aliases: [...agent.aliases] } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function withFallback(
|
|
89
|
+
fresh: AgentManifest[],
|
|
90
|
+
cached: AgentManifest[],
|
|
91
|
+
): AgentManifest[] {
|
|
92
|
+
const known = new Set(fresh.map((agent) => agent.id.toLowerCase()));
|
|
93
|
+
return [
|
|
94
|
+
...fresh,
|
|
95
|
+
...cached.filter((agent) => !known.has(agent.id.toLowerCase())),
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function registrationUrl(value: string): URL | null {
|
|
100
|
+
const projected = projectEnvironmentUrl(value);
|
|
101
|
+
if (!URL.canParse(projected)) return null;
|
|
102
|
+
const url = new URL(projected);
|
|
103
|
+
return (url.protocol === "https:" || url.protocol === "http:") &&
|
|
104
|
+
!url.username &&
|
|
105
|
+
!url.password &&
|
|
106
|
+
!url.search &&
|
|
107
|
+
!url.hash
|
|
108
|
+
? url
|
|
109
|
+
: null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function sameInstallation(agent: AgentManifest, mount: WorkspaceMount) {
|
|
113
|
+
if (agent.id.toLowerCase() !== mount.id.toLowerCase() || !mount.url) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const manifestUrl = registrationUrl(agent.url);
|
|
117
|
+
const currentUrl = registrationUrl(mount.url);
|
|
118
|
+
if (!manifestUrl || !currentUrl || manifestUrl.origin !== currentUrl.origin) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (
|
|
123
|
+
!mount.path.startsWith("/") ||
|
|
124
|
+
mount.path.startsWith("//") ||
|
|
125
|
+
mount.path.includes("\\") ||
|
|
126
|
+
/%(?:2f|5c)/i.test(mount.path)
|
|
127
|
+
)
|
|
128
|
+
return false;
|
|
129
|
+
const installUrl = new URL(mount.path, currentUrl.origin);
|
|
130
|
+
if (
|
|
131
|
+
installUrl.pathname !== mount.path ||
|
|
132
|
+
installUrl.search ||
|
|
133
|
+
installUrl.hash
|
|
134
|
+
) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const trimTrailingSlash = (path: string) => path.replace(/\/+$/, "");
|
|
139
|
+
const manifestPath = trimTrailingSlash(manifestUrl.pathname);
|
|
140
|
+
const installPath = trimTrailingSlash(installUrl.pathname);
|
|
141
|
+
const legacyPath = `/dispatch/apps/${encodeURIComponent(mount.id)}`;
|
|
142
|
+
return (
|
|
143
|
+
manifestPath === trimTrailingSlash(currentUrl.pathname) ||
|
|
144
|
+
manifestPath === installPath ||
|
|
145
|
+
manifestPath === legacyPath ||
|
|
146
|
+
manifestPath === `${getConfiguredAppBasePath()}${legacyPath}`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
type MountRead = Awaited<ReturnType<typeof readMounts>>;
|
|
151
|
+
|
|
152
|
+
async function recheckCachedInstallations(
|
|
153
|
+
readCached: () => AgentManifest[],
|
|
154
|
+
mountRead: Promise<MountRead>,
|
|
155
|
+
) {
|
|
156
|
+
const { mounts, degraded } = await mountRead;
|
|
157
|
+
if (degraded) return [];
|
|
158
|
+
const byId = new Map(mounts.map((mount) => [mount.id.toLowerCase(), mount]));
|
|
159
|
+
return readCached().filter((agent) => {
|
|
160
|
+
const mount = byId.get(agent.id.toLowerCase());
|
|
161
|
+
return mount !== undefined && sameInstallation(agent, mount);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const TRANSIENT_DIRECTORY_REASONS = new Set([
|
|
166
|
+
"network",
|
|
167
|
+
"server-error",
|
|
168
|
+
"timeout",
|
|
169
|
+
]);
|
|
170
|
+
|
|
171
|
+
async function readAgents(
|
|
172
|
+
scope: string | null,
|
|
173
|
+
started: number,
|
|
174
|
+
mountRead: Promise<MountRead>,
|
|
175
|
+
) {
|
|
176
|
+
let result: Awaited<ReturnType<typeof discoverAgentsWithDirectoryStatus>>;
|
|
177
|
+
try {
|
|
178
|
+
result = await discoverAgentsWithDirectoryStatus("dispatch", {
|
|
179
|
+
requireReadableAgentSources: true,
|
|
180
|
+
});
|
|
181
|
+
} catch (error) {
|
|
182
|
+
const httpStatus = statusFromError(error);
|
|
183
|
+
const forbidden = httpStatus === 401 || httpStatus === 403;
|
|
184
|
+
if (forbidden) saveSnapshot(manifests, scope, started, []);
|
|
185
|
+
const cached = forbidden
|
|
186
|
+
? []
|
|
187
|
+
: await recheckCachedInstallations(
|
|
188
|
+
() =>
|
|
189
|
+
readSnapshot(manifests, scope).filter(
|
|
190
|
+
(agent) =>
|
|
191
|
+
agent.source !== "builtin" && agent.source !== "org-directory",
|
|
192
|
+
),
|
|
193
|
+
mountRead,
|
|
194
|
+
);
|
|
195
|
+
return {
|
|
196
|
+
agents: withFallback(
|
|
197
|
+
getBuiltinAgents("dispatch").map(toManifest),
|
|
198
|
+
cached,
|
|
199
|
+
),
|
|
200
|
+
degraded: {
|
|
201
|
+
source: "connected-apps",
|
|
202
|
+
status: forbidden ? "forbidden" : "unavailable",
|
|
203
|
+
usingCache: cached.length > 0,
|
|
204
|
+
...(httpStatus ? { httpStatus } : {}),
|
|
205
|
+
} satisfies DispatchMcpDegradedSource,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const agents = result.agents.map(toManifest);
|
|
210
|
+
const directory = result.directory;
|
|
211
|
+
if (directory.status === "unavailable" || directory.status === "forbidden") {
|
|
212
|
+
const reason =
|
|
213
|
+
directory.status === "unavailable" ? directory.reason : "authorization";
|
|
214
|
+
const forbidden =
|
|
215
|
+
reason === "authentication" ||
|
|
216
|
+
reason === "unauthorized" ||
|
|
217
|
+
reason === "authorization";
|
|
218
|
+
const transient = TRANSIENT_DIRECTORY_REASONS.has(reason);
|
|
219
|
+
const current = agents.filter((agent) => agent.source !== "org-directory");
|
|
220
|
+
const cached = transient
|
|
221
|
+
? await recheckCachedInstallations(
|
|
222
|
+
() =>
|
|
223
|
+
readSnapshot(manifests, scope).filter(
|
|
224
|
+
(agent) => agent.source === "org-directory",
|
|
225
|
+
),
|
|
226
|
+
mountRead,
|
|
227
|
+
)
|
|
228
|
+
: [];
|
|
229
|
+
if (!transient) saveSnapshot(manifests, scope, started, current);
|
|
230
|
+
return {
|
|
231
|
+
agents: withFallback(current, cached),
|
|
232
|
+
degraded: {
|
|
233
|
+
source: "workspace-directory",
|
|
234
|
+
status: forbidden ? "forbidden" : "unavailable",
|
|
235
|
+
usingCache: cached.length > 0,
|
|
236
|
+
} satisfies DispatchMcpDegradedSource,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const available =
|
|
241
|
+
directory.status === "available"
|
|
242
|
+
? agents
|
|
243
|
+
: agents.filter((agent) => agent.source !== "org-directory");
|
|
244
|
+
saveSnapshot(manifests, scope, started, available);
|
|
245
|
+
return { agents: available, degraded: undefined };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function statusFromError(error: unknown): number | undefined {
|
|
249
|
+
const seen = new Set<object>();
|
|
250
|
+
let current: unknown = error;
|
|
251
|
+
let firstStatus: number | undefined;
|
|
252
|
+
while (current && typeof current === "object" && !seen.has(current)) {
|
|
253
|
+
seen.add(current);
|
|
254
|
+
for (const key of ["statusCode", "status", "code"] as const) {
|
|
255
|
+
const status = (current as Record<string, unknown>)[key];
|
|
256
|
+
if (status === 401 || status === 403) return status;
|
|
257
|
+
if (
|
|
258
|
+
firstStatus === undefined &&
|
|
259
|
+
typeof status === "number" &&
|
|
260
|
+
status >= 400 &&
|
|
261
|
+
status <= 599
|
|
262
|
+
) {
|
|
263
|
+
firstStatus = status;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
current = "cause" in current ? current.cause : undefined;
|
|
267
|
+
}
|
|
268
|
+
return firstStatus;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function readMounts() {
|
|
272
|
+
try {
|
|
273
|
+
const apps = await listWorkspaceApps({ includeAgentCards: false });
|
|
274
|
+
return {
|
|
275
|
+
mounts: apps
|
|
276
|
+
.filter((app) => app.status !== "pending")
|
|
277
|
+
.map(({ id, url, path }) => ({ id, url, path })),
|
|
278
|
+
};
|
|
279
|
+
} catch (error) {
|
|
280
|
+
const httpStatus = statusFromError(error);
|
|
281
|
+
return {
|
|
282
|
+
mounts: [],
|
|
283
|
+
degraded: {
|
|
284
|
+
source: "workspace-mounts",
|
|
285
|
+
status:
|
|
286
|
+
httpStatus === 401 || httpStatus === 403
|
|
287
|
+
? "forbidden"
|
|
288
|
+
: "unavailable",
|
|
289
|
+
usingCache: false,
|
|
290
|
+
...(httpStatus ? { httpStatus } : {}),
|
|
291
|
+
} satisfies DispatchMcpDegradedSource,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export async function discoverDispatchMcpApps(): Promise<{
|
|
297
|
+
agents: AgentManifest[];
|
|
298
|
+
mountedApps: WorkspaceMount[];
|
|
299
|
+
degradedSources: DispatchMcpDegradedSource[];
|
|
300
|
+
}> {
|
|
301
|
+
const ownerEmail = getRequestUserEmail();
|
|
302
|
+
if (!ownerEmail) throw new Error("no authenticated user");
|
|
303
|
+
const orgId = getRequestOrgId();
|
|
304
|
+
const scope = scopeKey(ownerEmail, orgId);
|
|
305
|
+
const started = ++nextRead;
|
|
306
|
+
const mountRead = readMounts();
|
|
307
|
+
const [agents, mounts] = await Promise.all([
|
|
308
|
+
readAgents(scope, started, mountRead),
|
|
309
|
+
mountRead,
|
|
310
|
+
]);
|
|
311
|
+
const degradedSources = [agents.degraded, mounts.degraded].filter(
|
|
312
|
+
(source) => source !== undefined,
|
|
313
|
+
);
|
|
314
|
+
for (const source of degradedSources) {
|
|
315
|
+
console.warn("[dispatch] MCP app discovery degraded", source);
|
|
316
|
+
}
|
|
317
|
+
return { agents: agents.agents, mountedApps: mounts.mounts, degradedSources };
|
|
318
|
+
}
|