@agent-native/core 0.84.4 → 0.84.6
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 +12 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/production-agent.ts +97 -38
- package/corpus/core/src/agent/run-store.ts +17 -0
- package/corpus/core/src/cli/skills.ts +9 -7
- package/corpus/core/src/client/agent-chat-adapter.ts +13 -1
- package/corpus/core/src/client/sse-event-processor.ts +75 -1
- package/corpus/core/src/server/agent-chat-plugin.ts +57 -12
- package/corpus/templates/design/AGENTS.md +7 -6
- package/corpus/templates/design/actions/present-design-variants.ts +4 -2
- package/corpus/templates/design/app/hooks/use-question-flow.ts +2 -2
- package/corpus/templates/design/app/pages/DesignEditor.tsx +1 -1
- package/dist/agent/production-agent.d.ts +20 -0
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +65 -32
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-store.d.ts +14 -0
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +14 -0
- package/dist/agent/run-store.js.map +1 -1
- package/dist/cli/skills.d.ts.map +1 -1
- package/dist/cli/skills.js +9 -7
- package/dist/cli/skills.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +8 -1
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +63 -1
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/collab/routes.d.ts +2 -2
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/observability/routes.d.ts +5 -5
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/server/agent-chat-plugin.d.ts +9 -0
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +20 -8
- 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
|
@@ -3046,6 +3046,34 @@ export function shouldChainBackgroundContinuation(opts) {
|
|
|
3046
3046
|
endsAtInternalContinuationBoundary(opts.run) &&
|
|
3047
3047
|
opts.continuationCount < MAX_BACKGROUND_RUN_CONTINUATIONS);
|
|
3048
3048
|
}
|
|
3049
|
+
export async function claimBackgroundWorkerRunEarly(opts) {
|
|
3050
|
+
const record = opts.deps?.recordRunDiagnostic ?? recordRunDiagnostic;
|
|
3051
|
+
const insert = opts.deps?.insertRun ?? insertRun;
|
|
3052
|
+
const claim = opts.deps?.claimBackgroundRun ?? claimBackgroundRun;
|
|
3053
|
+
const heartbeat = opts.deps?.updateRunHeartbeat ?? updateRunHeartbeat;
|
|
3054
|
+
const threadId = typeof opts.threadId === "string" && opts.threadId.trim()
|
|
3055
|
+
? opts.threadId.trim()
|
|
3056
|
+
: opts.runId;
|
|
3057
|
+
const turnId = typeof opts.markerTurnId === "string" && opts.markerTurnId.trim()
|
|
3058
|
+
? opts.markerTurnId.trim()
|
|
3059
|
+
: typeof opts.requestTurnId === "string" && opts.requestTurnId.trim()
|
|
3060
|
+
? opts.requestTurnId.trim()
|
|
3061
|
+
: opts.runId;
|
|
3062
|
+
await record(opts.runId, RUN_DIAG_STAGE.workerEntered, `runsInBackgroundFunction=${opts.runsInBackgroundFunction} continuationCount=${opts.continuationCount}`).catch(() => { });
|
|
3063
|
+
if (opts.continuationCount > 0) {
|
|
3064
|
+
await insert(opts.runId, threadId, turnId, {
|
|
3065
|
+
dispatchMode: "background",
|
|
3066
|
+
}).catch(() => { });
|
|
3067
|
+
}
|
|
3068
|
+
const won = await claim(opts.runId);
|
|
3069
|
+
if (!won) {
|
|
3070
|
+
await record(opts.runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => { });
|
|
3071
|
+
return { claimed: false, skipped: "already-claimed" };
|
|
3072
|
+
}
|
|
3073
|
+
await record(opts.runId, RUN_DIAG_STAGE.workerClaimed).catch(() => { });
|
|
3074
|
+
await heartbeat(opts.runId).catch(() => { });
|
|
3075
|
+
return { claimed: true };
|
|
3076
|
+
}
|
|
3049
3077
|
function progressStepFromAgentChatEvent(event) {
|
|
3050
3078
|
switch (event.type) {
|
|
3051
3079
|
case "activity":
|
|
@@ -3164,6 +3192,23 @@ export function createProductionAgentHandler(options) {
|
|
|
3164
3192
|
Number.isFinite(backgroundRunMarker.continuationCount)
|
|
3165
3193
|
? Math.max(0, Math.floor(backgroundRunMarker.continuationCount))
|
|
3166
3194
|
: 0;
|
|
3195
|
+
let backgroundRunClaimedEarly = false;
|
|
3196
|
+
if (isBackgroundWorker && bgRunId) {
|
|
3197
|
+
const earlyClaim = await claimBackgroundWorkerRunEarly({
|
|
3198
|
+
runId: bgRunId,
|
|
3199
|
+
threadId,
|
|
3200
|
+
markerTurnId: typeof backgroundRunMarker?.turnId === "string"
|
|
3201
|
+
? backgroundRunMarker.turnId
|
|
3202
|
+
: null,
|
|
3203
|
+
requestTurnId,
|
|
3204
|
+
continuationCount: backgroundContinuationCount,
|
|
3205
|
+
runsInBackgroundFunction,
|
|
3206
|
+
});
|
|
3207
|
+
if (!earlyClaim.claimed) {
|
|
3208
|
+
return { ok: true, skipped: earlyClaim.skipped };
|
|
3209
|
+
}
|
|
3210
|
+
backgroundRunClaimedEarly = true;
|
|
3211
|
+
}
|
|
3167
3212
|
// The foreground POST decides whether to dispatch into a background
|
|
3168
3213
|
// function. The background worker itself never re-dispatches.
|
|
3169
3214
|
const dispatchToBackground = !isBackgroundWorker &&
|
|
@@ -4061,40 +4106,28 @@ export function createProductionAgentHandler(options) {
|
|
|
4061
4106
|
}
|
|
4062
4107
|
}
|
|
4063
4108
|
: undefined;
|
|
4064
|
-
// Background worker:
|
|
4065
|
-
//
|
|
4066
|
-
//
|
|
4067
|
-
//
|
|
4068
|
-
//
|
|
4109
|
+
// Background worker: the run was claimed immediately after the authenticated
|
|
4110
|
+
// `_process-run` body was parsed, before owner/model/prompt/tool setup. That
|
|
4111
|
+
// early claim is what lets the foreground subscribe to the real background
|
|
4112
|
+
// worker instead of racing slow setup and falling back to the 40s inline
|
|
4113
|
+
// path. This late block is a defensive fallback for older/custom callers
|
|
4114
|
+
// that somehow reach here without the early claim.
|
|
4069
4115
|
if (isBackgroundWorker) {
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
await
|
|
4084
|
-
dispatchMode: "background",
|
|
4085
|
-
}).catch(() => { });
|
|
4086
|
-
}
|
|
4087
|
-
const won = await claimBackgroundRun(runId);
|
|
4088
|
-
if (!won) {
|
|
4089
|
-
// Already claimed by an earlier delivery — return a benign ack so
|
|
4090
|
-
// Netlify doesn't retry a successful handoff.
|
|
4091
|
-
await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => { });
|
|
4092
|
-
return { ok: true, skipped: "already-claimed" };
|
|
4116
|
+
if (!backgroundRunClaimedEarly) {
|
|
4117
|
+
await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerEntered, `runsInBackgroundFunction=${runsInBackgroundFunction} continuationCount=${backgroundContinuationCount}`).catch(() => { });
|
|
4118
|
+
if (isChainedBackgroundContinuation) {
|
|
4119
|
+
await insertRun(runId, effectiveThreadId, effectiveTurnId, {
|
|
4120
|
+
dispatchMode: "background",
|
|
4121
|
+
}).catch(() => { });
|
|
4122
|
+
}
|
|
4123
|
+
const won = await claimBackgroundRun(runId);
|
|
4124
|
+
if (!won) {
|
|
4125
|
+
await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => { });
|
|
4126
|
+
return { ok: true, skipped: "already-claimed" };
|
|
4127
|
+
}
|
|
4128
|
+
await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimed).catch(() => { });
|
|
4129
|
+
await updateRunHeartbeat(runId).catch(() => { });
|
|
4093
4130
|
}
|
|
4094
|
-
// DIAGNOSTIC: this worker won the claim and now OWNS the run. If a run
|
|
4095
|
-
// ever stalls at this stage it means the loop below failed to start.
|
|
4096
|
-
await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimed).catch(() => { });
|
|
4097
|
-
await updateRunHeartbeat(runId).catch(() => { });
|
|
4098
4131
|
}
|
|
4099
4132
|
// DIAGNOSTIC-ONLY: build the pre-startRun setup-timing breakdown now (so the
|
|
4100
4133
|
// marks reflect the work done BEFORE the loop), but EMIT it from inside
|