@agent-native/core 0.219.0 → 0.220.0-nightly-20261023212848
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/action.d.ts +23 -3
- package/dist/action.js +58 -3
- package/dist/agent/abort-reasons.d.ts +6 -0
- package/dist/agent/abort-reasons.js +6 -0
- package/dist/agent/execution-fence.js +5 -1
- package/dist/agent/production-agent.d.ts +22 -6
- package/dist/agent/production-agent.js +136 -37
- package/dist/agent/run-manager.js +92 -44
- package/dist/agent/run-store.d.ts +1 -0
- package/dist/agent/run-store.js +260 -31
- package/dist/agent/run-terminal-tracking.d.ts +29 -0
- package/dist/agent/run-terminal-tracking.js +56 -0
- package/dist/agent/run-turn-id-header.d.ts +9 -0
- package/dist/agent/run-turn-id-header.js +13 -0
- package/dist/agent/types.d.ts +11 -0
- package/dist/chat-threads/store.d.ts +23 -6
- package/dist/chat-threads/store.js +119 -36
- package/dist/cli/amplify-stream.js +1 -1
- package/dist/client/agent-chat/index.d.ts +2 -1
- package/dist/client/agent-chat/index.js +2 -1
- package/dist/client/agent-chat.d.ts +2 -0
- package/dist/client/agent-chat.js +31 -5
- package/dist/client/chat/agentkit-agent-native.js +8 -1
- package/dist/client/chat/agentkit-protocol.js +7 -1
- package/dist/client/chat/run-outcome-telemetry.js +1 -0
- package/dist/client/chat/run-outcome.d.ts +5 -0
- package/dist/client/chat/runtime.d.ts +34 -1
- package/dist/client/chat/runtime.js +96 -12
- package/dist/client/chat/turn-submitted-telemetry.d.ts +4 -0
- package/dist/client/chat/turn-submitted-telemetry.js +39 -0
- package/dist/client/chat/turn-submitted.d.ts +39 -0
- package/dist/client/chat/turn-submitted.js +16 -0
- package/dist/client/route-chunk-recovery.d.ts +3 -8
- package/dist/client/route-chunk-recovery.js +11 -9
- package/dist/client/use-chat-thread-list.d.ts +2 -0
- package/dist/client/use-chat-thread-list.js +48 -2
- package/dist/client/use-chat-threads.d.ts +13 -0
- package/dist/client/use-chat-threads.js +59 -4
- package/dist/collab/routes.d.ts +2 -2
- package/dist/db/client.d.ts +1 -0
- package/dist/db/client.js +28 -18
- package/dist/db/schema-snapshot.generated.js +5 -0
- package/dist/identity/rekey.d.ts +2 -0
- package/dist/identity/rekey.js +19 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp/agent-connected.d.ts +5 -0
- package/dist/mcp/agent-connected.js +10 -3
- package/dist/mcp/analytics.d.ts +14 -1
- package/dist/mcp/analytics.js +54 -2
- package/dist/mcp/embed-app.js +2 -1
- package/dist/mcp/oauth-route.js +56 -1
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/observability/routes.d.ts +7 -7
- package/dist/observability/traces.d.ts +2 -0
- package/dist/observability/traces.js +11 -2
- package/dist/provider-api/actions/custom-provider-registration.d.ts +16 -16
- package/dist/provider-api/actions/provider-api.d.ts +13 -13
- package/dist/provider-api/corpus-jobs.d.ts +2 -2
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/review/index.d.ts +1 -1
- package/dist/review/index.js +1 -1
- package/dist/review/suggestions/actions.js +25 -17
- package/dist/review/suggestions/store.d.ts +14 -1
- package/dist/review/suggestions/store.js +16 -3
- package/dist/review/suggestions/types.d.ts +15 -1
- package/dist/scripts/chat/search-chats.js +14 -2
- package/dist/server/agent-chat/browser-team-tools.js +39 -6
- package/dist/server/agent-chat/script-entries.js +44 -9
- package/dist/server/agent-chat-plugin.d.ts +2 -0
- package/dist/server/agent-chat-plugin.js +66 -16
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/agent-engine-default-model-route.d.ts +1 -1
- package/dist/server/first-touch-route.d.ts +2 -2
- package/dist/shared/route-chunk-recovery-bootstrap.d.ts +9 -0
- package/dist/shared/route-chunk-recovery-bootstrap.js +25 -0
- package/dist/sharing/actions/list-resource-shares.d.ts +1 -1
- package/dist/templates/chat/.agents/skills/actions/SKILL.md +1 -0
- package/dist/templates/default/.agents/skills/actions/SKILL.md +1 -0
- package/dist/templates/factory/.agents/skills/review-prs/SKILL.md +27 -3
- package/dist/templates/headless/.agents/skills/actions/SKILL.md +1 -0
- package/dist/templates/workspace-core/.agents/skills/actions/SKILL.md +1 -0
- package/dist/templates/workspace-core/.agents/skills/external-agents/references/mcp-apps-embedding.md +12 -5
- package/dist/tracking/providers.js +3 -0
- package/dist/triggers/actions/manage-automation.d.ts +2 -2
- package/docs/content/external-agents.mdx +1 -1
- package/docs/content/mcp-apps.mdx +3 -3
- package/docs/content/mcp-protocol.mdx +1 -1
- package/docs/content/sharing.mdx +1 -0
- package/docs/content/template-assets-integrations.mdx +5 -3
- package/package.json +3 -3
- package/src/templates/chat/.agents/skills/actions/SKILL.md +1 -0
- package/src/templates/default/.agents/skills/actions/SKILL.md +1 -0
- package/src/templates/factory/.agents/skills/review-prs/SKILL.md +27 -3
- package/src/templates/headless/.agents/skills/actions/SKILL.md +1 -0
- package/src/templates/workspace-core/.agents/skills/actions/SKILL.md +1 -0
- package/src/templates/workspace-core/.agents/skills/external-agents/references/mcp-apps-embedding.md +12 -5
|
@@ -5,13 +5,14 @@ import { recordAgentRun } from "../observability/metrics.js";
|
|
|
5
5
|
import { parseServiceIdentityEmail } from "../org/service-identity.js";
|
|
6
6
|
import { ServicePrincipalRefusedError } from "../org/service-principal-guard.js";
|
|
7
7
|
import { captureError } from "../server/capture-error.js";
|
|
8
|
+
import { EXECUTION_LEASE_LOST_ABORT_REASON } from "./abort-reasons.js";
|
|
8
9
|
import { isLlmCredentialError, LLM_MISSING_CREDENTIALS_ERROR_CODE, LLM_MISSING_CREDENTIALS_MESSAGE, } from "./engine/credential-errors.js";
|
|
9
10
|
import { classifyTerminalErrorCode, describeErrorWithCauses, isProviderConnectionError, } from "./engine/error-detail.js";
|
|
10
|
-
import { runErrorTelemetryProperties } from "./engine/error-telemetry.js";
|
|
11
11
|
import { getAgentEngineEntry } from "./engine/registry.js";
|
|
12
12
|
import { EngineError } from "./engine/types.js";
|
|
13
13
|
import { currentExecutionFence, MissingExecutionFenceError, StaleExecutionFenceError, withExecutionFence, withExecutionLeaseRequested, } from "./execution-fence.js";
|
|
14
|
-
import { AgentRunEventNotPersistedError, insertRun, insertRunEvent, insertRunEvents, updateRunStatusIfRunning, markRunAborted, markRunAbortedAtSafeBoundary, getRunAbortState, getRunStatus, getRunEventsSince, getCurrentTurnRunEventsForThread, getRunById, getRunByThread, getRunTurnRef, listRunsForThread, markTurnAborted, cleanupOldRuns, updateRunHeartbeat, bumpRunProgress, setRunInFlightMarker, reapIfStale, reapUnclaimedBackgroundRun, shouldRedispatchUnclaimedBackgroundRun, reconcileTerminalRunFromEvents, ensureTerminalRunEvent, getLastTerminalRunEvent, resolveErroredRunTerminalEvent, setRunError, setRunTerminalReason, persistRunCheckpointEvent, recordRunDiagnostic, RUN_DIAG_STAGE, claimTurnExecutionLease, renewTurnExecutionLease, releaseTurnExecutionLease, TurnExecutionLeaseBusyError, terminalEventForAbortReason, RUN_RECORD_MISSING_ERROR_EVENT, RUN_RECORD_MISSING_GRACE_MS, RUN_TERMINAL_LOOKUP_FAILED_ERROR_EVENT, UNKNOWN_RUN_STATUS_ERROR_EVENT, } from "./run-store.js";
|
|
14
|
+
import { AgentRunEventNotPersistedError, insertRun, insertRunEvent, insertRunEvents, updateRunStatusIfRunning, markRunAborted, markRunAbortedAtSafeBoundary, getRunAbortState, getRunStatus, getRunEventsSince, getCurrentTurnRunEventsForThread, getRunById, getRunByThread, getRunTurnRef, listRunsForThread, markTurnAborted, cleanupOldRuns, updateRunHeartbeat, bumpRunProgress, setRunInFlightMarker, reapIfStale, reapUnclaimedBackgroundRun, shouldRedispatchUnclaimedBackgroundRun, reconcileTerminalRunFromEvents, ensureTerminalRunEvent, getLastTerminalRunEvent, resolveErroredRunTerminalEvent, setRunError, setRunTerminalReason, setRunTerminalReasonIfStatus, persistRunCheckpointEvent, recordRunDiagnostic, RUN_DIAG_STAGE, claimTurnExecutionLease, renewTurnExecutionLease, releaseTurnExecutionLease, TurnExecutionLeaseBusyError, terminalEventForAbortReason, RUN_RECORD_MISSING_ERROR_EVENT, RUN_RECORD_MISSING_GRACE_MS, RUN_TERMINAL_LOOKUP_FAILED_ERROR_EVENT, UNKNOWN_RUN_STATUS_ERROR_EVENT, } from "./run-store.js";
|
|
15
|
+
import { trackRunTerminal } from "./run-terminal-tracking.js";
|
|
15
16
|
import { CONTINUATION_REASONS, isContinuationTerminalReason } from "./types.js";
|
|
16
17
|
const activeRuns = new Map();
|
|
17
18
|
const threadToRun = new Map();
|
|
@@ -435,39 +436,26 @@ function emitRunTerminalTrackingEvent(args) {
|
|
|
435
436
|
catch {
|
|
436
437
|
// Metrics must never affect the agent run or its persisted status.
|
|
437
438
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
439
|
+
// An abort is reported by the SQL write that ended the row, which may be
|
|
440
|
+
// another process's stop; reporting it here too would double-count it.
|
|
441
|
+
if (args.status === "aborted")
|
|
442
|
+
return;
|
|
443
|
+
void trackRunTerminal({
|
|
444
|
+
runId: args.runId,
|
|
445
|
+
threadId: args.threadId,
|
|
446
|
+
turnId: args.turnId,
|
|
443
447
|
status: args.status,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
duration_ms: args.durationMs,
|
|
448
|
+
terminalReason: args.terminalReason,
|
|
449
|
+
errorCode: args.errorCode,
|
|
450
|
+
dispatchMode: args.dispatchMode,
|
|
451
|
+
abortReason: args.abortReason,
|
|
452
|
+
durationMs: args.durationMs,
|
|
450
453
|
model: args.model,
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
delete properties[key];
|
|
457
|
-
}
|
|
458
|
-
try {
|
|
459
|
-
void Promise.all([
|
|
460
|
-
import("../tracking/registry.js"),
|
|
461
|
-
import("../observability/tracking-identity.js"),
|
|
462
|
-
])
|
|
463
|
-
.then(([{ track }, { trackingIdentityProperties }]) => {
|
|
464
|
-
track("agent_run_terminal", { ...properties, ...trackingIdentityProperties() }, { userId: args.userId });
|
|
465
|
-
})
|
|
466
|
-
.catch(() => { });
|
|
467
|
-
}
|
|
468
|
-
catch {
|
|
469
|
-
// Tracking must never affect the agent run or its persisted status.
|
|
470
|
-
}
|
|
454
|
+
engineName: args.engineName,
|
|
455
|
+
attemptCount: args.attemptCount,
|
|
456
|
+
blockedTool: args.blockedTool,
|
|
457
|
+
blockedBy: args.blockedBy,
|
|
458
|
+
}, { userId: args.userId });
|
|
471
459
|
}
|
|
472
460
|
function abortInMemoryRun(run, reason = "user") {
|
|
473
461
|
run.abortReason = reason;
|
|
@@ -1208,6 +1196,7 @@ export function startRun(runId, threadId, runFn, onComplete, options) {
|
|
|
1208
1196
|
let completionInProgress = false;
|
|
1209
1197
|
let ownTerminalStatusEstablished = false;
|
|
1210
1198
|
let terminalStatusWrite = null;
|
|
1199
|
+
let terminalStatusWriteOutcomeUnknown = false;
|
|
1211
1200
|
const checkSqlAbort = () => {
|
|
1212
1201
|
const now = Date.now();
|
|
1213
1202
|
if (now - lastAbortCheck < 3000)
|
|
@@ -1223,8 +1212,18 @@ export function startRun(runId, threadId, runFn, onComplete, options) {
|
|
|
1223
1212
|
const status = await getRunStatus(runId);
|
|
1224
1213
|
if (status !== null && status !== "running") {
|
|
1225
1214
|
const pendingStatusWrite = terminalStatusWrite;
|
|
1226
|
-
if (pendingStatusWrite)
|
|
1227
|
-
|
|
1215
|
+
if (pendingStatusWrite) {
|
|
1216
|
+
try {
|
|
1217
|
+
await pendingStatusWrite;
|
|
1218
|
+
}
|
|
1219
|
+
catch (error) {
|
|
1220
|
+
if (!terminalStatusWriteOutcomeUnknown)
|
|
1221
|
+
throw error;
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
if (terminalStatusWriteOutcomeUnknown)
|
|
1226
|
+
return;
|
|
1228
1227
|
}
|
|
1229
1228
|
if (status !== null &&
|
|
1230
1229
|
status !== "running" &&
|
|
@@ -1272,7 +1271,7 @@ export function startRun(runId, threadId, runFn, onComplete, options) {
|
|
|
1272
1271
|
if (options?.executionLease &&
|
|
1273
1272
|
error?.code === "stale_execution_fence" &&
|
|
1274
1273
|
!completionInProgress) {
|
|
1275
|
-
abortInMemoryRun(run,
|
|
1274
|
+
abortInMemoryRun(run, EXECUTION_LEASE_LOST_ABORT_REASON);
|
|
1276
1275
|
}
|
|
1277
1276
|
consecutiveHeartbeatFailures += 1;
|
|
1278
1277
|
if (consecutiveHeartbeatFailures >= 3) {
|
|
@@ -1607,6 +1606,8 @@ export function startRun(runId, threadId, runFn, onComplete, options) {
|
|
|
1607
1606
|
let terminalPersistenceError = null;
|
|
1608
1607
|
let eventPersistenceError = null;
|
|
1609
1608
|
let runTerminalErrorCode;
|
|
1609
|
+
let runTerminalBlockedTool;
|
|
1610
|
+
let runTerminalBlockedBy;
|
|
1610
1611
|
let terminalPersistenceEstablished = false;
|
|
1611
1612
|
let continuationStatusPersistedBeforeEvent = false;
|
|
1612
1613
|
let suppressContinuationEvent = false;
|
|
@@ -1758,12 +1759,21 @@ export function startRun(runId, threadId, runFn, onComplete, options) {
|
|
|
1758
1759
|
? updateRunStatusIfRunning(runId, persistedStatus)
|
|
1759
1760
|
: updateRunStatusIfRunning(runId, persistedStatus, terminalStatusOptions);
|
|
1760
1761
|
const persistOwnTerminalState = async (persist) => {
|
|
1761
|
-
|
|
1762
|
+
let writeStarted = false;
|
|
1763
|
+
const write = withWorkerFence(() => {
|
|
1764
|
+
writeStarted = true;
|
|
1765
|
+
return persist();
|
|
1766
|
+
}).catch((error) => {
|
|
1767
|
+
if (writeStarted)
|
|
1768
|
+
terminalStatusWriteOutcomeUnknown = true;
|
|
1769
|
+
throw error;
|
|
1770
|
+
});
|
|
1762
1771
|
terminalStatusWrite = write;
|
|
1763
1772
|
try {
|
|
1764
1773
|
const established = await write;
|
|
1765
|
-
if (established)
|
|
1774
|
+
if (established && !terminalStatusWriteOutcomeUnknown) {
|
|
1766
1775
|
ownTerminalStatusEstablished = true;
|
|
1776
|
+
}
|
|
1767
1777
|
return established;
|
|
1768
1778
|
}
|
|
1769
1779
|
finally {
|
|
@@ -1772,11 +1782,45 @@ export function startRun(runId, threadId, runFn, onComplete, options) {
|
|
|
1772
1782
|
}
|
|
1773
1783
|
};
|
|
1774
1784
|
const persistOwnTerminalStatus = () => persistOwnTerminalState(persistTerminalStatus);
|
|
1775
|
-
const
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1785
|
+
const confirmAmbiguousTerminalStatus = async () => {
|
|
1786
|
+
const persistedRun = await getRunById(runId);
|
|
1787
|
+
if (persistedRun?.status !== persistedStatus)
|
|
1788
|
+
return false;
|
|
1789
|
+
const expectedTerminalReason = terminalReason.slice(0, 200);
|
|
1790
|
+
if (persistedRun.terminalReason === expectedTerminalReason) {
|
|
1791
|
+
return true;
|
|
1792
|
+
}
|
|
1793
|
+
if (persistedRun.terminalReason)
|
|
1794
|
+
return false;
|
|
1795
|
+
return withWorkerFence(() => setRunTerminalReasonIfStatus(runId, persistedStatus, expectedTerminalReason));
|
|
1796
|
+
};
|
|
1797
|
+
const reconcileTerminalRun = async () => {
|
|
1798
|
+
let reconciled = false;
|
|
1799
|
+
try {
|
|
1800
|
+
reconciled = await persistOwnTerminalState(() => threadProjectionPending
|
|
1801
|
+
? reconcileTerminalRunFromEvents(runId, {
|
|
1802
|
+
threadProjectionPending: true,
|
|
1803
|
+
})
|
|
1804
|
+
: reconcileTerminalRunFromEvents(runId));
|
|
1805
|
+
}
|
|
1806
|
+
catch (error) {
|
|
1807
|
+
if (!terminalStatusWriteOutcomeUnknown)
|
|
1808
|
+
throw error;
|
|
1809
|
+
}
|
|
1810
|
+
if (reconciled) {
|
|
1811
|
+
terminalStatusWriteOutcomeUnknown = false;
|
|
1812
|
+
ownTerminalStatusEstablished = true;
|
|
1813
|
+
return true;
|
|
1814
|
+
}
|
|
1815
|
+
if (!terminalStatusWriteOutcomeUnknown) {
|
|
1816
|
+
return reconciled;
|
|
1817
|
+
}
|
|
1818
|
+
const confirmed = await confirmAmbiguousTerminalStatus();
|
|
1819
|
+
terminalStatusWriteOutcomeUnknown = false;
|
|
1820
|
+
if (confirmed)
|
|
1821
|
+
ownTerminalStatusEstablished = true;
|
|
1822
|
+
return confirmed;
|
|
1823
|
+
};
|
|
1780
1824
|
const reportTerminalStatusPersistenceError = (error) => {
|
|
1781
1825
|
captureError(error, {
|
|
1782
1826
|
route: "/_agent-native/agent-chat",
|
|
@@ -1888,7 +1932,7 @@ export function startRun(runId, threadId, runFn, onComplete, options) {
|
|
|
1888
1932
|
}
|
|
1889
1933
|
else if (!executionLeaseClaimFailed &&
|
|
1890
1934
|
(run.abortReason === "superseded" ||
|
|
1891
|
-
run.abortReason ===
|
|
1935
|
+
run.abortReason === EXECUTION_LEASE_LOST_ABORT_REASON)) {
|
|
1892
1936
|
terminalPersistenceEstablished = false;
|
|
1893
1937
|
}
|
|
1894
1938
|
else {
|
|
@@ -1955,6 +1999,8 @@ export function startRun(runId, threadId, runFn, onComplete, options) {
|
|
|
1955
1999
|
else if (ev.type === "error") {
|
|
1956
2000
|
errorCode = ev.errorCode;
|
|
1957
2001
|
errorDetail = ev.error ?? ev.details;
|
|
2002
|
+
runTerminalBlockedTool = ev.blockedTool;
|
|
2003
|
+
runTerminalBlockedBy = ev.blockedBy;
|
|
1958
2004
|
break;
|
|
1959
2005
|
}
|
|
1960
2006
|
}
|
|
@@ -2002,6 +2048,8 @@ export function startRun(runId, threadId, runFn, onComplete, options) {
|
|
|
2002
2048
|
status: persistedStatus,
|
|
2003
2049
|
terminalReason,
|
|
2004
2050
|
errorCode: runTerminalErrorCode,
|
|
2051
|
+
blockedTool: runTerminalBlockedTool,
|
|
2052
|
+
blockedBy: runTerminalBlockedBy,
|
|
2005
2053
|
dispatchMode: options?.dispatchMode,
|
|
2006
2054
|
abortReason: run.abortReason,
|
|
2007
2055
|
durationMs: Date.now() - run.startedAt,
|
|
@@ -276,6 +276,7 @@ export declare function tryClaimRunSlot(threadId: string, runId: string, maxStal
|
|
|
276
276
|
}>;
|
|
277
277
|
export declare function setRunError(runId: string, errorCode: string | undefined, errorDetail: string | undefined): Promise<void>;
|
|
278
278
|
export declare function setRunTerminalReason(runId: string, terminalReason: string | undefined): Promise<void>;
|
|
279
|
+
export declare function setRunTerminalReasonIfStatus(runId: string, expectedStatus: "completed" | "truncated" | "errored" | "aborted", terminalReason: string): Promise<boolean>;
|
|
279
280
|
/**
|
|
280
281
|
* Repair a run whose terminal event was durably appended but whose final
|
|
281
282
|
* `agent_runs.status` write lost a race with reconnect/reaper code.
|