@agent-native/core 0.107.1 → 0.107.2
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/corpus/core/CHANGELOG.md +6 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/a2a/artifact-response.ts +32 -10
- package/corpus/core/src/integrations/a2a-continuation-processor.ts +107 -3
- package/corpus/core/src/integrations/pending-tasks-store.ts +98 -1
- package/corpus/core/src/integrations/plugin.ts +129 -4
- package/corpus/core/src/integrations/webhook-handler.ts +339 -36
- package/corpus/core/src/server/agent-chat-plugin.ts +93 -8
- package/dist/a2a/artifact-response.d.ts +5 -1
- package/dist/a2a/artifact-response.d.ts.map +1 -1
- package/dist/a2a/artifact-response.js +18 -12
- package/dist/a2a/artifact-response.js.map +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/integrations/a2a-continuation-processor.js +62 -5
- package/dist/integrations/a2a-continuation-processor.js.map +1 -1
- package/dist/integrations/pending-tasks-store.d.ts +3 -0
- package/dist/integrations/pending-tasks-store.d.ts.map +1 -1
- package/dist/integrations/pending-tasks-store.js +75 -1
- package/dist/integrations/pending-tasks-store.js.map +1 -1
- package/dist/integrations/plugin.d.ts.map +1 -1
- package/dist/integrations/plugin.js +81 -5
- package/dist/integrations/plugin.js.map +1 -1
- package/dist/integrations/webhook-handler.d.ts +23 -2
- package/dist/integrations/webhook-handler.d.ts.map +1 -1
- package/dist/integrations/webhook-handler.js +257 -35
- package/dist/integrations/webhook-handler.js.map +1 -1
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/server/agent-chat-plugin.d.ts +6 -0
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +71 -6
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import nodePath from "node:path";
|
|
3
3
|
import { createError, defineEventHandler, setResponseStatus, setResponseHeader, getMethod, getQuery, getHeader, getRequestIP, } from "h3";
|
|
4
|
-
import { buildA2ARecoverableArtifactMessage, } from "../a2a/artifact-response.js";
|
|
4
|
+
import { appendA2AArtifactLinks, buildA2ARecoverableArtifactMessage, } from "../a2a/artifact-response.js";
|
|
5
5
|
import { hasConfiguredA2ASecret, isLoopbackAddress, isTrustedLocalRuntime, } from "../a2a/auth-policy.js";
|
|
6
6
|
import { applyAgentTextEventToBuffer } from "../a2a/response-text.js";
|
|
7
7
|
import { createA2AApproval, updateTaskStatusMessage, } from "../a2a/task-store.js";
|
|
@@ -77,6 +77,60 @@ export { shouldBlockInProductCodeEditingSurface };
|
|
|
77
77
|
export { loadRunCodeToolEntries };
|
|
78
78
|
export { shouldDisableRecurringJobsRuntime };
|
|
79
79
|
export { finalizeClaimedAgentChatProcessRunFailure };
|
|
80
|
+
export function createSerializedA2ATaskStatusWriter(taskId, writeStatus = updateTaskStatusMessage, onError = (error) => {
|
|
81
|
+
console.error(`[A2A] Failed to persist recoverable artifact message for task ${taskId}:`, error);
|
|
82
|
+
}) {
|
|
83
|
+
const maxAttempts = 3;
|
|
84
|
+
let latestWrite = Promise.resolve();
|
|
85
|
+
const persistWithRetry = async (message) => {
|
|
86
|
+
let lastError;
|
|
87
|
+
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
|
88
|
+
try {
|
|
89
|
+
await writeStatus(taskId, message);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
lastError = error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
onError(lastError);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// The durable-write error below remains the authoritative failure.
|
|
101
|
+
}
|
|
102
|
+
throw lastError;
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
enqueue(message) {
|
|
106
|
+
// A newer checkpoint supersedes an earlier failed checkpoint, so keep
|
|
107
|
+
// the queue moving. flush() still rejects when the latest write itself
|
|
108
|
+
// cannot be made durable after bounded retries.
|
|
109
|
+
latestWrite = latestWrite
|
|
110
|
+
.catch(() => undefined)
|
|
111
|
+
.then(() => {
|
|
112
|
+
return persistWithRetry(message);
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
flush() {
|
|
116
|
+
return latestWrite;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export async function resolveA2ARecoverableArtifactSecret(orgId = getRequestOrgId()) {
|
|
121
|
+
const globalSecret = process.env.A2A_SECRET?.trim();
|
|
122
|
+
if (globalSecret)
|
|
123
|
+
return globalSecret;
|
|
124
|
+
if (!orgId)
|
|
125
|
+
return undefined;
|
|
126
|
+
try {
|
|
127
|
+
const { getOrgA2ASecret } = await import("../org/context.js");
|
|
128
|
+
return (await getOrgA2ASecret(orgId))?.trim() || undefined;
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
80
134
|
export function buildLeanRunPolicyPrompt(codeEditingSurfaceRestriction, prodCodeExecPromptNote) {
|
|
81
135
|
return codeEditingSurfaceRestriction + prodCodeExecPromptNote;
|
|
82
136
|
}
|
|
@@ -1116,6 +1170,8 @@ export function createAgentChatPlugin(options) {
|
|
|
1116
1170
|
const a2aEvents = [];
|
|
1117
1171
|
const a2aToolResults = [];
|
|
1118
1172
|
let lastRecoverableArtifactText = "";
|
|
1173
|
+
const recoverableArtifactSecret = await resolveA2ARecoverableArtifactSecret();
|
|
1174
|
+
const recoverableArtifactStatusWriter = createSerializedA2ATaskStatusWriter(context.taskId);
|
|
1119
1175
|
const controller = new AbortController();
|
|
1120
1176
|
console.log(`[A2A] Starting agent loop: ${a2aToolSurface.tools.length}/${a2aToolSurface.availableTools.length} initial tools, prompt ${systemPrompt.length} chars`);
|
|
1121
1177
|
await runA2AAgentLoop({
|
|
@@ -1146,13 +1202,21 @@ export function createAgentChatPlugin(options) {
|
|
|
1146
1202
|
isError: event.isError,
|
|
1147
1203
|
completedSideEffect: event.completedSideEffect,
|
|
1148
1204
|
});
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1205
|
+
const artifactBaseUrl = resolveArtifactBaseUrl(context.event);
|
|
1206
|
+
const recoverableArtifactMessage = buildA2ARecoverableArtifactMessage(a2aToolResults, {
|
|
1207
|
+
baseUrl: artifactBaseUrl,
|
|
1151
1208
|
});
|
|
1209
|
+
const recoverableArtifactText = recoverableArtifactMessage
|
|
1210
|
+
? appendA2AArtifactLinks(recoverableArtifactMessage, a2aToolResults, {
|
|
1211
|
+
baseUrl: artifactBaseUrl,
|
|
1212
|
+
includePersistedArtifactMarker: true,
|
|
1213
|
+
persistedArtifactSecret: recoverableArtifactSecret,
|
|
1214
|
+
})
|
|
1215
|
+
: null;
|
|
1152
1216
|
if (recoverableArtifactText &&
|
|
1153
1217
|
recoverableArtifactText !== lastRecoverableArtifactText) {
|
|
1154
1218
|
lastRecoverableArtifactText = recoverableArtifactText;
|
|
1155
|
-
|
|
1219
|
+
recoverableArtifactStatusWriter.enqueue({
|
|
1156
1220
|
role: "agent",
|
|
1157
1221
|
metadata: { agentNativeRecoverableArtifacts: true },
|
|
1158
1222
|
parts: [
|
|
@@ -1161,8 +1225,6 @@ export function createAgentChatPlugin(options) {
|
|
|
1161
1225
|
text: recoverableArtifactText,
|
|
1162
1226
|
},
|
|
1163
1227
|
],
|
|
1164
|
-
}).catch((err) => {
|
|
1165
|
-
console.error(`[A2A] Failed to persist recoverable artifact message for task ${context.taskId}:`, err);
|
|
1166
1228
|
});
|
|
1167
1229
|
}
|
|
1168
1230
|
}
|
|
@@ -1181,6 +1243,9 @@ export function createAgentChatPlugin(options) {
|
|
|
1181
1243
|
backgroundFunction: options?.durableBackgroundRuns === true &&
|
|
1182
1244
|
isInBackgroundFunctionRuntime(),
|
|
1183
1245
|
});
|
|
1246
|
+
// The continuation can observe terminal output immediately, so make
|
|
1247
|
+
// its latest mutation checkpoint durable first.
|
|
1248
|
+
await recoverableArtifactStatusWriter.flush();
|
|
1184
1249
|
const approval = [...a2aEvents]
|
|
1185
1250
|
.reverse()
|
|
1186
1251
|
.find((event) => event.type === "approval_required");
|