@agent-native/dispatch 0.42.9-nightly-20261118063257 → 0.42.10
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 +25 -61
- package/dist/actions/call_app_action.d.ts +15 -0
- package/dist/actions/call_app_action.d.ts.map +1 -0
- package/dist/actions/call_app_action.js +48 -0
- package/dist/actions/call_app_action.js.map +1 -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/index.d.ts +8 -0
- package/dist/actions/index.d.ts.map +1 -1
- package/dist/actions/index.js +31 -0
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/list_app_actions.d.ts +14 -0
- package/dist/actions/list_app_actions.d.ts.map +1 -0
- package/dist/actions/list_app_actions.js +29 -0
- package/dist/actions/list_app_actions.js.map +1 -0
- package/dist/actions/read_view.d.ts +8 -0
- package/dist/actions/read_view.d.ts.map +1 -0
- package/dist/actions/read_view.js +38 -0
- package/dist/actions/read_view.js.map +1 -0
- package/dist/components/usage-alerts-panel.d.ts +6 -0
- package/dist/components/usage-alerts-panel.d.ts.map +1 -1
- package/dist/components/usage-alerts-panel.js +12 -1
- package/dist/components/usage-alerts-panel.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/lib/app-action-result.d.ts +4 -0
- package/dist/server/lib/app-action-result.d.ts.map +1 -0
- package/dist/server/lib/app-action-result.js +15 -0
- package/dist/server/lib/app-action-result.js.map +1 -0
- package/dist/server/lib/app-creation-store.d.ts +9 -1
- package/dist/server/lib/app-creation-store.d.ts.map +1 -1
- package/dist/server/lib/app-creation-store.js +70 -7
- package/dist/server/lib/app-creation-store.js.map +1 -1
- package/dist/server/lib/mcp-gateway.d.ts +33 -0
- package/dist/server/lib/mcp-gateway.d.ts.map +1 -1
- package/dist/server/lib/mcp-gateway.js +204 -3
- package/dist/server/lib/mcp-gateway.js.map +1 -1
- package/dist/server/lib/usage-metrics-store.d.ts.map +1 -1
- package/dist/server/lib/usage-metrics-store.js +2 -2
- package/dist/server/lib/usage-metrics-store.js.map +1 -1
- package/dist/server/plugins/agent-chat.js +2 -2
- package/dist/server/plugins/agent-chat.js.map +1 -1
- package/package.json +4 -4
- package/src/actions/app_actions.spec.ts +198 -0
- package/src/actions/call_app_action.ts +59 -0
- package/src/actions/index.spec.ts +50 -2
- package/src/actions/index.ts +34 -0
- package/src/actions/list_app_actions.ts +33 -0
- package/src/actions/read_view.ts +46 -0
- package/src/components/usage-alerts-panel.tsx +17 -3
- package/src/server/index.ts +5 -0
- package/src/server/lib/app-action-result.ts +19 -0
- package/src/server/lib/app-creation-store.spec.ts +181 -0
- package/src/server/lib/app-creation-store.ts +100 -7
- package/src/server/lib/mcp-gateway.spec.ts +254 -0
- package/src/server/lib/mcp-gateway.ts +279 -2
- package/src/server/lib/usage-metrics-store.spec.ts +1 -0
- package/src/server/lib/usage-metrics-store.ts +2 -1
- package/src/server/plugins/agent-chat.spec.ts +4 -0
- package/src/server/plugins/agent-chat.ts +2 -2
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
listAvailableWorkspaceTemplates,
|
|
18
18
|
listOrganizationVisibleWorkspaceApps,
|
|
19
19
|
listWorkspaceApps,
|
|
20
|
+
getWorkspaceInfo,
|
|
20
21
|
scaffoldWorkspaceAppFromTemplate,
|
|
21
22
|
setAppCreationSettings,
|
|
22
23
|
startWorkspaceAppCreation,
|
|
@@ -1830,6 +1831,121 @@ describe("listWorkspaceApps", () => {
|
|
|
1830
1831
|
}
|
|
1831
1832
|
});
|
|
1832
1833
|
|
|
1834
|
+
it("reads an app icon from the deployment manifest", async () => {
|
|
1835
|
+
stubNoPendingContext();
|
|
1836
|
+
stubManifest([
|
|
1837
|
+
{ id: "dispatch", name: "Dispatch", path: "/dispatch" },
|
|
1838
|
+
{ id: "notes", name: "Notes", path: "/notes", icon: " users " },
|
|
1839
|
+
]);
|
|
1840
|
+
|
|
1841
|
+
const apps = await runWithRequestContext(
|
|
1842
|
+
{ userEmail: "dev@example.test" },
|
|
1843
|
+
() => listWorkspaceApps({ includeAgentCards: false }),
|
|
1844
|
+
);
|
|
1845
|
+
|
|
1846
|
+
expect(apps.find((app) => app.id === "notes")?.icon).toBe("users");
|
|
1847
|
+
expect(apps.find((app) => app.id === "dispatch")).not.toHaveProperty(
|
|
1848
|
+
"icon",
|
|
1849
|
+
);
|
|
1850
|
+
});
|
|
1851
|
+
|
|
1852
|
+
function writeFilesystemWorkspace(
|
|
1853
|
+
workspaceRoot: string,
|
|
1854
|
+
appDirs: string[],
|
|
1855
|
+
files: Record<string, unknown> = {},
|
|
1856
|
+
) {
|
|
1857
|
+
fs.writeFileSync(
|
|
1858
|
+
path.join(workspaceRoot, "package.json"),
|
|
1859
|
+
JSON.stringify({
|
|
1860
|
+
name: "test-workspace",
|
|
1861
|
+
"agent-native": { workspaceCore: "workspace-core" },
|
|
1862
|
+
}),
|
|
1863
|
+
);
|
|
1864
|
+
for (const dir of appDirs) {
|
|
1865
|
+
const appDir = path.join(workspaceRoot, dir);
|
|
1866
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
1867
|
+
const id = path.basename(dir);
|
|
1868
|
+
fs.writeFileSync(
|
|
1869
|
+
path.join(appDir, "package.json"),
|
|
1870
|
+
JSON.stringify({ name: id, displayName: id }),
|
|
1871
|
+
);
|
|
1872
|
+
}
|
|
1873
|
+
for (const [file, value] of Object.entries(files)) {
|
|
1874
|
+
fs.mkdirSync(path.dirname(path.join(workspaceRoot, file)), {
|
|
1875
|
+
recursive: true,
|
|
1876
|
+
});
|
|
1877
|
+
fs.writeFileSync(path.join(workspaceRoot, file), JSON.stringify(value));
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
async function listFilesystemWorkspaceApps(workspaceRoot: string) {
|
|
1882
|
+
const cwdSpy = vi.spyOn(process, "cwd").mockReturnValue(workspaceRoot);
|
|
1883
|
+
try {
|
|
1884
|
+
stubNoPendingContext();
|
|
1885
|
+
vi.stubEnv("NODE_ENV", "test");
|
|
1886
|
+
vi.stubEnv("AGENT_NATIVE_WORKSPACE_APPS_JSON", "");
|
|
1887
|
+
mocks.readConfiguredWorkspaceAppHomePath.mockResolvedValue(undefined);
|
|
1888
|
+
return await runWithRequestContext(
|
|
1889
|
+
{ userEmail: "dev@example.test" },
|
|
1890
|
+
() => listWorkspaceApps({ includeAgentCards: false }),
|
|
1891
|
+
);
|
|
1892
|
+
} finally {
|
|
1893
|
+
cwdSpy.mockRestore();
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
it("discovers every app under apps/ without icons by default", async () => {
|
|
1898
|
+
const workspaceRoot = fs.mkdtempSync(
|
|
1899
|
+
path.join(os.tmpdir(), "dispatch-workspace-"),
|
|
1900
|
+
);
|
|
1901
|
+
try {
|
|
1902
|
+
writeFilesystemWorkspace(workspaceRoot, [
|
|
1903
|
+
"apps/dispatch",
|
|
1904
|
+
"apps/notes",
|
|
1905
|
+
"templates/elsewhere",
|
|
1906
|
+
]);
|
|
1907
|
+
|
|
1908
|
+
const apps = await listFilesystemWorkspaceApps(workspaceRoot);
|
|
1909
|
+
|
|
1910
|
+
expect(apps.map((app) => app.id)).toEqual(["dispatch", "notes"]);
|
|
1911
|
+
for (const app of apps) expect(app).not.toHaveProperty("icon");
|
|
1912
|
+
} finally {
|
|
1913
|
+
fs.rmSync(workspaceRoot, { recursive: true, force: true });
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
|
|
1917
|
+
it("honors the workspace app directory, include patterns, and icon overrides", async () => {
|
|
1918
|
+
const workspaceRoot = fs.mkdtempSync(
|
|
1919
|
+
path.join(os.tmpdir(), "dispatch-workspace-"),
|
|
1920
|
+
);
|
|
1921
|
+
try {
|
|
1922
|
+
writeFilesystemWorkspace(
|
|
1923
|
+
workspaceRoot,
|
|
1924
|
+
["apps/notes", "templates/notes-next", "templates/excluded"],
|
|
1925
|
+
{
|
|
1926
|
+
"agent-native.json": {
|
|
1927
|
+
deployment: {
|
|
1928
|
+
workspace: {
|
|
1929
|
+
appsDirectory: "templates",
|
|
1930
|
+
appInclude: ["*-next"],
|
|
1931
|
+
},
|
|
1932
|
+
},
|
|
1933
|
+
},
|
|
1934
|
+
".agent-native/workspace-apps.json": {
|
|
1935
|
+
apps: [{ id: "notes-next", path: "/notes-next", icon: "users" }],
|
|
1936
|
+
},
|
|
1937
|
+
},
|
|
1938
|
+
);
|
|
1939
|
+
|
|
1940
|
+
const apps = await listFilesystemWorkspaceApps(workspaceRoot);
|
|
1941
|
+
|
|
1942
|
+
expect(apps.map((app) => app.id)).toEqual(["notes-next"]);
|
|
1943
|
+
expect(apps[0]?.icon).toBe("users");
|
|
1944
|
+
} finally {
|
|
1945
|
+
fs.rmSync(workspaceRoot, { recursive: true, force: true });
|
|
1946
|
+
}
|
|
1947
|
+
});
|
|
1948
|
+
|
|
1833
1949
|
it("keeps healthy filesystem apps discoverable when config or routes cannot load", async () => {
|
|
1834
1950
|
const workspaceRoot = fs.mkdtempSync(
|
|
1835
1951
|
path.join(os.tmpdir(), "dispatch-workspace-"),
|
|
@@ -1888,6 +2004,39 @@ describe("listWorkspaceApps", () => {
|
|
|
1888
2004
|
}
|
|
1889
2005
|
});
|
|
1890
2006
|
|
|
2007
|
+
it("names an unloadable workspace config instead of listing a guessed apps directory", async () => {
|
|
2008
|
+
const workspaceRoot = fs.mkdtempSync(
|
|
2009
|
+
path.join(os.tmpdir(), "dispatch-workspace-"),
|
|
2010
|
+
);
|
|
2011
|
+
const cwdSpy = vi.spyOn(process, "cwd").mockReturnValue(workspaceRoot);
|
|
2012
|
+
try {
|
|
2013
|
+
writeFilesystemWorkspace(workspaceRoot, ["apps/healthy"]);
|
|
2014
|
+
fs.writeFileSync(
|
|
2015
|
+
path.join(workspaceRoot, "agent-native.config.ts"),
|
|
2016
|
+
"export default {\n",
|
|
2017
|
+
);
|
|
2018
|
+
stubNoPendingContext();
|
|
2019
|
+
vi.stubEnv("NODE_ENV", "test");
|
|
2020
|
+
|
|
2021
|
+
await expect(
|
|
2022
|
+
runWithRequestContext({ userEmail: "dev@example.test" }, () =>
|
|
2023
|
+
listWorkspaceApps({ includeAgentCards: false }),
|
|
2024
|
+
),
|
|
2025
|
+
).rejects.toMatchObject({
|
|
2026
|
+
name: "WorkspaceAppLayoutUnreadableError",
|
|
2027
|
+
message: expect.stringContaining(
|
|
2028
|
+
"The workspace config could not be loaded",
|
|
2029
|
+
),
|
|
2030
|
+
});
|
|
2031
|
+
await expect(getWorkspaceInfo()).rejects.toMatchObject({
|
|
2032
|
+
name: "WorkspaceAppLayoutUnreadableError",
|
|
2033
|
+
});
|
|
2034
|
+
} finally {
|
|
2035
|
+
cwdSpy.mockRestore();
|
|
2036
|
+
fs.rmSync(workspaceRoot, { recursive: true, force: true });
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
|
|
1891
2040
|
it("continues workspace root discovery past malformed ancestor package metadata", async () => {
|
|
1892
2041
|
const workspaceRoot = fs.mkdtempSync(
|
|
1893
2042
|
path.join(os.tmpdir(), "dispatch-workspace-"),
|
|
@@ -3499,6 +3648,38 @@ describe("startWorkspaceAppCreation", () => {
|
|
|
3499
3648
|
).rejects.toThrow("already registered");
|
|
3500
3649
|
});
|
|
3501
3650
|
|
|
3651
|
+
it("refuses to scaffold when only the TS config moves the apps directory", async () => {
|
|
3652
|
+
const workspaceRoot = fs.mkdtempSync(
|
|
3653
|
+
path.join(os.tmpdir(), "dispatch-workspace-"),
|
|
3654
|
+
);
|
|
3655
|
+
const cwd = vi.spyOn(process, "cwd").mockReturnValue(workspaceRoot);
|
|
3656
|
+
try {
|
|
3657
|
+
fs.writeFileSync(
|
|
3658
|
+
path.join(workspaceRoot, "package.json"),
|
|
3659
|
+
JSON.stringify({
|
|
3660
|
+
name: "test-workspace",
|
|
3661
|
+
"agent-native": { workspaceCore: "workspace-core" },
|
|
3662
|
+
}),
|
|
3663
|
+
);
|
|
3664
|
+
fs.writeFileSync(
|
|
3665
|
+
path.join(workspaceRoot, "agent-native.config.ts"),
|
|
3666
|
+
'export default { deployment: { workspace: { appsDirectory: "templates" } } };\n',
|
|
3667
|
+
);
|
|
3668
|
+
|
|
3669
|
+
await expect(
|
|
3670
|
+
runWithRequestContext(
|
|
3671
|
+
{ userEmail: "dev@example.test", orgId: "org-123" },
|
|
3672
|
+
() => scaffoldWorkspaceAppFromTemplate({ template: "mail" }),
|
|
3673
|
+
),
|
|
3674
|
+
).rejects.toThrow(/add-app cannot read/);
|
|
3675
|
+
expect(fs.existsSync(path.join(workspaceRoot, "apps"))).toBe(false);
|
|
3676
|
+
expect(fs.existsSync(path.join(workspaceRoot, "templates"))).toBe(false);
|
|
3677
|
+
} finally {
|
|
3678
|
+
cwd.mockRestore();
|
|
3679
|
+
fs.rmSync(workspaceRoot, { recursive: true, force: true });
|
|
3680
|
+
}
|
|
3681
|
+
});
|
|
3682
|
+
|
|
3502
3683
|
it("returns builder-error with the raw failure in detail when runBuilderAgent throws", async () => {
|
|
3503
3684
|
stubHostedRuntime();
|
|
3504
3685
|
stubBuilderProjectConfigured();
|
|
@@ -57,6 +57,10 @@ import {
|
|
|
57
57
|
type ConnectRequiredCard,
|
|
58
58
|
} from "@agent-native/core/shared";
|
|
59
59
|
import { resolveAccessMany } from "@agent-native/core/sharing";
|
|
60
|
+
import {
|
|
61
|
+
resolveScaffoldWorkspaceAppPaths,
|
|
62
|
+
resolveWorkspaceAppPaths,
|
|
63
|
+
} from "@agent-native/core/workspace-app-paths";
|
|
60
64
|
|
|
61
65
|
import { getDb } from "../../db/index.js";
|
|
62
66
|
import { workspaceAppRoute } from "../../shared/workspace-app-route.js";
|
|
@@ -167,6 +171,30 @@ class WorkspaceGatewayConfigurationError extends Error {
|
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
|
|
174
|
+
/**
|
|
175
|
+
* The workspace config that places its apps could not load. Discovery cannot
|
|
176
|
+
* guess another directory without listing the wrong apps, so it says why.
|
|
177
|
+
*/
|
|
178
|
+
export class WorkspaceAppLayoutUnreadableError extends Error {
|
|
179
|
+
constructor(cause: unknown) {
|
|
180
|
+
super(
|
|
181
|
+
`The workspace config could not be loaded, so its apps directory is unknown: ${
|
|
182
|
+
cause instanceof Error ? cause.message : String(cause)
|
|
183
|
+
}`,
|
|
184
|
+
{ cause },
|
|
185
|
+
);
|
|
186
|
+
this.name = "WorkspaceAppLayoutUnreadableError";
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function resolveDiscoveredWorkspaceAppPaths(workspaceRoot: string) {
|
|
191
|
+
try {
|
|
192
|
+
return await resolveWorkspaceAppPaths(workspaceRoot);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
throw new WorkspaceAppLayoutUnreadableError(error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
170
198
|
function requireWorkspaceAppOrgId(): string {
|
|
171
199
|
const orgId = currentOrgId();
|
|
172
200
|
if (!orgId) throw new WorkspaceAppOrgRequiredError();
|
|
@@ -244,6 +272,7 @@ type WorkspaceAppVisibility = "private" | "org";
|
|
|
244
272
|
|
|
245
273
|
export interface WorkspaceAppSummary {
|
|
246
274
|
id: string;
|
|
275
|
+
icon?: string;
|
|
247
276
|
name: string;
|
|
248
277
|
description: string;
|
|
249
278
|
whenToUse?: string[];
|
|
@@ -1032,6 +1061,9 @@ function parseWorkspaceAppsManifest(
|
|
|
1032
1061
|
}
|
|
1033
1062
|
return {
|
|
1034
1063
|
id,
|
|
1064
|
+
...(typeof entry.icon === "string" && entry.icon.trim()
|
|
1065
|
+
? { icon: entry.icon.trim() }
|
|
1066
|
+
: {}),
|
|
1035
1067
|
name:
|
|
1036
1068
|
typeof entry.name === "string" && entry.name.trim()
|
|
1037
1069
|
? entry.name.trim()
|
|
@@ -2347,16 +2379,56 @@ function readWorkspaceAppsFromManifestFile(): WorkspaceAppSummary[] | null {
|
|
|
2347
2379
|
return null;
|
|
2348
2380
|
}
|
|
2349
2381
|
|
|
2382
|
+
// The checked-in `.agent-native/workspace-apps.json` overrides are what a
|
|
2383
|
+
// workspace deploy copies into the served manifest; local discovery reads the
|
|
2384
|
+
// same `icon` so a local app shows the icon it will have once deployed. A file
|
|
2385
|
+
// that exists but cannot be read fails here as it fails the deploy.
|
|
2386
|
+
function readWorkspaceAppIconOverrides(
|
|
2387
|
+
workspaceRoot: string,
|
|
2388
|
+
): Map<string, string> {
|
|
2389
|
+
const file = path.join(
|
|
2390
|
+
workspaceRoot,
|
|
2391
|
+
".agent-native",
|
|
2392
|
+
WORKSPACE_APPS_MANIFEST_FILE,
|
|
2393
|
+
);
|
|
2394
|
+
const icons = new Map<string, string>();
|
|
2395
|
+
const parsed: unknown = readJson(file);
|
|
2396
|
+
if (parsed === null) return icons;
|
|
2397
|
+
const entries: unknown =
|
|
2398
|
+
typeof parsed === "object" && "apps" in parsed ? parsed.apps : parsed;
|
|
2399
|
+
if (!Array.isArray(entries)) {
|
|
2400
|
+
throw new Error(`${file} must contain an apps array.`);
|
|
2401
|
+
}
|
|
2402
|
+
for (const entry of entries) {
|
|
2403
|
+
if (
|
|
2404
|
+
entry &&
|
|
2405
|
+
typeof entry === "object" &&
|
|
2406
|
+
typeof entry.id === "string" &&
|
|
2407
|
+
typeof entry.icon === "string" &&
|
|
2408
|
+
entry.icon.trim()
|
|
2409
|
+
)
|
|
2410
|
+
icons.set(entry.id.trim(), entry.icon.trim());
|
|
2411
|
+
}
|
|
2412
|
+
return icons;
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2350
2415
|
async function readWorkspaceAppsFromFilesystem(
|
|
2351
2416
|
workspaceRoot: string,
|
|
2352
2417
|
): Promise<WorkspaceAppSummary[] | null> {
|
|
2353
|
-
const appsDir
|
|
2418
|
+
const { appsDir, includes } =
|
|
2419
|
+
await resolveDiscoveredWorkspaceAppPaths(workspaceRoot);
|
|
2354
2420
|
if (!fs.existsSync(appsDir)) return null;
|
|
2421
|
+
const icons = readWorkspaceAppIconOverrides(workspaceRoot);
|
|
2355
2422
|
|
|
2356
2423
|
const apps: WorkspaceAppSummary[] = [];
|
|
2357
2424
|
for (const entry of fs
|
|
2358
2425
|
.readdirSync(appsDir, { withFileTypes: true })
|
|
2359
|
-
.filter(
|
|
2426
|
+
.filter(
|
|
2427
|
+
(entry) =>
|
|
2428
|
+
entry.isDirectory() &&
|
|
2429
|
+
!entry.name.startsWith(".") &&
|
|
2430
|
+
includes(entry.name),
|
|
2431
|
+
)) {
|
|
2360
2432
|
const appDir = path.join(appsDir, entry.name);
|
|
2361
2433
|
let pkg: any;
|
|
2362
2434
|
try {
|
|
@@ -2385,8 +2457,10 @@ async function readWorkspaceAppsFromFilesystem(
|
|
|
2385
2457
|
);
|
|
2386
2458
|
continue;
|
|
2387
2459
|
}
|
|
2460
|
+
const icon = icons.get(entry.name);
|
|
2388
2461
|
apps.push({
|
|
2389
2462
|
id: entry.name,
|
|
2463
|
+
...(icon ? { icon } : {}),
|
|
2390
2464
|
name: pkg.displayName || titleCase(entry.name),
|
|
2391
2465
|
description: pkg.description || "",
|
|
2392
2466
|
path: `/${entry.name}`,
|
|
@@ -2418,7 +2492,7 @@ export function getEnvBuilderProjectId(): string | null {
|
|
|
2418
2492
|
);
|
|
2419
2493
|
}
|
|
2420
2494
|
|
|
2421
|
-
export function getWorkspaceInfo(): WorkspaceInfo {
|
|
2495
|
+
export async function getWorkspaceInfo(): Promise<WorkspaceInfo> {
|
|
2422
2496
|
const rootPath = findWorkspaceRoot();
|
|
2423
2497
|
if (!rootPath) {
|
|
2424
2498
|
return {
|
|
@@ -2436,12 +2510,13 @@ export function getWorkspaceInfo(): WorkspaceInfo {
|
|
|
2436
2510
|
typeof pkg?.displayName === "string" ? pkg.displayName.trim() : "";
|
|
2437
2511
|
const displayName = rawDisplay || (name ? titleCase(name) : null);
|
|
2438
2512
|
let appCount = 0;
|
|
2439
|
-
const appsDir
|
|
2513
|
+
const { appsDir, includes } =
|
|
2514
|
+
await resolveDiscoveredWorkspaceAppPaths(rootPath);
|
|
2440
2515
|
if (fs.existsSync(appsDir)) {
|
|
2441
2516
|
try {
|
|
2442
2517
|
appCount = fs
|
|
2443
2518
|
.readdirSync(appsDir, { withFileTypes: true })
|
|
2444
|
-
.filter((entry) => entry.isDirectory()).length;
|
|
2519
|
+
.filter((entry) => entry.isDirectory() && includes(entry.name)).length;
|
|
2445
2520
|
} catch {
|
|
2446
2521
|
appCount = 0;
|
|
2447
2522
|
}
|
|
@@ -2827,9 +2902,27 @@ export async function scaffoldWorkspaceAppFromTemplate(input: {
|
|
|
2827
2902
|
if (!workspaceRoot) {
|
|
2828
2903
|
throw new Error("No agent-native workspace detected for scaffolding.");
|
|
2829
2904
|
}
|
|
2830
|
-
|
|
2905
|
+
// `add-app` writes where agent-native.json points; discovery reads the full
|
|
2906
|
+
// config, so the two must agree or the new app is never found.
|
|
2907
|
+
const [{ appsDir, includes }, discovered] = await Promise.all([
|
|
2908
|
+
resolveScaffoldWorkspaceAppPaths(workspaceRoot),
|
|
2909
|
+
resolveDiscoveredWorkspaceAppPaths(workspaceRoot),
|
|
2910
|
+
]);
|
|
2911
|
+
if (discovered.appsDir !== appsDir) {
|
|
2912
|
+
throw new Error(
|
|
2913
|
+
`The workspace's apps directory is set only in agent-native.config.ts, which add-app cannot read. Set deployment.workspace.appsDirectory in agent-native.json too.`,
|
|
2914
|
+
);
|
|
2915
|
+
}
|
|
2916
|
+
if (!includes(appId) || !discovered.includes(appId)) {
|
|
2917
|
+
throw new Error(
|
|
2918
|
+
`App id ${appId} does not match the workspace appInclude patterns.`,
|
|
2919
|
+
);
|
|
2920
|
+
}
|
|
2921
|
+
const appDir = path.join(appsDir, appId);
|
|
2831
2922
|
if (fs.existsSync(appDir)) {
|
|
2832
|
-
throw new Error(
|
|
2923
|
+
throw new Error(
|
|
2924
|
+
`${path.relative(workspaceRoot, appDir) || appDir} already exists.`,
|
|
2925
|
+
);
|
|
2833
2926
|
}
|
|
2834
2927
|
|
|
2835
2928
|
const visibility = await workspaceAppDefaultVisibility();
|
|
@@ -26,6 +26,9 @@ const mocks = vi.hoisted(() => ({
|
|
|
26
26
|
managerStop: vi.fn(),
|
|
27
27
|
managerCallTool: vi.fn(),
|
|
28
28
|
managerConstructor: vi.fn(),
|
|
29
|
+
managerHasServer: vi.fn(),
|
|
30
|
+
managerGetTool: vi.fn(),
|
|
31
|
+
managerGetToolsForServer: vi.fn(),
|
|
29
32
|
a2aConstructor: vi.fn(),
|
|
30
33
|
a2aSend: vi.fn(),
|
|
31
34
|
a2aGetTask: vi.fn(),
|
|
@@ -107,6 +110,8 @@ vi.mock("@agent-native/core/org", () => ({
|
|
|
107
110
|
}));
|
|
108
111
|
|
|
109
112
|
vi.mock("@agent-native/core/mcp-client", () => ({
|
|
113
|
+
mcpToolCallWasNotSent: (error: unknown) =>
|
|
114
|
+
error instanceof Error && error.name === "NotSentFixture",
|
|
110
115
|
buildMcpToolName: (serverId: string, toolName: string) =>
|
|
111
116
|
`mcp__${serverId}__${toolName}`,
|
|
112
117
|
McpClientManager: class MockMcpClientManager {
|
|
@@ -129,22 +134,38 @@ vi.mock("@agent-native/core/mcp-client", () => ({
|
|
|
129
134
|
callTool(name: string, args: unknown) {
|
|
130
135
|
return mocks.managerCallTool(name, args);
|
|
131
136
|
}
|
|
137
|
+
|
|
138
|
+
hasServer(serverId: string) {
|
|
139
|
+
return mocks.managerHasServer(serverId);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getTool(name: string) {
|
|
143
|
+
return mocks.managerGetTool(name);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getToolsForServer(serverId: string) {
|
|
147
|
+
return mocks.managerGetToolsForServer(serverId);
|
|
148
|
+
}
|
|
132
149
|
},
|
|
133
150
|
}));
|
|
134
151
|
|
|
135
152
|
import { runWithRequestContext } from "@agent-native/core/server";
|
|
136
153
|
|
|
137
154
|
import {
|
|
155
|
+
callGrantedDispatchMcpAppAction,
|
|
138
156
|
createGrantedDispatchMcpEmbedSession,
|
|
139
157
|
createGrantedDispatchMcpEmbedSessionForWorkspaceAppChat,
|
|
140
158
|
createWorkspaceSsoEmbedSession,
|
|
141
159
|
createWorkspaceSsoEmbedSessionForWorkspaceAppChat,
|
|
142
160
|
askGrantedDispatchMcpApp,
|
|
143
161
|
getGrantedDispatchMcpAppTask,
|
|
162
|
+
listDispatchMcpApps,
|
|
163
|
+
listGrantedDispatchMcpAppActions,
|
|
144
164
|
listGrantedDispatchMcpApps,
|
|
145
165
|
listGrantedDispatchMcpAppOrigins,
|
|
146
166
|
openGrantedDispatchMcpApp,
|
|
147
167
|
resolveGrantedDispatchMcpApp,
|
|
168
|
+
setDispatchAppActionHeaderProvider,
|
|
148
169
|
} from "./mcp-gateway.js";
|
|
149
170
|
|
|
150
171
|
const analyticsAgent = {
|
|
@@ -194,6 +215,9 @@ beforeEach(() => {
|
|
|
194
215
|
mocks.managerStart.mockResolvedValue(undefined);
|
|
195
216
|
mocks.managerGetConnectErrorStatus.mockReturnValue(undefined);
|
|
196
217
|
mocks.managerStop.mockResolvedValue(undefined);
|
|
218
|
+
mocks.managerHasServer.mockReturnValue(true);
|
|
219
|
+
mocks.managerGetTool.mockReturnValue({ name: "mcp__target__get-project" });
|
|
220
|
+
mocks.managerGetToolsForServer.mockReturnValue([]);
|
|
197
221
|
mocks.managerCallTool.mockResolvedValue({
|
|
198
222
|
structuredContent: {
|
|
199
223
|
startUrl: "http://localhost:8086/_agent-native/embed/start?ticket=remote",
|
|
@@ -226,7 +250,237 @@ afterEach(() => {
|
|
|
226
250
|
vi.clearAllMocks();
|
|
227
251
|
});
|
|
228
252
|
|
|
253
|
+
describe("Dispatch direct app actions", () => {
|
|
254
|
+
const asOwner = <T>(work: () => Promise<T>) =>
|
|
255
|
+
runWithRequestContext(
|
|
256
|
+
{
|
|
257
|
+
userEmail: "owner@example.test",
|
|
258
|
+
requestOrigin: "http://localhost:8092",
|
|
259
|
+
},
|
|
260
|
+
work,
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
beforeEach(() => {
|
|
264
|
+
vi.stubEnv("A2A_SECRET", "test-only-secret");
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("refuses before resolving any app while the capability is off", async () => {
|
|
268
|
+
await expect(
|
|
269
|
+
asOwner(() => listGrantedDispatchMcpAppActions("analytics")),
|
|
270
|
+
).rejects.toMatchObject({ errorCode: "direct_app_actions_disabled" });
|
|
271
|
+
await expect(
|
|
272
|
+
asOwner(() =>
|
|
273
|
+
callGrantedDispatchMcpAppAction("analytics", "get-project", {}),
|
|
274
|
+
),
|
|
275
|
+
).rejects.toMatchObject({ errorCode: "direct_app_actions_disabled" });
|
|
276
|
+
expect(mocks.discoverAgents).not.toHaveBeenCalled();
|
|
277
|
+
expect(mocks.managerConstructor).not.toHaveBeenCalled();
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("lists a granted app's actions over a full-catalog user credential", async () => {
|
|
281
|
+
defineAppConfig({ dispatch: { directAppActions: true } });
|
|
282
|
+
mocks.managerGetToolsForServer.mockReturnValue([
|
|
283
|
+
{
|
|
284
|
+
originalName: "get-project",
|
|
285
|
+
description: "Read one project. Includes its members and settings.",
|
|
286
|
+
inputSchema: { type: "object" },
|
|
287
|
+
annotations: { readOnlyHint: true },
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
originalName: "create_embed_session",
|
|
291
|
+
description: "Embed handshake.",
|
|
292
|
+
inputSchema: { type: "object" },
|
|
293
|
+
},
|
|
294
|
+
]);
|
|
295
|
+
|
|
296
|
+
const actions = await asOwner(() =>
|
|
297
|
+
listGrantedDispatchMcpAppActions("analytics"),
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
expect(actions).toEqual([
|
|
301
|
+
{ name: "get-project", description: "Read one project.", readOnly: true },
|
|
302
|
+
]);
|
|
303
|
+
expect(mocks.signA2AToken).toHaveBeenCalledWith(
|
|
304
|
+
"owner@example.test",
|
|
305
|
+
undefined,
|
|
306
|
+
undefined,
|
|
307
|
+
expect.objectContaining({
|
|
308
|
+
extraClaims: expect.objectContaining({ catalog_scope: "full" }),
|
|
309
|
+
}),
|
|
310
|
+
);
|
|
311
|
+
expect(mocks.managerConstructor).toHaveBeenCalledWith({
|
|
312
|
+
servers: {
|
|
313
|
+
target: expect.objectContaining({
|
|
314
|
+
url: "http://localhost:8086/mcp",
|
|
315
|
+
headers: expect.objectContaining({
|
|
316
|
+
Authorization: "Bearer signed-token",
|
|
317
|
+
}),
|
|
318
|
+
}),
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
expect(mocks.managerStop).toHaveBeenCalled();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("calls one action of a granted app and returns its result", async () => {
|
|
325
|
+
defineAppConfig({ dispatch: { directAppActions: true } });
|
|
326
|
+
mocks.managerCallTool.mockResolvedValue({
|
|
327
|
+
structuredContent: { id: "fixture" },
|
|
328
|
+
content: [{ type: "text", text: '{"id":"fixture"}' }],
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const result = await asOwner(() =>
|
|
332
|
+
callGrantedDispatchMcpAppAction("analytics", "get-project", { id: "p" }),
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
expect(mocks.managerCallTool).toHaveBeenCalledWith(
|
|
336
|
+
"mcp__target__get-project",
|
|
337
|
+
{ id: "p" },
|
|
338
|
+
);
|
|
339
|
+
expect(result).toEqual({
|
|
340
|
+
structuredContent: { id: "fixture" },
|
|
341
|
+
content: [{ type: "text", text: '{"id":"fixture"}' }],
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("sends a deployment's per-call headers without letting them replace the credential", async () => {
|
|
346
|
+
defineAppConfig({ dispatch: { directAppActions: true } });
|
|
347
|
+
mocks.managerCallTool.mockResolvedValue({
|
|
348
|
+
content: [{ type: "text", text: "{}" }],
|
|
349
|
+
});
|
|
350
|
+
const provider = vi.fn(() => ({ "x-agent-native-turn-grant": "grant-1" }));
|
|
351
|
+
const remove = setDispatchAppActionHeaderProvider(provider);
|
|
352
|
+
try {
|
|
353
|
+
await asOwner(() =>
|
|
354
|
+
callGrantedDispatchMcpAppAction("analytics", "get-project", {}),
|
|
355
|
+
);
|
|
356
|
+
expect(provider).toHaveBeenCalledWith({
|
|
357
|
+
app: "analytics",
|
|
358
|
+
action: "get-project",
|
|
359
|
+
ownerEmail: "owner@example.test",
|
|
360
|
+
});
|
|
361
|
+
expect(mocks.managerConstructor).toHaveBeenCalledWith({
|
|
362
|
+
servers: {
|
|
363
|
+
target: expect.objectContaining({
|
|
364
|
+
headers: expect.objectContaining({
|
|
365
|
+
Authorization: "Bearer signed-token",
|
|
366
|
+
"x-agent-native-turn-grant": "grant-1",
|
|
367
|
+
}),
|
|
368
|
+
}),
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
provider.mockReturnValue({ authorization: "Bearer other" } as never);
|
|
373
|
+
await expect(
|
|
374
|
+
asOwner(() =>
|
|
375
|
+
callGrantedDispatchMcpAppAction("analytics", "get-project", {}),
|
|
376
|
+
),
|
|
377
|
+
).rejects.toThrow(/invalid "authorization" header/);
|
|
378
|
+
} finally {
|
|
379
|
+
remove();
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("refuses an app the caller has not granted", async () => {
|
|
384
|
+
defineAppConfig({ dispatch: { directAppActions: true } });
|
|
385
|
+
mocks.getUserSetting.mockResolvedValue({
|
|
386
|
+
mode: "selected-apps",
|
|
387
|
+
selectedAppIds: ["dispatch"],
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
await expect(
|
|
391
|
+
asOwner(() =>
|
|
392
|
+
callGrantedDispatchMcpAppAction("analytics", "get-project", {}),
|
|
393
|
+
),
|
|
394
|
+
).rejects.toThrow(/not granted/);
|
|
395
|
+
await expect(
|
|
396
|
+
asOwner(() => listGrantedDispatchMcpAppActions("analytics")),
|
|
397
|
+
).rejects.toThrow(/not granted/);
|
|
398
|
+
expect(mocks.managerConstructor).not.toHaveBeenCalled();
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it("rejects an unreadable upstream result rather than returning empty content", async () => {
|
|
402
|
+
defineAppConfig({ dispatch: { directAppActions: true } });
|
|
403
|
+
mocks.managerCallTool.mockResolvedValue({
|
|
404
|
+
structuredContent: { id: "fixture" },
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
await expect(
|
|
408
|
+
asOwner(() =>
|
|
409
|
+
callGrantedDispatchMcpAppAction("analytics", "get-project", {}),
|
|
410
|
+
),
|
|
411
|
+
).rejects.toMatchObject({ errorCode: "app_action_result_unreadable" });
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("warns that a write may have landed when the upstream call throws", async () => {
|
|
415
|
+
defineAppConfig({ dispatch: { directAppActions: true } });
|
|
416
|
+
mocks.managerCallTool.mockRejectedValue(new Error("socket hang up"));
|
|
417
|
+
|
|
418
|
+
const call = asOwner(() =>
|
|
419
|
+
callGrantedDispatchMcpAppAction("analytics", "get-project", {}),
|
|
420
|
+
);
|
|
421
|
+
await expect(call).rejects.toMatchObject({
|
|
422
|
+
errorCode: "app_action_outcome_unknown",
|
|
423
|
+
});
|
|
424
|
+
await expect(call).rejects.toThrow(/socket hang up.*inspect the app/);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it("tries the org-member fallback once when every credential is rejected", async () => {
|
|
428
|
+
defineAppConfig({ dispatch: { directAppActions: true } });
|
|
429
|
+
mocks.getOrgDomain.mockResolvedValue("builder.io");
|
|
430
|
+
mocks.getOrgA2ASecret.mockResolvedValue("org-specific-secret");
|
|
431
|
+
mocks.managerGetConnectErrorStatus.mockReturnValue(401);
|
|
432
|
+
|
|
433
|
+
await expect(
|
|
434
|
+
runWithRequestContext(
|
|
435
|
+
{
|
|
436
|
+
userEmail: "owner@example.test",
|
|
437
|
+
orgId: "org-1",
|
|
438
|
+
requestOrigin: "http://localhost:8092",
|
|
439
|
+
},
|
|
440
|
+
() => callGrantedDispatchMcpAppAction("analytics", "get-project", {}),
|
|
441
|
+
),
|
|
442
|
+
).rejects.toThrow("The analytics app rejected this connection.");
|
|
443
|
+
expect(mocks.signA2AOrgMemberDelegationToken).toHaveBeenCalledTimes(1);
|
|
444
|
+
expect(mocks.managerConstructor).toHaveBeenCalledTimes(2);
|
|
445
|
+
expect(mocks.managerCallTool).not.toHaveBeenCalled();
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it("reports a refusal raised before sending as not run, not as an uncertain write", async () => {
|
|
449
|
+
defineAppConfig({ dispatch: { directAppActions: true } });
|
|
450
|
+
const refusal = Object.assign(new Error("Not authorized"), {
|
|
451
|
+
name: "NotSentFixture",
|
|
452
|
+
statusCode: 403,
|
|
453
|
+
});
|
|
454
|
+
mocks.managerCallTool.mockRejectedValue(refusal);
|
|
455
|
+
|
|
456
|
+
const error = await asOwner(() =>
|
|
457
|
+
callGrantedDispatchMcpAppAction("analytics", "get-project", {}),
|
|
458
|
+
).catch((caught: unknown) => caught);
|
|
459
|
+
expect(error).toMatchObject({
|
|
460
|
+
errorCode: "app_action_not_sent",
|
|
461
|
+
statusCode: 403,
|
|
462
|
+
});
|
|
463
|
+
expect((error as Error).message).toMatch(/did not run \(Not authorized\)/);
|
|
464
|
+
expect((error as Error).message).not.toMatch(/outcome may be unknown/);
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
|
|
229
468
|
describe("Dispatch MCP gateway app discovery", () => {
|
|
469
|
+
it("lists a discovered app without a description as an empty description", async () => {
|
|
470
|
+
const { description: _omitted, ...agent } = analyticsAgent;
|
|
471
|
+
mocks.discoverAgents.mockResolvedValue([agent]);
|
|
472
|
+
|
|
473
|
+
const { apps } = await runWithRequestContext(
|
|
474
|
+
{
|
|
475
|
+
userEmail: "owner@example.test",
|
|
476
|
+
requestOrigin: "http://localhost:8092",
|
|
477
|
+
},
|
|
478
|
+
() => listDispatchMcpApps(),
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
expect(apps.find((app) => app.id === "analytics")?.description).toBe("");
|
|
482
|
+
});
|
|
483
|
+
|
|
230
484
|
it("keeps discovered agents available when mounted app lookup fails", async () => {
|
|
231
485
|
mocks.listWorkspaceApps.mockRejectedValue({ status: 503 });
|
|
232
486
|
|