@agent-native/core 0.204.0 → 0.204.1-nightly-20261008034100
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.js +5 -6
- package/dist/agent/auto-continue.d.ts +35 -0
- package/dist/agent/auto-continue.js +38 -0
- package/dist/agent/connection-required-note.d.ts +52 -0
- package/dist/agent/connection-required-note.js +187 -0
- package/dist/agent/jev-tool-prefetch.d.ts +5 -1
- package/dist/agent/jev-tool-prefetch.js +19 -6
- package/dist/agent/previous-turn-note.d.ts +9 -0
- package/dist/agent/previous-turn-note.js +48 -0
- package/dist/agent/production-agent.d.ts +17 -13
- package/dist/agent/production-agent.js +185 -43
- package/dist/agent/reaped-run-thread.d.ts +13 -0
- package/dist/agent/reaped-run-thread.js +45 -0
- package/dist/agent/run-store.d.ts +29 -5
- package/dist/agent/run-store.js +144 -30
- package/dist/agent/thread-data-builder.d.ts +16 -0
- package/dist/agent/thread-data-builder.js +30 -8
- package/dist/agent/thread-message-projection.js +5 -3
- package/dist/agent/tool-search.js +5 -1
- package/dist/agent/types.d.ts +3 -0
- package/dist/audit/config.d.ts +6 -0
- package/dist/audit/config.js +12 -1
- package/dist/audit/index.d.ts +1 -1
- package/dist/audit/index.js +1 -1
- package/dist/audit/store.js +39 -4
- package/dist/cli/skills.d.ts +1 -0
- package/dist/cli/skills.js +1 -1
- package/dist/client/chat/agentkit-agent-native.js +83 -7
- package/dist/client/chat/agentkit-protocol.js +140 -67
- package/dist/client/chat/runtime.js +5 -3
- package/dist/client/use-run-stuck-detection.d.ts +18 -1
- package/dist/client/use-run-stuck-detection.js +115 -75
- package/dist/db/request-telemetry.d.ts +7 -1
- package/dist/db/request-telemetry.js +20 -1
- package/dist/deploy/build.d.ts +25 -1
- package/dist/deploy/build.js +176 -3
- package/dist/deploy/workspace-deploy.js +8 -3
- package/dist/extensions/fetch-tool.js +50 -14
- package/dist/file-upload/actions/upload-image.d.ts +2 -2
- package/dist/integrations/adapters/email.js +11 -3
- package/dist/integrations/adapters/telegram.js +4 -2
- package/dist/jobs/actions/automation-no-op.d.ts +12 -0
- package/dist/jobs/actions/automation-no-op.js +20 -0
- package/dist/jobs/actions/manage-recurring-job.d.ts +1 -1
- package/dist/jobs/background-automation-runner.d.ts +8 -1
- package/dist/jobs/background-automation-runner.js +102 -19
- package/dist/jobs/run-history.d.ts +1 -1
- package/dist/jobs/run-history.js +8 -4
- package/dist/jobs/scheduler.js +25 -12
- package/dist/localization/automation-outcome-messages.d.ts +22 -0
- package/dist/localization/automation-outcome-messages.js +90 -0
- package/dist/localization/default-messages.d.ts +2 -0
- package/dist/localization/default-messages.js +4 -2
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/observability/metrics.d.ts +3 -0
- package/dist/observability/metrics.js +10 -0
- package/dist/observability/migrations.js +22 -0
- package/dist/observability/routes.d.ts +13 -8
- package/dist/observability/routes.js +88 -14
- package/dist/observability/sentiment.d.ts +5 -0
- package/dist/observability/sentiment.js +75 -25
- package/dist/observability/store.d.ts +28 -0
- package/dist/observability/store.js +58 -0
- package/dist/observability/traces.js +37 -5
- package/dist/org/index.d.ts +2 -2
- package/dist/progress/actions.js +1 -0
- package/dist/provider-api/actions/custom-provider-registration.d.ts +12 -12
- package/dist/provider-api/actions/provider-api.d.ts +7 -7
- package/dist/provider-api/actions/provider-api.js +6 -2
- package/dist/provider-api/corpus-jobs.d.ts +2 -2
- package/dist/provider-api/index.d.ts +1 -0
- package/dist/provider-api/index.js +18 -0
- package/dist/provider-api/result-outcome.d.ts +1 -0
- package/dist/provider-api/result-outcome.js +20 -0
- package/dist/provider-api/staging.js +10 -9
- package/dist/server/agent-chat/prompt-resources.d.ts +8 -2
- package/dist/server/agent-chat/prompt-resources.js +30 -7
- package/dist/server/agent-chat/recurring-jobs-runtime.d.ts +19 -4
- package/dist/server/agent-chat/recurring-jobs-runtime.js +52 -16
- package/dist/server/agent-chat/sweep-trigger-auth.d.ts +18 -0
- package/dist/server/agent-chat/sweep-trigger-auth.js +36 -0
- package/dist/server/agent-chat-plugin.js +20 -13
- package/dist/server/agent-engine-default-model-route.d.ts +2 -2
- package/dist/server/auth.js +4 -4
- package/dist/server/framework-request-handler.js +19 -0
- package/dist/server/http-response-telemetry.js +4 -1
- package/dist/server/realtime-token.d.ts +1 -1
- package/dist/server/request-context.d.ts +6 -0
- package/dist/shared/context-status.d.ts +21 -0
- package/dist/shared/context-status.js +54 -0
- package/dist/templates/chat/app/components/chat/ChatRouteContent.tsx +8 -1
- package/dist/templates/workspace-core/.agents/skills/automations/SKILL.md +8 -1
- package/dist/templates/workspace-core/.agents/skills/recurring-jobs/SKILL.md +3 -1
- package/dist/triggers/actions/manage-automation.d.ts +7 -7
- package/dist/triggers/dispatcher.js +10 -7
- package/docs/content/audit-log.mdx +3 -3
- package/docs/content/cloudflare.mdx +27 -0
- package/docs/content/deployment-environment-variables.mdx +2 -0
- package/docs/content/durable-resume.mdx +3 -1
- package/docs/content/environment-variables.mdx +2 -0
- package/docs/content/recurring-jobs.mdx +29 -9
- package/docs/content/vercel.mdx +30 -0
- package/package.json +3 -3
- package/src/templates/chat/app/components/chat/ChatRouteContent.tsx +8 -1
- package/src/templates/workspace-core/.agents/skills/automations/SKILL.md +8 -1
- package/src/templates/workspace-core/.agents/skills/recurring-jobs/SKILL.md +3 -1
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { hasCloudflareRuntime } from "../../db/migration-runtime.js";
|
|
2
|
+
function detectRecurringJobsPlatform() {
|
|
3
|
+
return { cloudflareWorker: hasCloudflareRuntime() };
|
|
4
|
+
}
|
|
1
5
|
function isTruthyEnv(value) {
|
|
2
6
|
return /^(1|true|yes|on)$/i.test(value?.trim() ?? "");
|
|
3
7
|
}
|
|
@@ -25,19 +29,20 @@ function isLoopbackAppUrl(value) {
|
|
|
25
29
|
}
|
|
26
30
|
return false;
|
|
27
31
|
}
|
|
28
|
-
function isServerlessRecurringJobsRuntime(env) {
|
|
32
|
+
function isServerlessRecurringJobsRuntime(env, platform) {
|
|
29
33
|
return (env.NETLIFY_LOCAL !== "true" &&
|
|
30
|
-
(
|
|
34
|
+
(platform.cloudflareWorker ||
|
|
35
|
+
isTruthyEnv(env.NETLIFY) ||
|
|
31
36
|
env.NITRO_PRESET === "netlify" ||
|
|
32
37
|
Boolean(env.AWS_LAMBDA_FUNCTION_NAME) ||
|
|
33
38
|
env.AWS_EXECUTION_ENV?.startsWith("AWS_Lambda") === true ||
|
|
34
39
|
isTruthyEnv(env.CF_PAGES) ||
|
|
35
40
|
isTruthyEnv(env.VERCEL)));
|
|
36
41
|
}
|
|
37
|
-
export function shouldDisableRecurringJobsRuntime(env = process.env) {
|
|
42
|
+
export function shouldDisableRecurringJobsRuntime(env = process.env, platform = detectRecurringJobsPlatform()) {
|
|
38
43
|
if (isTruthyEnv(env.AGENT_NATIVE_DISABLE_RECURRING_JOBS))
|
|
39
44
|
return true;
|
|
40
|
-
if (isServerlessRecurringJobsRuntime(env))
|
|
45
|
+
if (isServerlessRecurringJobsRuntime(env, platform))
|
|
41
46
|
return true;
|
|
42
47
|
const isLocalRuntime = env.NODE_ENV === "development" ||
|
|
43
48
|
env.NODE_ENV === "test" ||
|
|
@@ -82,26 +87,57 @@ function readRecurringJobsBuildMarker(env) {
|
|
|
82
87
|
const value = raw?.trim();
|
|
83
88
|
return value === "enabled" || value === "disabled" ? value : undefined;
|
|
84
89
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
/**
|
|
91
|
+
* The secret each emitted trigger authenticates with. Netlify is absent
|
|
92
|
+
* because its build refuses to emit the scheduled function without
|
|
93
|
+
* `A2A_SECRET`; Vercel and Cloudflare read theirs only at runtime, so a deploy
|
|
94
|
+
* without one has a trigger that fires and is rejected every minute.
|
|
95
|
+
*/
|
|
96
|
+
const PLATFORM_TRIGGER_SECRET = {
|
|
97
|
+
"vercel-cron": "CRON_SECRET",
|
|
98
|
+
"cloudflare-cron-trigger": "A2A_SECRET",
|
|
99
|
+
};
|
|
100
|
+
function platformScheduledTriggerDriver(env, platform) {
|
|
101
|
+
if (isNetlifyRecurringJobsRuntime(env))
|
|
102
|
+
return "netlify-scheduled-function";
|
|
103
|
+
if (platform.cloudflareWorker)
|
|
104
|
+
return "cloudflare-cron-trigger";
|
|
105
|
+
// Vercel invokes cron jobs only on the production deployment.
|
|
106
|
+
if (isTruthyEnv(env.VERCEL) &&
|
|
107
|
+
(env.VERCEL_ENV ?? "production") === "production") {
|
|
108
|
+
return "vercel-cron";
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
export function scheduledTriggerAvailability(env = process.env, platform = detectRecurringJobsPlatform()) {
|
|
113
|
+
const driver = platformScheduledTriggerDriver(env, platform);
|
|
114
|
+
if (driver) {
|
|
115
|
+
// The emitted trigger fires on the platform's clock whatever the deployed
|
|
116
|
+
// env says, so the build's decision outranks a runtime-only switch.
|
|
117
|
+
const buildMarker = readRecurringJobsBuildMarker(env);
|
|
118
|
+
const disabled = buildMarker
|
|
119
|
+
? buildMarker === "disabled"
|
|
120
|
+
: isTruthyEnv(env.AGENT_NATIVE_DISABLE_RECURRING_JOBS);
|
|
121
|
+
if (disabled)
|
|
89
122
|
return { available: false, reason: "disabled-by-env" };
|
|
123
|
+
const secret = PLATFORM_TRIGGER_SECRET[driver];
|
|
124
|
+
if (secret && !env[secret]?.trim()) {
|
|
125
|
+
return {
|
|
126
|
+
available: false,
|
|
127
|
+
reason: "missing-trigger-secret",
|
|
128
|
+
driver,
|
|
129
|
+
secret,
|
|
130
|
+
};
|
|
90
131
|
}
|
|
91
|
-
|
|
92
|
-
return { available: true, driver: "netlify-scheduled-function" };
|
|
93
|
-
}
|
|
94
|
-
return isTruthyEnv(env.AGENT_NATIVE_DISABLE_RECURRING_JOBS)
|
|
95
|
-
? { available: false, reason: "disabled-by-env" }
|
|
96
|
-
: { available: true, driver: "netlify-scheduled-function" };
|
|
132
|
+
return { available: true, driver };
|
|
97
133
|
}
|
|
98
134
|
if (isTruthyEnv(env.AGENT_NATIVE_DISABLE_RECURRING_JOBS)) {
|
|
99
135
|
return { available: false, reason: "disabled-by-env" };
|
|
100
136
|
}
|
|
101
|
-
if (isServerlessRecurringJobsRuntime(env)) {
|
|
137
|
+
if (isServerlessRecurringJobsRuntime(env, platform)) {
|
|
102
138
|
return { available: false, reason: "no-platform-scheduler" };
|
|
103
139
|
}
|
|
104
|
-
return shouldDisableRecurringJobsRuntime(env)
|
|
140
|
+
return shouldDisableRecurringJobsRuntime(env, platform)
|
|
105
141
|
? { available: false, reason: "local-development" }
|
|
106
142
|
: { available: true, driver: "in-process" };
|
|
107
143
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type SweepTriggerAuthorization = {
|
|
2
|
+
ok: true;
|
|
3
|
+
} | {
|
|
4
|
+
ok: false;
|
|
5
|
+
status: 401 | 405 | 503;
|
|
6
|
+
error: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Netlify's scheduled function and the Cloudflare worker's `scheduled` handler
|
|
10
|
+
* POST a short-lived token signed with A2A_SECRET. Vercel Cron can only send a
|
|
11
|
+
* GET carrying the project's CRON_SECRET as a bearer, so that is the one other
|
|
12
|
+
* request shape the sweep accepts.
|
|
13
|
+
*/
|
|
14
|
+
export declare function authorizeSweepTrigger(input: {
|
|
15
|
+
method: string;
|
|
16
|
+
authorization: string | undefined;
|
|
17
|
+
cronSecret: string | undefined;
|
|
18
|
+
}): SweepTriggerAuthorization;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { extractBearerToken, verifyInternalToken, } from "../../integrations/internal-token.js";
|
|
3
|
+
import { RECURRING_JOBS_SWEEP_TOKEN_SUBJECT } from "../../jobs/scheduler-dispatch.js";
|
|
4
|
+
/**
|
|
5
|
+
* Netlify's scheduled function and the Cloudflare worker's `scheduled` handler
|
|
6
|
+
* POST a short-lived token signed with A2A_SECRET. Vercel Cron can only send a
|
|
7
|
+
* GET carrying the project's CRON_SECRET as a bearer, so that is the one other
|
|
8
|
+
* request shape the sweep accepts.
|
|
9
|
+
*/
|
|
10
|
+
export function authorizeSweepTrigger(input) {
|
|
11
|
+
if (input.method === "POST") {
|
|
12
|
+
const token = extractBearerToken(input.authorization);
|
|
13
|
+
return token &&
|
|
14
|
+
verifyInternalToken(RECURRING_JOBS_SWEEP_TOKEN_SUBJECT, token)
|
|
15
|
+
? { ok: true }
|
|
16
|
+
: { ok: false, status: 401, error: "Invalid or expired internal token" };
|
|
17
|
+
}
|
|
18
|
+
if (input.method === "GET") {
|
|
19
|
+
if (!input.cronSecret) {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
status: 503,
|
|
23
|
+
error: "CRON_SECRET is not set on this deployment, so a cron request cannot be verified.",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return bearerMatches(input.authorization, input.cronSecret)
|
|
27
|
+
? { ok: true }
|
|
28
|
+
: { ok: false, status: 401, error: "Invalid cron secret" };
|
|
29
|
+
}
|
|
30
|
+
return { ok: false, status: 405, error: "Method not allowed" };
|
|
31
|
+
}
|
|
32
|
+
function bearerMatches(header, secret) {
|
|
33
|
+
const expected = Buffer.from(`Bearer ${secret}`, "utf8");
|
|
34
|
+
const actual = Buffer.from(header?.trim() ?? "", "utf8");
|
|
35
|
+
return actual.length === expected.length && timingSafeEqual(actual, expected);
|
|
36
|
+
}
|
|
@@ -35,7 +35,7 @@ import { createDbAdminAgentTools } from "../db-admin/agent-tools.js";
|
|
|
35
35
|
import { isTransientDatabaseError } from "../db/client.js";
|
|
36
36
|
import { filterFrameworkToolGroups, resolveFrameworkTools, } from "../framework-tools.js";
|
|
37
37
|
import { verifyInternalToken, extractBearerToken, } from "../integrations/internal-token.js";
|
|
38
|
-
import { RECURRING_JOBS_SWEEP_PATH
|
|
38
|
+
import { RECURRING_JOBS_SWEEP_PATH } from "../jobs/scheduler-dispatch.js";
|
|
39
39
|
import { RECURRING_SWEEP_BUDGET_MS } from "../jobs/sweep-hooks.js";
|
|
40
40
|
import { CHATGPT_SUBSCRIPTION_LAB } from "../labs/core-labs.js";
|
|
41
41
|
import { getUserLabEnabled } from "../labs/store.js";
|
|
@@ -184,6 +184,7 @@ import { isLocalhost, shouldBlockInProductCodeEditingSurface, } from "./agent-ch
|
|
|
184
184
|
import { loadRunCodeToolEntries } from "./agent-chat/run-code-tools.js";
|
|
185
185
|
import { createAgentEngineScriptEntries, createAgentLoopSettingsScriptEntries, createCallAgentScriptEntry, createChatScriptEntries, createDbScriptEntries, createDocsScriptEntries, createResourceScriptEntries, } from "./agent-chat/script-entries.js";
|
|
186
186
|
import { isRuntimeVisibleScope, parseSkillFrontmatter, } from "./agent-chat/skill-frontmatter.js";
|
|
187
|
+
import { authorizeSweepTrigger } from "./agent-chat/sweep-trigger-auth.js";
|
|
187
188
|
import { shouldDisableInProcessSweeps } from "./sweep-runtime.js";
|
|
188
189
|
export { loadResourcesForPrompt };
|
|
189
190
|
export { _agentChatPromptSectionsForTests };
|
|
@@ -5796,6 +5797,7 @@ Non-code requests are still fine on this surface: read data, navigate the UI, su
|
|
|
5796
5797
|
title: body?.title ?? "",
|
|
5797
5798
|
scope: bodyIncludesScope ? bodyScope : requestedScope,
|
|
5798
5799
|
source: options?.appId ? { appId: options.appId } : null,
|
|
5800
|
+
orgId: await getOrgIdFromEvent(event),
|
|
5799
5801
|
});
|
|
5800
5802
|
return thread;
|
|
5801
5803
|
}
|
|
@@ -6275,19 +6277,20 @@ Non-code requests are still fine on this surface: read data, navigate the UI, su
|
|
|
6275
6277
|
const { processPendingAutomationFailureAlerts } = await import("../jobs/run-history.js");
|
|
6276
6278
|
return processPendingAutomationFailureAlerts();
|
|
6277
6279
|
};
|
|
6278
|
-
//
|
|
6279
|
-
// the
|
|
6280
|
-
//
|
|
6280
|
+
// Every platform trigger lands here: Netlify's scheduled function (via
|
|
6281
|
+
// the durable background function), Vercel Cron, and the Cloudflare
|
|
6282
|
+
// worker's Cron Trigger. Keeping the sweep behind an authenticated,
|
|
6283
|
+
// fixed route prevents a public request from choosing an owner or job.
|
|
6281
6284
|
getH3App(nitroApp).use(RECURRING_JOBS_SWEEP_PATH, defineEventHandler(async (event) => {
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
setResponseStatus(event,
|
|
6290
|
-
return { error:
|
|
6285
|
+
const { readDeployCredentialEnv } = await import("./credential-provider.js");
|
|
6286
|
+
const authorization = authorizeSweepTrigger({
|
|
6287
|
+
method: getMethod(event),
|
|
6288
|
+
authorization: getHeader(event, "authorization"),
|
|
6289
|
+
cronSecret: readDeployCredentialEnv("CRON_SECRET"),
|
|
6290
|
+
});
|
|
6291
|
+
if (!authorization.ok) {
|
|
6292
|
+
setResponseStatus(event, authorization.status);
|
|
6293
|
+
return { error: authorization.error };
|
|
6291
6294
|
}
|
|
6292
6295
|
if (isNetlifyRecurringJobsRuntime() &&
|
|
6293
6296
|
!isInBackgroundFunctionRuntime()) {
|
|
@@ -6694,6 +6697,10 @@ Non-code requests are still fine on this surface: read data, navigate the UI, su
|
|
|
6694
6697
|
"/mcp",
|
|
6695
6698
|
"/.well-known/agent-card.json",
|
|
6696
6699
|
"/_agent-native/a2a",
|
|
6700
|
+
// A platform scheduler usually lands on a cold instance. Without the
|
|
6701
|
+
// gate the first sweep 404s, or runs before the trigger dispatcher
|
|
6702
|
+
// registers its sweep handler and silently skips queued events.
|
|
6703
|
+
RECURRING_JOBS_SWEEP_PATH,
|
|
6697
6704
|
],
|
|
6698
6705
|
});
|
|
6699
6706
|
nitroApp.hooks?.hook?.("close", async () => {
|
|
@@ -9,16 +9,16 @@ export declare const AGENT_ENGINE_API_KEY_ACTION_NAME = "agent-engine-api-key";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function createAgentEngineDisconnectHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
11
11
|
error: string;
|
|
12
|
-
scope?: undefined;
|
|
13
12
|
ok?: undefined;
|
|
13
|
+
scope?: undefined;
|
|
14
14
|
} | {
|
|
15
15
|
ok: boolean;
|
|
16
16
|
error: any;
|
|
17
17
|
scope?: undefined;
|
|
18
18
|
} | {
|
|
19
|
+
error?: undefined;
|
|
19
20
|
ok: boolean;
|
|
20
21
|
scope: "org" | "user";
|
|
21
|
-
error?: undefined;
|
|
22
22
|
}>>;
|
|
23
23
|
export interface DefaultModelSelectionRequest {
|
|
24
24
|
engine: string;
|
package/dist/server/auth.js
CHANGED
|
@@ -2789,10 +2789,10 @@ function createAuthGuardFn(app) {
|
|
|
2789
2789
|
p === "/_agent-native/creative-context/process-background") {
|
|
2790
2790
|
return;
|
|
2791
2791
|
}
|
|
2792
|
-
// Scheduled recurring-job sweeps are
|
|
2793
|
-
//
|
|
2794
|
-
// short-lived HMAC token
|
|
2795
|
-
// carry a browser session, so let the route
|
|
2792
|
+
// Scheduled recurring-job sweeps are fired by the platform scheduler
|
|
2793
|
+
// (Netlify's scheduled function, a Cloudflare Cron Trigger, or Vercel Cron)
|
|
2794
|
+
// and authenticate with a short-lived HMAC token or Vercel's CRON_SECRET.
|
|
2795
|
+
// They do not carry a browser session, so let the route check them itself.
|
|
2796
2796
|
if (p === "/_agent-native/jobs/_process-sweep") {
|
|
2797
2797
|
return;
|
|
2798
2798
|
}
|
|
@@ -178,6 +178,7 @@ export function getH3App(nitroApp) {
|
|
|
178
178
|
registerMiddleware(nitroApp, "", createCsrfMiddleware());
|
|
179
179
|
registerRequestContextBoundary(nitroApp);
|
|
180
180
|
nitroApp.hooks?.hook?.("request", async (event) => {
|
|
181
|
+
keepRequestOpenForPluginInit(nitroApp, event);
|
|
181
182
|
translatePublicFrameworkRequest(event);
|
|
182
183
|
const reqPath = event.url?.pathname ?? "";
|
|
183
184
|
if (resolveMountMatch(reqPath, FRAMEWORK_PREFIX) ||
|
|
@@ -363,6 +364,9 @@ export function trackPluginInit(nitroApp, promise, options = {}) {
|
|
|
363
364
|
paths: options.paths?.filter(Boolean),
|
|
364
365
|
excludedPaths: options.excludedPaths?.filter(Boolean),
|
|
365
366
|
};
|
|
367
|
+
void safe.then(() => {
|
|
368
|
+
entry.settled = true;
|
|
369
|
+
});
|
|
366
370
|
const existing = nitroApp[PLUGIN_READY_KEY];
|
|
367
371
|
if (existing) {
|
|
368
372
|
existing.push(entry);
|
|
@@ -443,6 +447,21 @@ function debugClientAbort(args) {
|
|
|
443
447
|
const message = err?.message || String(args.error);
|
|
444
448
|
console.debug?.(`[agent-native] ${args.method ?? ""} ${args.route} aborted by client: ${message}`);
|
|
445
449
|
}
|
|
450
|
+
/**
|
|
451
|
+
* workerd stops a request's pending I/O once it responds, so plugin init that
|
|
452
|
+
* a page load started would never finish, and every route behind the readiness
|
|
453
|
+
* gate would time out on that isolate. Keep each request open until it does.
|
|
454
|
+
*/
|
|
455
|
+
function keepRequestOpenForPluginInit(nitroApp, event) {
|
|
456
|
+
const waitUntil = event.req
|
|
457
|
+
?.waitUntil;
|
|
458
|
+
if (typeof waitUntil !== "function")
|
|
459
|
+
return;
|
|
460
|
+
const pending = (nitroApp[PLUGIN_READY_KEY] ?? []).filter((entry) => !entry.settled);
|
|
461
|
+
if (!pending.length)
|
|
462
|
+
return;
|
|
463
|
+
waitUntil.call(event.req, Promise.all(pending.map((entry) => entry.promise)));
|
|
464
|
+
}
|
|
446
465
|
export async function awaitPluginsReady(nitroApp, reqPath, options = {}) {
|
|
447
466
|
const entries = nitroApp[PLUGIN_READY_KEY];
|
|
448
467
|
if (!entries?.length)
|
|
@@ -308,6 +308,7 @@ async function emitTelemetry(event, state, response, durationMs) {
|
|
|
308
308
|
db_url_hash: db.urlHash,
|
|
309
309
|
db_neon_endpoint: db.neon?.endpointId,
|
|
310
310
|
db_neon_pooled: db.neon?.pooled,
|
|
311
|
+
db_measured: state.dbMeasured,
|
|
311
312
|
db_operation_count: state.db.operationCount,
|
|
312
313
|
db_query_count: state.db.queryCount,
|
|
313
314
|
db_rows_returned: state.db.rowsReturned,
|
|
@@ -437,6 +438,7 @@ function logSlowRequest(event, state, response, durationMs, pathname) {
|
|
|
437
438
|
module_to_request_ms: moduleToRequestMs(state),
|
|
438
439
|
process_age_ms: state.processAgeAtStartMs,
|
|
439
440
|
framework_ready_wait_ms: Math.round(state.frameworkReadyWaitMs),
|
|
441
|
+
db_measured: state.dbMeasured,
|
|
440
442
|
db_ms: Math.round(state.db.operationWallMs),
|
|
441
443
|
db_connect_ms: Math.round(state.db.connectTotalMs),
|
|
442
444
|
db_operation_count: state.db.operationCount,
|
|
@@ -481,10 +483,11 @@ export function installHttpResponseTelemetryHooks(nitroApp) {
|
|
|
481
483
|
requestSequence: ++processState.requestSequence,
|
|
482
484
|
frameworkReadyWaitMs: 0,
|
|
483
485
|
db: createDatabaseRequestTelemetry(),
|
|
486
|
+
dbMeasured: false,
|
|
484
487
|
};
|
|
485
488
|
event.context[REQUEST_TELEMETRY_KEY] =
|
|
486
489
|
state;
|
|
487
|
-
enterDatabaseRequestTelemetry(state.db);
|
|
490
|
+
state.dbMeasured = enterDatabaseRequestTelemetry(state.db);
|
|
488
491
|
try {
|
|
489
492
|
event.res.headers.set(REQUEST_ID_HEADER, state.requestId);
|
|
490
493
|
event.res.errHeaders.set(REQUEST_ID_HEADER, state.requestId);
|
|
@@ -54,8 +54,8 @@ export declare function createRealtimeTokenHandler(): import("h3").EventHandlerW
|
|
|
54
54
|
expiresAt?: undefined;
|
|
55
55
|
ttlSeconds?: undefined;
|
|
56
56
|
} | {
|
|
57
|
+
error?: undefined;
|
|
57
58
|
token: string;
|
|
58
59
|
expiresAt: string;
|
|
59
60
|
ttlSeconds: number;
|
|
60
|
-
error?: undefined;
|
|
61
61
|
}>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentActionScope } from "../agent/types.js";
|
|
2
2
|
import type { TrackingEventScope } from "../observability/tracing.js";
|
|
3
|
+
import type { ContextStatus } from "../shared/context-status.js";
|
|
3
4
|
import type { SignupAttributionContext } from "./attribution.js";
|
|
4
5
|
export interface RequestRunContext {
|
|
5
6
|
waitUntil?: (promise: Promise<unknown>) => void;
|
|
@@ -30,6 +31,11 @@ export interface RequestRunContext {
|
|
|
30
31
|
analyticsJevPrefetch?: {
|
|
31
32
|
preloadedReferenceCount: number;
|
|
32
33
|
};
|
|
34
|
+
/** Whether the pre-model reference prefetch and screen grounding reached the model. */
|
|
35
|
+
contextStatus?: {
|
|
36
|
+
prefetch?: ContextStatus;
|
|
37
|
+
screen?: ContextStatus;
|
|
38
|
+
};
|
|
33
39
|
toolCalls?: Array<{
|
|
34
40
|
name: string;
|
|
35
41
|
input: unknown;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a piece of per-turn grounding reached the model. `empty` is a real
|
|
3
|
+
* answer (nothing relevant); `timed_out` and `failed` mean the model is
|
|
4
|
+
* working without context it would normally have, and must be told so.
|
|
5
|
+
*/
|
|
6
|
+
export type ContextStatus = "ok" | "empty" | "timed_out" | "failed";
|
|
7
|
+
export declare function isContextStatus(value: unknown): value is ContextStatus;
|
|
8
|
+
/**
|
|
9
|
+
* The status an app hook reported, from an object with a `status` field.
|
|
10
|
+
* Undefined means the hook reported nothing; a status this code doesn't know
|
|
11
|
+
* is a hook bug, so it counts as `failed` rather than as silence.
|
|
12
|
+
*/
|
|
13
|
+
export declare function readReportedContextStatus(value: unknown): ContextStatus | undefined;
|
|
14
|
+
export declare function worstContextStatus(...statuses: ReadonlyArray<ContextStatus | undefined>): ContextStatus | undefined;
|
|
15
|
+
export declare function isContextDegraded(status: ContextStatus | undefined): boolean;
|
|
16
|
+
export declare function screenContextUnavailableNote(canViewScreen: boolean): string;
|
|
17
|
+
export declare const SELECTION_CONTEXT_UNAVAILABLE_NOTE: string;
|
|
18
|
+
/** `partial` when another source did deliver context this turn. */
|
|
19
|
+
export declare function preloadedContextUnavailableNote(status: ContextStatus, options?: {
|
|
20
|
+
partial?: boolean;
|
|
21
|
+
}): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const SEVERITY = {
|
|
2
|
+
empty: 0,
|
|
3
|
+
ok: 1,
|
|
4
|
+
timed_out: 2,
|
|
5
|
+
failed: 3,
|
|
6
|
+
};
|
|
7
|
+
export function isContextStatus(value) {
|
|
8
|
+
return typeof value === "string" && Object.hasOwn(SEVERITY, value);
|
|
9
|
+
}
|
|
10
|
+
const warnedInvalidStatuses = new Set();
|
|
11
|
+
/**
|
|
12
|
+
* The status an app hook reported, from an object with a `status` field.
|
|
13
|
+
* Undefined means the hook reported nothing; a status this code doesn't know
|
|
14
|
+
* is a hook bug, so it counts as `failed` rather than as silence.
|
|
15
|
+
*/
|
|
16
|
+
export function readReportedContextStatus(value) {
|
|
17
|
+
if (!value || typeof value !== "object")
|
|
18
|
+
return undefined;
|
|
19
|
+
const status = value.status;
|
|
20
|
+
if (status === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
if (isContextStatus(status))
|
|
23
|
+
return status;
|
|
24
|
+
const shown = String(status).slice(0, 40);
|
|
25
|
+
if (!warnedInvalidStatuses.has(shown)) {
|
|
26
|
+
warnedInvalidStatuses.add(shown);
|
|
27
|
+
console.warn(`[agent-chat] unknown context status "${shown}" reported by prepareRequest; treating it as failed`);
|
|
28
|
+
}
|
|
29
|
+
return "failed";
|
|
30
|
+
}
|
|
31
|
+
export function worstContextStatus(...statuses) {
|
|
32
|
+
let worst;
|
|
33
|
+
for (const status of statuses) {
|
|
34
|
+
if (status && (!worst || SEVERITY[status] > SEVERITY[worst])) {
|
|
35
|
+
worst = status;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return worst;
|
|
39
|
+
}
|
|
40
|
+
export function isContextDegraded(status) {
|
|
41
|
+
return status === "timed_out" || status === "failed";
|
|
42
|
+
}
|
|
43
|
+
const wrapNote = (text) => `\n\n<context-note>${text}</context-note>`;
|
|
44
|
+
export function screenContextUnavailableNote(canViewScreen) {
|
|
45
|
+
return wrapNote(canViewScreen
|
|
46
|
+
? "Current screen unavailable this turn; call view-screen before editing or answering about the open page."
|
|
47
|
+
: "Current screen unavailable this turn; ask the user what is open before editing or answering about the page.");
|
|
48
|
+
}
|
|
49
|
+
export const SELECTION_CONTEXT_UNAVAILABLE_NOTE = wrapNote("Selected text unavailable this turn; ask the user to paste it if the request refers to a selection.");
|
|
50
|
+
/** `partial` when another source did deliver context this turn. */
|
|
51
|
+
export function preloadedContextUnavailableNote(status, options = {}) {
|
|
52
|
+
const reason = status === "timed_out" ? "timed out" : "failed";
|
|
53
|
+
return wrapNote(`${options.partial ? "Some preloaded context" : "Preloaded context"} was unavailable this turn (${reason}); search for anything relevant with the available tools before answering.`);
|
|
54
|
+
}
|
|
@@ -129,7 +129,14 @@ function ChatThreadRouteContent({
|
|
|
129
129
|
onIntegrityReport: reportStreamIntegrity,
|
|
130
130
|
}}
|
|
131
131
|
threadId={resolvedThreadId}
|
|
132
|
-
labels={{
|
|
132
|
+
labels={{
|
|
133
|
+
composerPlaceholder: t("chat.composerPlaceholder"),
|
|
134
|
+
continueRun: t("agentChat.common.continue"), // i18n-key-ignore shared framework catalog
|
|
135
|
+
continueRunUnavailable: t(
|
|
136
|
+
// i18n-key-ignore shared framework catalog
|
|
137
|
+
"agentChat.recovery.continueUnavailable",
|
|
138
|
+
),
|
|
139
|
+
}}
|
|
133
140
|
slots={{
|
|
134
141
|
emptyState: ChatEmptyState,
|
|
135
142
|
message: ChatMessage,
|
|
@@ -90,7 +90,7 @@ Use the web-request tool with ${keys.SLACK_WEBHOOK}.
|
|
|
90
90
|
| `mcpTools` | `string[]?` | Exact MCP tool allowlist for this automation |
|
|
91
91
|
| `lastRun` | `string?` | ISO timestamp of last execution |
|
|
92
92
|
| `lastStatus` | `string?` | `success`, `error`, `running`, `skipped`, or `paused` |
|
|
93
|
-
| `lastError` | `string?` | The
|
|
93
|
+
| `lastError` | `string?` | The last failure cause or declared skip reason |
|
|
94
94
|
| `lastErrorCode` | `string?` | Typed code of the last failure (see Failure handling) |
|
|
95
95
|
| `consecutiveFailures` | `number?` | Run of identical `lastErrorCode` failures |
|
|
96
96
|
| `pausedReason` | `string?` | Set with `enabled: false` when the framework paused it |
|
|
@@ -112,6 +112,13 @@ All automation operations are accessed through a single `manage-automations` too
|
|
|
112
112
|
|
|
113
113
|
Additional tool: `web-request` — outbound HTTP with `${keys.NAME}` substitution.
|
|
114
114
|
|
|
115
|
+
During an automation run, `automation-no-op` declares that no action or report
|
|
116
|
+
was needed. Pass a short `reason` (1–500 characters), such as "No urgent mail
|
|
117
|
+
found." The runner records `skipped` in the list and Past runs without counting
|
|
118
|
+
a failure or sending a report. This declaration cannot cover a failed tool,
|
|
119
|
+
rejected send, or missing credentials. Closing prose alone does not declare a
|
|
120
|
+
no-op: a run needs confirmed work, delivered output, or this structured signal.
|
|
121
|
+
|
|
115
122
|
`manage-automations` accepts personal or organization scope and supports
|
|
116
123
|
`model`, `reasoning_effort`, and `mcpTools` on define/update. An MCP allowlist
|
|
117
124
|
is enforced, not advisory: every named tool must resolve in the creator's
|
|
@@ -24,7 +24,9 @@ This skill covers only what is specific to the legacy scheduled path: the
|
|
|
24
24
|
|
|
25
25
|
1. User asks for something recurring via the agent chat
|
|
26
26
|
2. Agent uses `manage-jobs` tool (action: "create") to write a job file at `jobs/<name>.md`
|
|
27
|
-
3. A scheduler
|
|
27
|
+
3. A scheduler tick finds due jobs about once a minute. Long-running servers
|
|
28
|
+
fire it in-process; Netlify, Vercel, and Cloudflare fire it from a platform
|
|
29
|
+
trigger the build emits; AWS Lambda has no trigger, so jobs never fire there
|
|
28
30
|
4. Due jobs enter the shared background-automation runner, on the same
|
|
29
31
|
execution lifecycle as event automations
|
|
30
32
|
5. Job results are saved as chat threads
|
|
@@ -13,8 +13,6 @@ declare const _default: import("../../action.js").ActionDefinition<{
|
|
|
13
13
|
executionEngine?: string;
|
|
14
14
|
executionCwd?: string;
|
|
15
15
|
}, {
|
|
16
|
-
deleted?: undefined;
|
|
17
|
-
enabled?: undefined;
|
|
18
16
|
created: boolean;
|
|
19
17
|
name: string;
|
|
20
18
|
scope: "organization" | "personal";
|
|
@@ -25,31 +23,33 @@ declare const _default: import("../../action.js").ActionDefinition<{
|
|
|
25
23
|
reasoningEffort: "auto" | "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh";
|
|
26
24
|
webhookPath: string;
|
|
27
25
|
nextRun: string;
|
|
26
|
+
deleted?: undefined;
|
|
27
|
+
enabled?: undefined;
|
|
28
28
|
executionHostId?: undefined;
|
|
29
29
|
executionEngine?: undefined;
|
|
30
30
|
executionCwd?: undefined;
|
|
31
31
|
} | {
|
|
32
|
-
enabled?: undefined;
|
|
33
|
-
nextRun?: undefined;
|
|
34
|
-
created?: undefined;
|
|
35
32
|
scope?: undefined;
|
|
33
|
+
created?: undefined;
|
|
36
34
|
triggerType?: undefined;
|
|
37
35
|
event?: undefined;
|
|
38
36
|
deleted: boolean;
|
|
39
37
|
name: string;
|
|
38
|
+
enabled?: undefined;
|
|
40
39
|
schedule?: undefined;
|
|
41
40
|
timezone?: undefined;
|
|
42
41
|
reasoningEffort?: undefined;
|
|
43
42
|
executionHostId?: undefined;
|
|
44
43
|
executionEngine?: undefined;
|
|
45
44
|
executionCwd?: undefined;
|
|
45
|
+
nextRun?: undefined;
|
|
46
46
|
webhookPath?: undefined;
|
|
47
47
|
} | {
|
|
48
|
-
deleted?: undefined;
|
|
49
|
-
created?: undefined;
|
|
50
48
|
scope?: undefined;
|
|
49
|
+
created?: undefined;
|
|
51
50
|
triggerType?: undefined;
|
|
52
51
|
event?: undefined;
|
|
52
|
+
deleted?: undefined;
|
|
53
53
|
name: string;
|
|
54
54
|
enabled: boolean;
|
|
55
55
|
schedule: string;
|
|
@@ -96,11 +96,14 @@ Execute the following automation instructions, and only these:
|
|
|
96
96
|
|
|
97
97
|
${input.body}`;
|
|
98
98
|
}
|
|
99
|
-
async function recordTriggerSkip(resource, status, reason) {
|
|
99
|
+
async function recordTriggerSkip(resource, status, reason, errorCode) {
|
|
100
100
|
await recordTriggerExecutionOutcome(resource, {
|
|
101
101
|
lastCheck: new Date().toISOString(),
|
|
102
102
|
lastStatus: status,
|
|
103
103
|
lastError: reason,
|
|
104
|
+
...(status === "error" && errorCode !== undefined
|
|
105
|
+
? { lastErrorCode: errorCode }
|
|
106
|
+
: {}),
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
async function recordTriggerExecutionOutcome(resource, outcome,
|
|
@@ -674,7 +677,7 @@ async function dispatchQueuedAutomationEvent(queued, deps, hardDeadlineAt) {
|
|
|
674
677
|
resolved = await resolveAutomationExecutionIdentity(resource.owner, meta);
|
|
675
678
|
}
|
|
676
679
|
catch (error) {
|
|
677
|
-
await recordTriggerSkip(resource, "error", "Could not verify the automation execution identity.");
|
|
680
|
+
await recordTriggerSkip(resource, "error", "Could not verify the automation execution identity.", "owner_unverifiable");
|
|
678
681
|
throw error;
|
|
679
682
|
}
|
|
680
683
|
if (!resolved.ok) {
|
|
@@ -693,7 +696,7 @@ async function dispatchQueuedAutomationEvent(queued, deps, hardDeadlineAt) {
|
|
|
693
696
|
});
|
|
694
697
|
return "completed";
|
|
695
698
|
}
|
|
696
|
-
await recordTriggerSkip(resource, "
|
|
699
|
+
await recordTriggerSkip(resource, "error", resolved.reason, resolved.code);
|
|
697
700
|
return "completed";
|
|
698
701
|
}
|
|
699
702
|
if (!automationMatchesEventOwner(resolved.identity, queued.eventOwner)) {
|
|
@@ -909,7 +912,7 @@ async function dispatchAgentic(resource, payload, eventMeta, identity, hardDeadl
|
|
|
909
912
|
}
|
|
910
913
|
: undefined;
|
|
911
914
|
try {
|
|
912
|
-
await runBackgroundAutomation({
|
|
915
|
+
const result = await runBackgroundAutomation({
|
|
913
916
|
automation,
|
|
914
917
|
ownerEmail: jobUserEmail,
|
|
915
918
|
orgId: jobOrgId,
|
|
@@ -936,10 +939,10 @@ async function dispatchAgentic(resource, payload, eventMeta, identity, hardDeadl
|
|
|
936
939
|
...(hardDeadlineAt === undefined ? {} : { hardDeadlineAt }),
|
|
937
940
|
}, _deps);
|
|
938
941
|
await recordTriggerExecutionOutcome(latest, {
|
|
939
|
-
lastStatus:
|
|
940
|
-
lastError: undefined,
|
|
942
|
+
lastStatus: result.status,
|
|
943
|
+
lastError: result.status === "skipped" ? result.reason : undefined,
|
|
941
944
|
});
|
|
942
|
-
console.log(`[triggers] "${triggerName}"
|
|
945
|
+
console.log(`[triggers] "${triggerName}" ${result.status}`);
|
|
943
946
|
return true;
|
|
944
947
|
}
|
|
945
948
|
catch (err) {
|
|
@@ -28,7 +28,7 @@ When any **mutating** action runs (anything that isn't a read-only `GET`), the f
|
|
|
28
28
|
- **Action** — the action name (e.g. `delete-recording`).
|
|
29
29
|
- **Actor** — `agent`, `human`, or `system`, plus the actor's email — populated **even for agent calls**, so you get "the agent, acting for alice@, …".
|
|
30
30
|
- **Run linkage** — the agent `threadId` / `turnId` that triggered the call (a tool call), so a mutation traces back to the exact agent turn.
|
|
31
|
-
- **Surface** — `tool` (agent), `frontend`, `http`, `cli`, `mcp`, or `a2a`.
|
|
31
|
+
- **Surface** — `tool` (agent), `frontend`, `http`, `cli`, `mcp`, `webmcp`, or `a2a`. These are agent protocols, so a call over `mcp`, `webmcp`, or `a2a` records as `agent` acting for you, not as you.
|
|
32
32
|
- **Outcome** — `success`, `error` (with an error code), or `denied` (blocked by a human-approval gate).
|
|
33
33
|
- **Inputs** — the call arguments, with credential-shaped values [redacted](#privacy).
|
|
34
34
|
- **Target & owner** — the resource the action changed, used to [scope reads](#reading).
|
|
@@ -57,13 +57,13 @@ No wiring needed — the capture hooks into `defineAction` transparently. Read-o
|
|
|
57
57
|
name: "caller",
|
|
58
58
|
type: "enum",
|
|
59
59
|
nullable: false,
|
|
60
|
-
note: "tool | frontend | http | cli | mcp | a2a — the surface that invoked the action.",
|
|
60
|
+
note: "tool | frontend | http | cli | mcp | webmcp | a2a — the surface that invoked the action.",
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
63
|
name: "actor_kind",
|
|
64
64
|
type: "enum",
|
|
65
65
|
nullable: false,
|
|
66
|
-
note: "agent | human | system",
|
|
66
|
+
note: "agent | human | service | system — service for the organization's own service principals, agent for other tool, mcp, webmcp, and a2a calls.",
|
|
67
67
|
},
|
|
68
68
|
{ name: "actor_email", type: "text", nullable: true },
|
|
69
69
|
{ name: "org_id", type: "text", nullable: true },
|