@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
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
import { createMCPServerForRequest } from "@agent-native/core/mcp";
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
const requireCore = createRequire(
|
|
7
|
+
new URL("../../../core/package.json", import.meta.url),
|
|
8
|
+
);
|
|
9
|
+
const { Client } = requireCore("@modelcontextprotocol/client");
|
|
10
|
+
const { InMemoryTransport } = requireCore("@modelcontextprotocol/server");
|
|
11
|
+
|
|
12
|
+
const mocks = vi.hoisted(() => ({
|
|
13
|
+
listActions: vi.fn(),
|
|
14
|
+
callAction: vi.fn(),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
vi.mock("../server/lib/mcp-gateway.js", () => ({
|
|
18
|
+
listGrantedDispatchMcpAppActions: mocks.listActions,
|
|
19
|
+
callGrantedDispatchMcpAppAction: mocks.callAction,
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
vi.mock("../../../core/src/server/action-change-marker-write.js", () => ({
|
|
23
|
+
writeActionChangeMarker: vi.fn(async () => {}),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
import callAppAction from "./call_app_action.js";
|
|
27
|
+
import listAppActions from "./list_app_actions.js";
|
|
28
|
+
import readView from "./read_view.js";
|
|
29
|
+
|
|
30
|
+
const ctx = { caller: "mcp" } as never;
|
|
31
|
+
|
|
32
|
+
describe("app action tools", () => {
|
|
33
|
+
beforeEach(() => vi.clearAllMocks());
|
|
34
|
+
|
|
35
|
+
it("lists a granted app's actions", async () => {
|
|
36
|
+
mocks.listActions.mockResolvedValue([
|
|
37
|
+
{ name: "list-emails", description: "Inbox", inputSchema: {} },
|
|
38
|
+
]);
|
|
39
|
+
const result = await listAppActions.run({ app: "mail" } as never, ctx);
|
|
40
|
+
expect(mocks.listActions).toHaveBeenCalledWith("mail", undefined);
|
|
41
|
+
expect(result).toEqual({
|
|
42
|
+
app: "mail",
|
|
43
|
+
actions: [{ name: "list-emails", description: "Inbox", inputSchema: {} }],
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("calls one action with its args and defaults to none", async () => {
|
|
48
|
+
mocks.callAction.mockResolvedValue({ content: [] });
|
|
49
|
+
await callAppAction.run(
|
|
50
|
+
{ app: "mail", action: "list-emails", args: { limit: 5 } } as never,
|
|
51
|
+
ctx,
|
|
52
|
+
);
|
|
53
|
+
expect(mocks.callAction).toHaveBeenCalledWith("mail", "list-emails", {
|
|
54
|
+
limit: 5,
|
|
55
|
+
});
|
|
56
|
+
await callAppAction.run(
|
|
57
|
+
{ app: "calendar", action: "list-events" } as never,
|
|
58
|
+
ctx,
|
|
59
|
+
);
|
|
60
|
+
expect(mocks.callAction).toHaveBeenLastCalledWith(
|
|
61
|
+
"calendar",
|
|
62
|
+
"list-events",
|
|
63
|
+
{},
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("returns complete forwarded payloads through the MCP transport", async () => {
|
|
68
|
+
const payload = { decks: [{ id: "fixture-deck", body: "x".repeat(5000) }] };
|
|
69
|
+
const forwarded = {
|
|
70
|
+
structuredContent: payload,
|
|
71
|
+
content: [{ type: "text", text: JSON.stringify(payload) }],
|
|
72
|
+
};
|
|
73
|
+
mocks.callAction.mockResolvedValue(forwarded);
|
|
74
|
+
const server = await createMCPServerForRequest(
|
|
75
|
+
{
|
|
76
|
+
name: "dispatch-transport-test",
|
|
77
|
+
version: "1.0.0",
|
|
78
|
+
catalogMode: "app",
|
|
79
|
+
builtinCrossAppTools: false,
|
|
80
|
+
actions: { call_app_action: callAppAction },
|
|
81
|
+
},
|
|
82
|
+
undefined,
|
|
83
|
+
);
|
|
84
|
+
const client = new Client({ name: "transport-test", version: "1.0.0" });
|
|
85
|
+
const [clientTransport, serverTransport] =
|
|
86
|
+
InMemoryTransport.createLinkedPair();
|
|
87
|
+
await Promise.all([
|
|
88
|
+
client.connect(clientTransport),
|
|
89
|
+
server.connect(serverTransport),
|
|
90
|
+
]);
|
|
91
|
+
try {
|
|
92
|
+
const result = await client.callTool({
|
|
93
|
+
name: "call_app_action",
|
|
94
|
+
arguments: { app: "slides", action: "list-decks" },
|
|
95
|
+
});
|
|
96
|
+
expect(result.isError).not.toBe(true);
|
|
97
|
+
expect(result.structuredContent).toEqual(forwarded);
|
|
98
|
+
mocks.callAction.mockResolvedValue({
|
|
99
|
+
isError: true,
|
|
100
|
+
content: [{ type: "text", text: "Provider rejected the action" }],
|
|
101
|
+
});
|
|
102
|
+
const failure = await client.callTool({
|
|
103
|
+
name: "call_app_action",
|
|
104
|
+
arguments: { app: "slides", action: "list-decks" },
|
|
105
|
+
});
|
|
106
|
+
expect(failure.isError).toBe(true);
|
|
107
|
+
} finally {
|
|
108
|
+
await client.close();
|
|
109
|
+
await server.close();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("is not a read-only tool and carries no app panel", () => {
|
|
114
|
+
expect(callAppAction.readOnly).not.toBe(true);
|
|
115
|
+
expect(callAppAction.mcpApp?.resource).toBeUndefined();
|
|
116
|
+
expect(listAppActions.readOnly).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("passes the app's real error code through instead of a generic failure", async () => {
|
|
120
|
+
mocks.callAction.mockResolvedValue({
|
|
121
|
+
isError: true,
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
type: "text",
|
|
125
|
+
text: "Error: Google Calendar requests are paused for this deployment. (errorCode: google_calendar_paused)",
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
const error = await callAppAction
|
|
130
|
+
.run({ app: "calendar", action: "create-event", args: {} } as never, ctx)
|
|
131
|
+
.catch((caught: Error) => caught);
|
|
132
|
+
expect(error).toMatchObject({ errorCode: "google_calendar_paused" });
|
|
133
|
+
expect((error as Error).message).toMatch(
|
|
134
|
+
/paused for this deployment\. Its write outcome may be unknown; inspect the app before retrying\.$/,
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("reports an approval wait as approval_required with one errorCode", async () => {
|
|
139
|
+
mocks.callAction.mockResolvedValue({
|
|
140
|
+
isError: true,
|
|
141
|
+
approvalReview: { url: "https://app.example.test/approvals/1" },
|
|
142
|
+
content: [
|
|
143
|
+
{
|
|
144
|
+
type: "text",
|
|
145
|
+
text: "manage-event is waiting for the user's decision on its review page: https://app.example.test/approvals/1",
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
await expect(
|
|
150
|
+
callAppAction.run(
|
|
151
|
+
{ app: "calendar", action: "manage-event", args: {} } as never,
|
|
152
|
+
ctx,
|
|
153
|
+
),
|
|
154
|
+
).rejects.toMatchObject({
|
|
155
|
+
errorCode: "approval_required",
|
|
156
|
+
details: {
|
|
157
|
+
approvalReview: { url: "https://app.example.test/approvals/1" },
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
mocks.callAction.mockResolvedValue({
|
|
161
|
+
isError: true,
|
|
162
|
+
content: [
|
|
163
|
+
{
|
|
164
|
+
type: "text",
|
|
165
|
+
text: "Paused. (errorCode: x_paused) (errorCode: x_paused)",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
});
|
|
169
|
+
const err = await callAppAction
|
|
170
|
+
.run({ app: "a", action: "b", args: {} } as never, ctx)
|
|
171
|
+
.catch((e: Error) => e);
|
|
172
|
+
expect(
|
|
173
|
+
(err as Error).message.match(/errorCode/g)?.length ?? 0,
|
|
174
|
+
).toBeLessThanOrEqual(1);
|
|
175
|
+
});
|
|
176
|
+
it("reads the app's current view through its view-screen action", async () => {
|
|
177
|
+
mocks.callAction.mockResolvedValue({
|
|
178
|
+
content: [{ type: "text", text: "{}" }],
|
|
179
|
+
structuredContent: { mailWorkspace: { openOverlay: "composer" } },
|
|
180
|
+
});
|
|
181
|
+
const result = await readView.run({ app: "mail" } as never, ctx);
|
|
182
|
+
expect(mocks.callAction).toHaveBeenCalledWith("mail", "view-screen", {});
|
|
183
|
+
expect(result).toEqual({
|
|
184
|
+
app: "mail",
|
|
185
|
+
view: { mailWorkspace: { openOverlay: "composer" } },
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("fails loudly when the app cannot report its view", async () => {
|
|
190
|
+
mocks.callAction.mockResolvedValue({
|
|
191
|
+
isError: true,
|
|
192
|
+
content: [{ type: "text", text: "Mail is not open." }],
|
|
193
|
+
});
|
|
194
|
+
await expect(
|
|
195
|
+
readView.run({ app: "mail" } as never, ctx),
|
|
196
|
+
).rejects.toMatchObject({ errorCode: "view_unavailable" });
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineAction, fail } from "@agent-native/core/action";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
appActionErrorCode,
|
|
6
|
+
appActionResultText,
|
|
7
|
+
} from "../server/lib/app-action-result.js";
|
|
8
|
+
import { callGrantedDispatchMcpAppAction } from "../server/lib/mcp-gateway.js";
|
|
9
|
+
|
|
10
|
+
export default defineAction({
|
|
11
|
+
description:
|
|
12
|
+
"Run one action of a granted app as the signed-in user and return its result in about a second. Prefer this to ask_app whenever the step is a known action (list the inbox, read a thread, create a draft, list or move an event); ask_app runs the app's whole agent and takes 20 seconds or more. Call list_app_actions first for names and inputs. The app's screen updates from the same data, so call open_app once to show it beside the chat.",
|
|
13
|
+
schema: z.object({
|
|
14
|
+
app: z.string().describe("Granted app id, e.g. mail or calendar."),
|
|
15
|
+
action: z
|
|
16
|
+
.string()
|
|
17
|
+
.describe("Action name from list_app_actions, e.g. list-emails."),
|
|
18
|
+
args: z
|
|
19
|
+
.record(z.string(), z.unknown())
|
|
20
|
+
.optional()
|
|
21
|
+
.describe("Action input matching its schema."),
|
|
22
|
+
}),
|
|
23
|
+
mcpOutputSchema: true,
|
|
24
|
+
outputErrorStrategy: "strict",
|
|
25
|
+
outputSchema: z.object({
|
|
26
|
+
isError: z.boolean().optional(),
|
|
27
|
+
approvalReview: z
|
|
28
|
+
.object({ url: z.string().optional(), expiresAt: z.number().optional() })
|
|
29
|
+
.optional(),
|
|
30
|
+
structuredContent: z.unknown().optional(),
|
|
31
|
+
content: z.array(z.unknown()),
|
|
32
|
+
}),
|
|
33
|
+
mcpApp: { structuredContent: true },
|
|
34
|
+
run: async ({ app, action, args }) => {
|
|
35
|
+
const result = await callGrantedDispatchMcpAppAction(
|
|
36
|
+
app,
|
|
37
|
+
action,
|
|
38
|
+
args ?? {},
|
|
39
|
+
);
|
|
40
|
+
if (result.isError !== true) return result;
|
|
41
|
+
const text = appActionResultText(result);
|
|
42
|
+
if (result.approvalReview) {
|
|
43
|
+
fail(text, {
|
|
44
|
+
errorCode: "approval_required",
|
|
45
|
+
statusCode: 409,
|
|
46
|
+
details: { approvalReview: result.approvalReview },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const appCode = appActionErrorCode(text);
|
|
50
|
+
const message = appCode
|
|
51
|
+
? text.replace(/(\s*\(errorCode: [a-z0-9_]+\))+\s*$/i, "")
|
|
52
|
+
: text || "The app action failed.";
|
|
53
|
+
// A failed write can still have landed part of its change in the app.
|
|
54
|
+
fail(
|
|
55
|
+
`${message} Its write outcome may be unknown; inspect the app before retrying.`,
|
|
56
|
+
{ errorCode: appCode ?? "app_action_failed", statusCode: 502 },
|
|
57
|
+
);
|
|
58
|
+
},
|
|
59
|
+
});
|
|
@@ -1,6 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
defineAppConfig,
|
|
3
|
+
resetAppConfigForTests,
|
|
4
|
+
} from "@agent-native/core/app-config";
|
|
5
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
6
|
|
|
3
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
dispatchActions,
|
|
9
|
+
dispatchDirectAppActions,
|
|
10
|
+
resolveDispatchActions,
|
|
11
|
+
} from "./index.js";
|
|
12
|
+
|
|
13
|
+
const DIRECT_APP_ACTION_NAMES = [
|
|
14
|
+
"call_app_action",
|
|
15
|
+
"list_app_actions",
|
|
16
|
+
"read_view",
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
describe("dispatch direct app actions", () => {
|
|
20
|
+
afterEach(() => resetAppConfigForTests());
|
|
21
|
+
|
|
22
|
+
it("serves exactly the default registry while the capability is off", () => {
|
|
23
|
+
const actions = resolveDispatchActions();
|
|
24
|
+
|
|
25
|
+
expect(actions).toBe(dispatchActions);
|
|
26
|
+
for (const name of DIRECT_APP_ACTION_NAMES) {
|
|
27
|
+
expect(actions).not.toHaveProperty(name);
|
|
28
|
+
}
|
|
29
|
+
expect(actions.ask_app.tool.description).not.toContain("call_app_action");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("adds the direct tools and points ask_app at them when enabled", () => {
|
|
33
|
+
defineAppConfig({ dispatch: { directAppActions: true } });
|
|
34
|
+
|
|
35
|
+
const actions = resolveDispatchActions();
|
|
36
|
+
|
|
37
|
+
expect(Object.keys(dispatchDirectAppActions).sort()).toEqual(
|
|
38
|
+
DIRECT_APP_ACTION_NAMES,
|
|
39
|
+
);
|
|
40
|
+
for (const name of DIRECT_APP_ACTION_NAMES) {
|
|
41
|
+
expect(actions[name]).toBe(dispatchDirectAppActions[name]);
|
|
42
|
+
}
|
|
43
|
+
expect(actions.ask_app.run).toBe(dispatchActions.ask_app.run);
|
|
44
|
+
expect(actions.ask_app.tool.description).toContain(
|
|
45
|
+
"prefer list_app_actions and call_app_action",
|
|
46
|
+
);
|
|
47
|
+
expect(dispatchActions.ask_app.tool.description).not.toContain(
|
|
48
|
+
"call_app_action",
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
4
52
|
|
|
5
53
|
describe("dispatch action registry", () => {
|
|
6
54
|
it("keeps workspace resources runtime-inherited instead of exposing sync actions", () => {
|
package/src/actions/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getAppConfig } from "@agent-native/core/app-config";
|
|
1
2
|
import type { ActionEntry } from "@agent-native/core/server";
|
|
2
3
|
|
|
3
4
|
import applyDreamProposal from "./apply-dream-proposal.js";
|
|
@@ -6,6 +7,7 @@ import approveVaultRequest from "./approve-vault-request.js";
|
|
|
6
7
|
import archiveWorkspaceApp from "./archive-workspace-app.js";
|
|
7
8
|
import askApp from "./ask_app.js";
|
|
8
9
|
import askAppStatus from "./ask_app_status.js";
|
|
10
|
+
import callAppAction from "./call_app_action.js";
|
|
9
11
|
import claimWorkspaceAppOrganization from "./claim-workspace-app-organization.js";
|
|
10
12
|
import connectExternalAgent from "./connect-external-agent.js";
|
|
11
13
|
import createBrowserChatSession from "./create-browser-chat-session.js";
|
|
@@ -70,6 +72,7 @@ import listWorkspaceResourceGrants from "./list-workspace-resource-grants.js";
|
|
|
70
72
|
import listWorkspaceResourceOptions from "./list-workspace-resource-options.js";
|
|
71
73
|
import listWorkspaceResourcesForApp from "./list-workspace-resources-for-app.js";
|
|
72
74
|
import listWorkspaceResources from "./list-workspace-resources.js";
|
|
75
|
+
import listAppActions from "./list_app_actions.js";
|
|
73
76
|
import listApps from "./list_apps.js";
|
|
74
77
|
import navigate from "./navigate.js";
|
|
75
78
|
import openApp from "./open_app.js";
|
|
@@ -81,6 +84,7 @@ import providerApiRegister from "./provider-api-register.js";
|
|
|
81
84
|
import providerApiRequest from "./provider-api-request.js";
|
|
82
85
|
import queryStagedDataset from "./query-staged-dataset.js";
|
|
83
86
|
import readSlackThreadContext from "./read-slack-thread-context.js";
|
|
87
|
+
import readView from "./read_view.js";
|
|
84
88
|
import rejectDispatchChange from "./reject-dispatch-change.js";
|
|
85
89
|
import rejectDreamProposal from "./reject-dream-proposal.js";
|
|
86
90
|
import remixWorkspaceTemplate from "./remix-workspace-template.js";
|
|
@@ -222,3 +226,33 @@ export const dispatchActions: Record<string, ActionEntry> = {
|
|
|
222
226
|
"verify-curated-community-app": verifyCuratedCommunityApp,
|
|
223
227
|
"view-screen": viewScreen,
|
|
224
228
|
};
|
|
229
|
+
|
|
230
|
+
/** Opt-in tools that run a granted app's actions directly, without its agent. */
|
|
231
|
+
export const dispatchDirectAppActions: Record<string, ActionEntry> = {
|
|
232
|
+
call_app_action: callAppAction,
|
|
233
|
+
list_app_actions: listAppActions,
|
|
234
|
+
read_view: readView,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const ASK_APP_DIRECT_ACTIONS_HINT =
|
|
238
|
+
" For a known step prefer list_app_actions and call_app_action, which skip the app's agent and return in about a second.";
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* The actions Dispatch serves to its own agent and MCP callers. Direct app
|
|
242
|
+
* actions join only when `dispatch.directAppActions` is on; otherwise this is
|
|
243
|
+
* exactly `dispatchActions`.
|
|
244
|
+
*/
|
|
245
|
+
export function resolveDispatchActions(): Record<string, ActionEntry> {
|
|
246
|
+
if (!getAppConfig().dispatch.directAppActions) return dispatchActions;
|
|
247
|
+
return {
|
|
248
|
+
...dispatchActions,
|
|
249
|
+
ask_app: {
|
|
250
|
+
...askApp,
|
|
251
|
+
tool: {
|
|
252
|
+
...askApp.tool,
|
|
253
|
+
description: `${askApp.tool.description}${ASK_APP_DIRECT_ACTIONS_HINT}`,
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
...dispatchDirectAppActions,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineAction } from "@agent-native/core/action";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import { listGrantedDispatchMcpAppActions } from "../server/lib/mcp-gateway.js";
|
|
5
|
+
|
|
6
|
+
export default defineAction({
|
|
7
|
+
description:
|
|
8
|
+
"List the actions a granted app exposes (read inbox, create draft, move event, and so on) as names and one-line descriptions. Pass names to get full input schemas for just those actions. Call before call_app_action; results are fast, unlike ask_app.",
|
|
9
|
+
schema: z.object({
|
|
10
|
+
app: z.string().describe("Granted app id, e.g. mail or calendar."),
|
|
11
|
+
names: z
|
|
12
|
+
.array(z.string())
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Action names to return full input schemas for."),
|
|
15
|
+
}),
|
|
16
|
+
outputSchema: z.object({
|
|
17
|
+
app: z.string(),
|
|
18
|
+
actions: z.array(
|
|
19
|
+
z.object({
|
|
20
|
+
name: z.string(),
|
|
21
|
+
description: z.string(),
|
|
22
|
+
inputSchema: z.record(z.string(), z.unknown()).optional(),
|
|
23
|
+
readOnly: z.boolean().optional(),
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
}),
|
|
27
|
+
readOnly: true,
|
|
28
|
+
parallelSafe: true,
|
|
29
|
+
run: async ({ app, names }) => ({
|
|
30
|
+
app,
|
|
31
|
+
actions: await listGrantedDispatchMcpAppActions(app, names),
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { defineAction, fail } from "@agent-native/core/action";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
appActionErrorCode,
|
|
6
|
+
appActionResultText,
|
|
7
|
+
} from "../server/lib/app-action-result.js";
|
|
8
|
+
import { callGrantedDispatchMcpAppAction } from "../server/lib/mcp-gateway.js";
|
|
9
|
+
|
|
10
|
+
export default defineAction({
|
|
11
|
+
description:
|
|
12
|
+
"Read what the user is looking at in a granted app right now: the open screen, selection, and any open composer or draft, including edits not yet saved. Call it before answering questions like 'what does my draft say now?'. Fast; use after the user edits in the app view.",
|
|
13
|
+
schema: z.object({
|
|
14
|
+
app: z.string().describe("Granted app id, e.g. mail or calendar."),
|
|
15
|
+
}),
|
|
16
|
+
outputSchema: z.object({ app: z.string(), view: z.unknown() }),
|
|
17
|
+
readOnly: true,
|
|
18
|
+
parallelSafe: true,
|
|
19
|
+
run: async ({ app }) => {
|
|
20
|
+
const result = await callGrantedDispatchMcpAppAction(
|
|
21
|
+
app,
|
|
22
|
+
"view-screen",
|
|
23
|
+
{},
|
|
24
|
+
);
|
|
25
|
+
const text = appActionResultText(result);
|
|
26
|
+
if (result.isError === true) {
|
|
27
|
+
fail(text || "The app could not report its current view.", {
|
|
28
|
+
errorCode: appActionErrorCode(text) ?? "view_unavailable",
|
|
29
|
+
statusCode: 502,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (result.structuredContent !== undefined) {
|
|
33
|
+
return { app, view: result.structuredContent };
|
|
34
|
+
}
|
|
35
|
+
let view: unknown;
|
|
36
|
+
try {
|
|
37
|
+
view = JSON.parse(text);
|
|
38
|
+
} catch {
|
|
39
|
+
fail("The app returned a view that could not be read.", {
|
|
40
|
+
errorCode: "view_unreadable",
|
|
41
|
+
statusCode: 502,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return { app, view };
|
|
45
|
+
},
|
|
46
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { UsageAlertRule } from "@agent-native/core";
|
|
2
|
+
import { commercialSurfacesHidden } from "@agent-native/core/client/app-config";
|
|
2
3
|
import {
|
|
3
4
|
useActionMutation,
|
|
4
5
|
useActionQuery,
|
|
@@ -35,6 +36,17 @@ interface UsageAlertsPanelProps {
|
|
|
35
36
|
type AlertUnit = "usd" | "builder-credits" | "tokens";
|
|
36
37
|
type AlertChannel = "in-app" | "email";
|
|
37
38
|
|
|
39
|
+
/** Units a rule can be created in; credits are left out where the deployment hides them. */
|
|
40
|
+
export function alertUnitOptions(): Array<{ value: AlertUnit; label: string }> {
|
|
41
|
+
return [
|
|
42
|
+
{ value: "usd", label: "Dollars" },
|
|
43
|
+
...(commercialSurfacesHidden()
|
|
44
|
+
? []
|
|
45
|
+
: [{ value: "builder-credits" as const, label: "Credits" }]),
|
|
46
|
+
{ value: "tokens", label: "Tokens" },
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
|
|
38
50
|
interface AlertDraft {
|
|
39
51
|
ruleId?: string;
|
|
40
52
|
appId: string;
|
|
@@ -147,9 +159,11 @@ function AlertEditor({
|
|
|
147
159
|
<SelectValue />
|
|
148
160
|
</SelectTrigger>
|
|
149
161
|
<SelectContent>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
{alertUnitOptions().map((option) => (
|
|
163
|
+
<SelectItem key={option.value} value={option.value}>
|
|
164
|
+
{option.label}
|
|
165
|
+
</SelectItem>
|
|
166
|
+
))}
|
|
153
167
|
</SelectContent>
|
|
154
168
|
</Select>
|
|
155
169
|
</label>
|
package/src/server/index.ts
CHANGED
|
@@ -11,6 +11,11 @@ export {
|
|
|
11
11
|
listOrganizationVisibleWorkspaceApps,
|
|
12
12
|
listWorkspaceApps,
|
|
13
13
|
} from "./lib/app-creation-store.js";
|
|
14
|
+
export {
|
|
15
|
+
setDispatchAppActionHeaderProvider,
|
|
16
|
+
type DispatchAppActionHeaderProvider,
|
|
17
|
+
type DispatchAppActionRequest,
|
|
18
|
+
} from "./lib/mcp-gateway.js";
|
|
14
19
|
export {
|
|
15
20
|
invalidateOrgAppsDirectoryCache,
|
|
16
21
|
orgAppsDirectoryAccessCache,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GrantedAppActionResult } from "./mcp-gateway.js";
|
|
2
|
+
|
|
3
|
+
export function appActionResultText(result: GrantedAppActionResult): string {
|
|
4
|
+
return result.content
|
|
5
|
+
.map((part) =>
|
|
6
|
+
part !== null &&
|
|
7
|
+
typeof part === "object" &&
|
|
8
|
+
"text" in part &&
|
|
9
|
+
typeof part.text === "string"
|
|
10
|
+
? part.text
|
|
11
|
+
: "",
|
|
12
|
+
)
|
|
13
|
+
.join(" ")
|
|
14
|
+
.trim();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function appActionErrorCode(text: string): string | undefined {
|
|
18
|
+
return /errorCode: ([a-z0-9_]+)/i.exec(text)?.[1];
|
|
19
|
+
}
|