@agent-native/dispatch 0.30.2 → 0.30.3
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/dist/actions/ask_app.d.ts +1 -0
- package/dist/actions/ask_app_status.d.ts +1 -0
- package/dist/server/lib/dispatch-integrations.d.ts.map +1 -1
- package/dist/server/lib/dispatch-integrations.js +149 -7
- package/dist/server/lib/dispatch-integrations.js.map +1 -1
- package/dist/server/lib/dispatch-store.d.ts +1 -0
- package/dist/server/lib/dispatch-store.d.ts.map +1 -1
- package/dist/server/lib/dispatch-store.js +4 -0
- package/dist/server/lib/dispatch-store.js.map +1 -1
- package/dist/server/lib/mcp-gateway.d.ts +8 -2
- package/dist/server/lib/mcp-gateway.d.ts.map +1 -1
- package/dist/server/lib/mcp-gateway.js +39 -6
- package/dist/server/lib/mcp-gateway.js.map +1 -1
- package/package.json +3 -3
- package/src/server/lib/dispatch-integrations.spec.ts +578 -7
- package/src/server/lib/dispatch-integrations.ts +186 -9
- package/src/server/lib/dispatch-store.ts +7 -0
- package/src/server/lib/mcp-gateway.spec.ts +328 -17
- package/src/server/lib/mcp-gateway.ts +59 -4
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
A2AClient,
|
|
3
3
|
canonicalA2AAudience,
|
|
4
|
+
extractA2APersistedMutationReceipts,
|
|
4
5
|
signA2AToken,
|
|
6
|
+
stripA2APersistedArtifactMarkers,
|
|
7
|
+
type A2APersistedMutationReceipt,
|
|
5
8
|
type Task,
|
|
6
9
|
} from "@agent-native/core/a2a";
|
|
7
10
|
import { isFeatureFlagEnabled } from "@agent-native/core/feature-flags";
|
|
@@ -107,6 +110,39 @@ function dispatchTaskText(task: Task): string {
|
|
|
107
110
|
);
|
|
108
111
|
}
|
|
109
112
|
|
|
113
|
+
type DispatchMutationReceipt = A2APersistedMutationReceipt;
|
|
114
|
+
|
|
115
|
+
function dispatchTaskMutationReceipts(
|
|
116
|
+
task: Task,
|
|
117
|
+
app: string,
|
|
118
|
+
identity: {
|
|
119
|
+
userEmail: string;
|
|
120
|
+
orgId: string | null;
|
|
121
|
+
orgSecret: string | null;
|
|
122
|
+
},
|
|
123
|
+
): DispatchMutationReceipt[] {
|
|
124
|
+
if (app !== "content" || !identity.orgSecret) return [];
|
|
125
|
+
const text = dispatchTaskText(task);
|
|
126
|
+
if (!text) return [];
|
|
127
|
+
const result = [{ tool: "call-agent", result: text }];
|
|
128
|
+
const receipts = extractA2APersistedMutationReceipts(result, {
|
|
129
|
+
persistedArtifactSecrets: [identity.orgSecret],
|
|
130
|
+
expectedDelegatedTaskId: task.id,
|
|
131
|
+
});
|
|
132
|
+
return receipts.filter((receipt) => {
|
|
133
|
+
if (receipt.target.authorityScopeKind === "personal") {
|
|
134
|
+
return (
|
|
135
|
+
receipt.target.authorityScopeId.toLowerCase() ===
|
|
136
|
+
identity.userEmail.toLowerCase()
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return (
|
|
140
|
+
identity.orgId !== null &&
|
|
141
|
+
receipt.target.authorityScopeId === identity.orgId
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
110
146
|
type DispatchAskAppStatusErrorCategory =
|
|
111
147
|
| "transport"
|
|
112
148
|
| "timeout"
|
|
@@ -119,6 +155,7 @@ type DispatchAskAppTaskResult = {
|
|
|
119
155
|
taskId: string;
|
|
120
156
|
status: string;
|
|
121
157
|
response?: string;
|
|
158
|
+
receipts?: DispatchMutationReceipt[];
|
|
122
159
|
error?: string;
|
|
123
160
|
inputRequired?: string;
|
|
124
161
|
statusRead?: "unavailable";
|
|
@@ -133,9 +170,15 @@ type DispatchAskAppTaskResult = {
|
|
|
133
170
|
function dispatchAskAppTaskResult(
|
|
134
171
|
app: string,
|
|
135
172
|
task: Task,
|
|
173
|
+
identity: {
|
|
174
|
+
userEmail: string;
|
|
175
|
+
orgId: string | null;
|
|
176
|
+
orgSecret: string | null;
|
|
177
|
+
},
|
|
136
178
|
): DispatchAskAppTaskResult {
|
|
137
179
|
const status = String(task.status.state);
|
|
138
|
-
const response = dispatchTaskText(task);
|
|
180
|
+
const response = stripA2APersistedArtifactMarkers(dispatchTaskText(task));
|
|
181
|
+
const receipts = dispatchTaskMutationReceipts(task, app, identity);
|
|
139
182
|
const base = {
|
|
140
183
|
app,
|
|
141
184
|
routedVia: "a2a" as const,
|
|
@@ -144,7 +187,11 @@ function dispatchAskAppTaskResult(
|
|
|
144
187
|
};
|
|
145
188
|
|
|
146
189
|
if (status === "completed") {
|
|
147
|
-
return {
|
|
190
|
+
return {
|
|
191
|
+
...base,
|
|
192
|
+
response: response || "(no response)",
|
|
193
|
+
...(receipts.length > 0 ? { receipts } : {}),
|
|
194
|
+
};
|
|
148
195
|
}
|
|
149
196
|
if (status === "failed" || status === "canceled") {
|
|
150
197
|
return {
|
|
@@ -753,7 +800,11 @@ export async function askGrantedDispatchMcpApp(
|
|
|
753
800
|
{ async: true, metadata },
|
|
754
801
|
);
|
|
755
802
|
const finalOrRunning = await waitForDispatchA2ATask(client, task, deadline);
|
|
756
|
-
return dispatchAskAppTaskResult(target.id, finalOrRunning
|
|
803
|
+
return dispatchAskAppTaskResult(target.id, finalOrRunning, {
|
|
804
|
+
userEmail,
|
|
805
|
+
orgId: orgId ?? null,
|
|
806
|
+
orgSecret: orgSecret ?? null,
|
|
807
|
+
});
|
|
757
808
|
}
|
|
758
809
|
|
|
759
810
|
export async function getGrantedDispatchMcpAppTask(
|
|
@@ -788,7 +839,11 @@ export async function getGrantedDispatchMcpAppTask(
|
|
|
788
839
|
const startedAt = Date.now();
|
|
789
840
|
try {
|
|
790
841
|
const task = await client.getTask(trimmedTaskId);
|
|
791
|
-
return dispatchAskAppTaskResult(target.id, task
|
|
842
|
+
return dispatchAskAppTaskResult(target.id, task, {
|
|
843
|
+
userEmail,
|
|
844
|
+
orgId: orgId ?? null,
|
|
845
|
+
orgSecret: orgSecret ?? null,
|
|
846
|
+
});
|
|
792
847
|
} catch (err) {
|
|
793
848
|
const delayMs = DISPATCH_ASK_APP_STATUS_RETRY_DELAYS_MS[attempt];
|
|
794
849
|
const errorCategory = dispatchAskAppStatusErrorCategory(err);
|