@agent-native/core 0.204.0 → 0.204.1-nightly-20261008065100
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/automation/index.d.ts +1 -1
- package/dist/cli/skills.d.ts +1 -0
- package/dist/cli/skills.js +1 -1
- package/dist/client/agent-chat/index.d.ts +1 -1
- package/dist/client/agent-chat/index.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 +10 -4
- package/dist/client/embed-auth.d.ts +15 -0
- package/dist/client/embed-auth.js +77 -7
- package/dist/client/host/index.d.ts +1 -1
- package/dist/client/host/index.js +1 -1
- package/dist/client/mcp-app-host.d.ts +19 -0
- package/dist/client/mcp-app-host.js +88 -2
- package/dist/client/use-chat-threads.d.ts +1 -1
- package/dist/client/use-chat-threads.js +2 -0
- package/dist/client/use-run-stuck-detection.d.ts +18 -1
- package/dist/client/use-run-stuck-detection.js +115 -75
- package/dist/collab/routes.d.ts +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- 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/builder.js +1 -1
- package/dist/file-upload/s3.js +1 -1
- package/dist/file-upload/types.d.ts +1 -0
- 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/mcp/build-server.js +22 -11
- package/dist/mcp/embed-app.js +143 -9
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +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 +10 -5
- 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/handlers.d.ts +1 -1
- package/dist/progress/actions.js +1 -0
- package/dist/provider-api/actions/custom-provider-registration.d.ts +13 -13
- package/dist/provider-api/actions/provider-api.d.ts +13 -13
- package/dist/provider-api/actions/provider-api.js +6 -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/resources/handlers.d.ts +1 -1
- package/dist/resources/script-helpers.d.ts +1 -0
- package/dist/resources/script-helpers.js +1 -1
- package/dist/resources/store.js +81 -0
- package/dist/scripts/resources/save-memory.js +3 -0
- package/dist/server/action-routes.js +34 -6
- package/dist/server/agent-chat/prompt-resources.d.ts +8 -2
- package/dist/server/agent-chat/prompt-resources.js +31 -8
- 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/script-entries.js +30 -3
- 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 +51 -47
- package/dist/server/agent-engine-default-model-route.d.ts +2 -2
- package/dist/server/agent-engine-ollama-models-route.d.ts +2 -2
- package/dist/server/auth.js +21 -6
- package/dist/server/embed-route.js +5 -2
- 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/shared/mcp-app-display.d.ts +20 -0
- package/dist/shared/mcp-app-display.js +34 -0
- package/dist/shared/mcp-app-widget-embed.d.ts +18 -0
- package/dist/shared/mcp-app-widget-embed.js +41 -0
- package/dist/templates/chat/app/components/chat/ChatRouteContent.tsx +9 -2
- package/dist/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +9 -2
- 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 +5 -5
- 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/mcp-apps.mdx +1 -1
- package/docs/content/recurring-jobs.mdx +29 -9
- package/docs/content/vercel.mdx +30 -0
- package/package.json +4 -3
- package/src/templates/chat/app/components/chat/ChatRouteContent.tsx +9 -2
- package/src/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +9 -2
- 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
package/dist/deploy/build.js
CHANGED
|
@@ -19,7 +19,7 @@ import { frameworkSessionHintCookieName, resolveAuthCookieNamespace, } from "../
|
|
|
19
19
|
import { resolveAgentNativeBuildId } from "../shared/build-id.js";
|
|
20
20
|
import { DEFAULT_SPECULATION_RULES_PATH, resolveSsrCacheHeaders, resolveSsrCacheKeyHeaders, SSR_QUERY_CACHE_KEY_HEADER, } from "../shared/cache-control.js";
|
|
21
21
|
import { EMBED_TARGET_QUERY_PARAM, EMBED_TOKEN_QUERY_PARAM, } from "../shared/embed-auth.js";
|
|
22
|
-
import { normalizeFrameworkRoutePrefix } from "../shared/framework-route-prefix.js";
|
|
22
|
+
import { FRAMEWORK_INTERNAL_ROUTE_PREFIX, normalizeFrameworkRoutePrefix, toPublicFrameworkPath, } from "../shared/framework-route-prefix.js";
|
|
23
23
|
import { mcpEmbedStaticAssetRouteRules } from "../shared/mcp-embed-headers.js";
|
|
24
24
|
import { isTruthyRuntimeValue } from "../shared/runtime-config.js";
|
|
25
25
|
import { AGENT_NATIVE_SOCIAL_IMAGE_ALT, AGENT_NATIVE_SOCIAL_IMAGE_CACHE_BUSTER, AGENT_NATIVE_SOCIAL_IMAGE_HEIGHT, AGENT_NATIVE_SOCIAL_IMAGE_PATH, AGENT_NATIVE_SOCIAL_IMAGE_TYPE, AGENT_NATIVE_SOCIAL_IMAGE_WIDTH, } from "../shared/social-meta.js";
|
|
@@ -294,7 +294,79 @@ export function shimCloudflarePagesModuleTimers(code) {
|
|
|
294
294
|
}
|
|
295
295
|
return code;
|
|
296
296
|
}
|
|
297
|
-
export
|
|
297
|
+
export const CLOUDFLARE_SWEEP_CRON = "* * * * *";
|
|
298
|
+
/**
|
|
299
|
+
* The URL path a platform scheduler requests. Under a custom framework route
|
|
300
|
+
* prefix the request boundary 404s `/_agent-native/*` before any route runs,
|
|
301
|
+
* and the server is mounted under the app base path, so the internal sweep
|
|
302
|
+
* path alone never reaches the sweep.
|
|
303
|
+
*/
|
|
304
|
+
export function publicRecurringJobsSweepPath(env = process.env) {
|
|
305
|
+
const basePath = normalizeAppBasePath(env.VITE_APP_BASE_PATH || env.APP_BASE_PATH);
|
|
306
|
+
const publicPath = toPublicFrameworkPath(RECURRING_JOBS_SWEEP_PATH, {
|
|
307
|
+
publicPrefix: resolveBuildFrameworkRoutePrefix(env),
|
|
308
|
+
});
|
|
309
|
+
return `${basePath}${publicPath}`;
|
|
310
|
+
}
|
|
311
|
+
// The token format must match verifyInternalToken in
|
|
312
|
+
// integrations/internal-token.ts.
|
|
313
|
+
function cloudflareSweepTriggerScript(sweepPath) {
|
|
314
|
+
return `const SWEEP_CRON = ${JSON.stringify(CLOUDFLARE_SWEEP_CRON)};
|
|
315
|
+
const SWEEP_PATH = ${JSON.stringify(sweepPath)};
|
|
316
|
+
const SWEEP_TOKEN_SUBJECT = ${JSON.stringify(RECURRING_JOBS_SWEEP_TOKEN_SUBJECT)};
|
|
317
|
+
|
|
318
|
+
async function sweepToken(secret) {
|
|
319
|
+
const timestamp = Date.now();
|
|
320
|
+
const encoder = new TextEncoder();
|
|
321
|
+
const key = await crypto.subtle.importKey(
|
|
322
|
+
"raw",
|
|
323
|
+
encoder.encode(secret),
|
|
324
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
325
|
+
false,
|
|
326
|
+
["sign"],
|
|
327
|
+
);
|
|
328
|
+
const signature = await crypto.subtle.sign(
|
|
329
|
+
"HMAC",
|
|
330
|
+
key,
|
|
331
|
+
encoder.encode(SWEEP_TOKEN_SUBJECT + ":" + timestamp),
|
|
332
|
+
);
|
|
333
|
+
const hex = Array.from(new Uint8Array(signature), (byte) =>
|
|
334
|
+
byte.toString(16).padStart(2, "0"),
|
|
335
|
+
).join("");
|
|
336
|
+
return timestamp + "." + hex;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async function runSweep(h, env, ctx) {
|
|
340
|
+
const secret = env?.A2A_SECRET;
|
|
341
|
+
if (!secret) {
|
|
342
|
+
throw new Error("[recurring-jobs] A2A_SECRET is required for the scheduled sweep");
|
|
343
|
+
}
|
|
344
|
+
const request = new Request(
|
|
345
|
+
new URL(SWEEP_PATH, env.APP_URL || "https://scheduled-sweep.invalid"),
|
|
346
|
+
{
|
|
347
|
+
method: "POST",
|
|
348
|
+
headers: {
|
|
349
|
+
Authorization: "Bearer " + (await sweepToken(secret)),
|
|
350
|
+
"Content-Type": "application/json",
|
|
351
|
+
"user-agent": "agent-native-cloudflare-cron",
|
|
352
|
+
},
|
|
353
|
+
body: "{}",
|
|
354
|
+
},
|
|
355
|
+
);
|
|
356
|
+
if (typeof ctx?.waitUntil === "function") {
|
|
357
|
+
request.waitUntil = ctx.waitUntil.bind(ctx);
|
|
358
|
+
}
|
|
359
|
+
const response = await h.fetch(request, env, ctx);
|
|
360
|
+
const body = await response.text();
|
|
361
|
+
if (!response.ok) {
|
|
362
|
+
throw new Error(
|
|
363
|
+
"[recurring-jobs] Scheduled sweep failed (" + response.status + "): " + body.slice(0, 500),
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
console.log("[recurring-jobs] Scheduled sweep finished", body.slice(0, 500));
|
|
367
|
+
}`;
|
|
368
|
+
}
|
|
369
|
+
export function generateCloudflareModuleWorkerEntry(env = process.env) {
|
|
298
370
|
return `let handler;
|
|
299
371
|
|
|
300
372
|
async function loadHandler() {
|
|
@@ -306,6 +378,8 @@ ${cloudflareBindingsInitScript()}
|
|
|
306
378
|
|
|
307
379
|
${cloudflareModuleTimerRestoreScript()}
|
|
308
380
|
|
|
381
|
+
${cloudflareSweepTriggerScript(publicRecurringJobsSweepPath(env))}
|
|
382
|
+
|
|
309
383
|
export default {
|
|
310
384
|
async fetch(request, env, ctx) {
|
|
311
385
|
if (typeof ctx?.waitUntil === "function") {
|
|
@@ -320,7 +394,10 @@ export default {
|
|
|
320
394
|
initializeBindings(env);
|
|
321
395
|
const h = await loadHandler();
|
|
322
396
|
__cfRestoreModuleTimers();
|
|
323
|
-
|
|
397
|
+
await Promise.all([
|
|
398
|
+
h.scheduled?.(controller, env, ctx),
|
|
399
|
+
controller?.cron === SWEEP_CRON ? runSweep(h, env, ctx) : undefined,
|
|
400
|
+
]);
|
|
324
401
|
},
|
|
325
402
|
async email(message, env, ctx) {
|
|
326
403
|
initializeBindings(env);
|
|
@@ -386,6 +463,13 @@ export function configureCloudflareModuleWorkerOutput(serverDir) {
|
|
|
386
463
|
}
|
|
387
464
|
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
388
465
|
config.main = CLOUDFLARE_MODULE_WORKER_ENTRY;
|
|
466
|
+
const crons = Array.isArray(config.triggers?.crons)
|
|
467
|
+
? config.triggers.crons.filter((cron) => typeof cron === "string")
|
|
468
|
+
: [];
|
|
469
|
+
config.triggers = {
|
|
470
|
+
...config.triggers,
|
|
471
|
+
crons: [...new Set([...crons, CLOUDFLARE_SWEEP_CRON])],
|
|
472
|
+
};
|
|
389
473
|
const compatibilityFlags = Array.isArray(config.compatibility_flags)
|
|
390
474
|
? config.compatibility_flags.filter((flag) => typeof flag === "string")
|
|
391
475
|
: [];
|
|
@@ -2696,6 +2780,92 @@ export function resolveKeepWarmSchedule() {
|
|
|
2696
2780
|
}
|
|
2697
2781
|
return raw;
|
|
2698
2782
|
}
|
|
2783
|
+
const DEFAULT_VERCEL_SWEEP_CRON_SCHEDULE = "* * * * *";
|
|
2784
|
+
// Vercel accepts a narrower grammar than cron-parser, and a schedule outside
|
|
2785
|
+
// it fails the deployment rather than the build.
|
|
2786
|
+
function vercelCronScheduleProblem(raw) {
|
|
2787
|
+
const fields = raw.split(/\s+/);
|
|
2788
|
+
if (fields.length !== 5 || !isValidCron(raw)) {
|
|
2789
|
+
return `must be a 5-field cron expression (minute hour day month weekday); got "${raw}" (${fields.length} field(s))`;
|
|
2790
|
+
}
|
|
2791
|
+
if (!fields.every((field) => /^[\d*,/-]+$/.test(field))) {
|
|
2792
|
+
return `must use numbers, not names such as MON or JAN, on Vercel; got "${raw}"`;
|
|
2793
|
+
}
|
|
2794
|
+
const [, , dayOfMonth, , dayOfWeek] = fields;
|
|
2795
|
+
if (dayOfMonth !== "*" && dayOfWeek !== "*") {
|
|
2796
|
+
return `cannot set both a day of the month and a day of the week on Vercel, so one must be "*"; got "${raw}"`;
|
|
2797
|
+
}
|
|
2798
|
+
const weekdays = dayOfWeek
|
|
2799
|
+
.split(",")
|
|
2800
|
+
.flatMap((part) => part.split("/")[0].split("-"));
|
|
2801
|
+
if (weekdays.some((day) => day !== "*" && Number(day) > 6)) {
|
|
2802
|
+
return `must number weekdays 0-6 (Sunday to Saturday) on Vercel; got "${raw}"`;
|
|
2803
|
+
}
|
|
2804
|
+
return null;
|
|
2805
|
+
}
|
|
2806
|
+
// Vercel Hobby rejects a deployment whose cron runs more than once a day, and
|
|
2807
|
+
// the build cannot see the team's plan, so the schedule is the operator's call.
|
|
2808
|
+
export function resolveVercelSweepCronSchedule(env = process.env) {
|
|
2809
|
+
const raw = env.AGENT_NATIVE_VERCEL_CRON_SCHEDULE?.trim();
|
|
2810
|
+
if (!raw)
|
|
2811
|
+
return DEFAULT_VERCEL_SWEEP_CRON_SCHEDULE;
|
|
2812
|
+
const problem = vercelCronScheduleProblem(raw);
|
|
2813
|
+
if (problem) {
|
|
2814
|
+
throw new Error(`AGENT_NATIVE_VERCEL_CRON_SCHEDULE ${problem}. ` +
|
|
2815
|
+
`Example: "0 9 * * *" for once a day on Vercel Hobby.`);
|
|
2816
|
+
}
|
|
2817
|
+
return raw;
|
|
2818
|
+
}
|
|
2819
|
+
export function vercelSweepCrons(sweepPaths, env = process.env) {
|
|
2820
|
+
const schedule = resolveVercelSweepCronSchedule(env);
|
|
2821
|
+
return sweepPaths.map((sweepPath) => ({ path: sweepPath, schedule }));
|
|
2822
|
+
}
|
|
2823
|
+
export function addVercelSweepCron(outputDir, env = process.env) {
|
|
2824
|
+
const configPath = path.join(outputDir, "config.json");
|
|
2825
|
+
if (!fs.existsSync(configPath)) {
|
|
2826
|
+
throw new Error(`[deploy] Nitro did not generate ${configPath} for vercel`);
|
|
2827
|
+
}
|
|
2828
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
2829
|
+
const [sweepCron] = vercelSweepCrons([publicRecurringJobsSweepPath(env)], env);
|
|
2830
|
+
config.crons = [
|
|
2831
|
+
...(config.crons ?? []).filter((cron) => cron.path !== sweepCron.path),
|
|
2832
|
+
sweepCron,
|
|
2833
|
+
];
|
|
2834
|
+
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
2835
|
+
console.log(`[build] Added Vercel cron "${sweepCron.schedule}" for ${sweepCron.path}. ` +
|
|
2836
|
+
"Vercel sends CRON_SECRET as its bearer, so set CRON_SECRET in the project." +
|
|
2837
|
+
(env.AGENT_NATIVE_VERCEL_CRON_SCHEDULE?.trim()
|
|
2838
|
+
? ""
|
|
2839
|
+
: " Hobby only allows daily crons: set AGENT_NATIVE_VERCEL_CRON_SCHEDULE " +
|
|
2840
|
+
'to a daily expression such as "0 9 * * *" there.'));
|
|
2841
|
+
}
|
|
2842
|
+
const SWEEP_PATH_AFTER_PREFIX = RECURRING_JOBS_SWEEP_PATH.slice(FRAMEWORK_INTERNAL_ROUTE_PREFIX.length);
|
|
2843
|
+
/**
|
|
2844
|
+
* Reads back the sweep cron `addVercelSweepCron` wrote for an app mounted at
|
|
2845
|
+
* `basePath`. A workspace deploy must reuse it rather than recompute it: the
|
|
2846
|
+
* app's build resolved its framework route prefix from config files the
|
|
2847
|
+
* workspace build never reads.
|
|
2848
|
+
*/
|
|
2849
|
+
export function readVercelSweepCron(outputDir, basePath) {
|
|
2850
|
+
const configPath = path.join(outputDir, "config.json");
|
|
2851
|
+
if (!fs.existsSync(configPath)) {
|
|
2852
|
+
throw new Error(`[deploy] Expected Vercel build config at ${configPath}`);
|
|
2853
|
+
}
|
|
2854
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
2855
|
+
const sweepCrons = (config.crons ?? []).filter((cron) => {
|
|
2856
|
+
if (!cron.path.startsWith(`${basePath}/`) ||
|
|
2857
|
+
!cron.path.endsWith(SWEEP_PATH_AFTER_PREFIX)) {
|
|
2858
|
+
return false;
|
|
2859
|
+
}
|
|
2860
|
+
const prefix = cron.path.slice(basePath.length, -SWEEP_PATH_AFTER_PREFIX.length);
|
|
2861
|
+
return /^\/[^/]+$/.test(prefix);
|
|
2862
|
+
});
|
|
2863
|
+
if (sweepCrons.length !== 1) {
|
|
2864
|
+
throw new Error(`[deploy] Expected one recurring-jobs sweep cron under ${basePath} in ${configPath}, found ${sweepCrons.length}. ` +
|
|
2865
|
+
"Build the app with this version of @agent-native/core so its scheduled work runs on Vercel.");
|
|
2866
|
+
}
|
|
2867
|
+
return sweepCrons[0];
|
|
2868
|
+
}
|
|
2699
2869
|
export function emitSingleTemplateNetlifyKeepWarmFunction(projectCwd) {
|
|
2700
2870
|
if (!isKeepWarmDeployEnabled()) {
|
|
2701
2871
|
const reason = isDisabledByEnv("AGENT_NATIVE_DISABLE_KEEP_WARM")
|
|
@@ -4147,6 +4317,9 @@ export default bundle;
|
|
|
4147
4317
|
if (isCloudflareModulePreset(preset)) {
|
|
4148
4318
|
configureCloudflareModuleWorkerOutput(nitro.options.output.serverDir);
|
|
4149
4319
|
}
|
|
4320
|
+
if (preset === "vercel") {
|
|
4321
|
+
addVercelSweepCron(nitro.options.output.dir);
|
|
4322
|
+
}
|
|
4150
4323
|
if (preset === "netlify" ||
|
|
4151
4324
|
preset === "vercel" ||
|
|
4152
4325
|
isAwsLambdaPreset(preset) ||
|
|
@@ -12,7 +12,7 @@ import { DEFAULT_WORKSPACE_APP_AUDIENCE, normalizeWorkspaceAppHomePath, normaliz
|
|
|
12
12
|
import { DISPATCH_WORKSPACE_ROOT_REDIRECTS, isValidWorkspaceAppIdFormat, } from "../shared/workspace-app-id.js";
|
|
13
13
|
import { createAgentNativeConfigContext, loadResolvedAgentNativeConfig, } from "../vite/agent-native-config-loader.js";
|
|
14
14
|
import { inferWorkspaceAppRootHomePath, readConfiguredWorkspaceAppHomePath, } from "../workspace-app-config.js";
|
|
15
|
-
import { assertEmittedBackgroundFunctionOnDisk, isRecurringJobsDeployEnabled, } from "./build.js";
|
|
15
|
+
import { assertEmittedBackgroundFunctionOnDisk, isRecurringJobsDeployEnabled, readVercelSweepCron, } from "./build.js";
|
|
16
16
|
import { cloneServerBundleForFunction, pruneSsrIslandFromRewritingClone, } from "./function-bundle.js";
|
|
17
17
|
import { collectImmutableAssetPaths, IMMUTABLE_ASSET_CACHE_HEADERS, } from "./immutable-assets.js";
|
|
18
18
|
function workspaceFrameworkRoutePrefixEnv() {
|
|
@@ -211,9 +211,13 @@ export async function runWorkspaceDeploy(opts = {}) {
|
|
|
211
211
|
}
|
|
212
212
|
console.log(`[workspace-deploy] Building ${apps.length} app(s) for preset=${preset}`);
|
|
213
213
|
const execFile = opts.execFile ?? execFileSync;
|
|
214
|
+
const sweepCrons = [];
|
|
214
215
|
for (const app of apps) {
|
|
215
216
|
buildOneApp(workspaceRoot, appsDir, app, preset, execFile, workspaceApps, workspaceAuthMode);
|
|
216
217
|
moveAppBuildIntoWorkspaceOutput(workspaceRoot, appsDir, app, preset, distDir, vercelOutputDir, workspaceApps, workspaceAuthMode);
|
|
218
|
+
if (preset === "vercel") {
|
|
219
|
+
sweepCrons.push(readVercelSweepCron(path.join(appsDir, app, VERCEL_OUTPUT_DIR), `/${app}`));
|
|
220
|
+
}
|
|
217
221
|
}
|
|
218
222
|
writeWorkspaceAppManifests(workspaceRoot, apps, workspaceApps, preset);
|
|
219
223
|
if (workspaceRootPage === "directory") {
|
|
@@ -224,7 +228,7 @@ export async function runWorkspaceDeploy(opts = {}) {
|
|
|
224
228
|
writeNetlifyHeaders(distDir, apps);
|
|
225
229
|
}
|
|
226
230
|
else {
|
|
227
|
-
writeVercelBuildConfig(vercelOutputDir, apps, workspaceApps, workspaceRootPage);
|
|
231
|
+
writeVercelBuildConfig(vercelOutputDir, apps, workspaceApps, workspaceRootPage, sweepCrons);
|
|
228
232
|
}
|
|
229
233
|
if (buildOnly) {
|
|
230
234
|
const outputDir = preset === "vercel" ? vercelOutputDir : distDir;
|
|
@@ -442,7 +446,7 @@ function netlifyHeaderBlock(pathname) {
|
|
|
442
446
|
...Object.entries(IMMUTABLE_ASSET_CACHE_HEADERS).map(([name, value]) => ` ${name}: ${value}`),
|
|
443
447
|
].join("\n");
|
|
444
448
|
}
|
|
445
|
-
function writeVercelBuildConfig(outputDir, apps, workspaceApps, rootPage) {
|
|
449
|
+
function writeVercelBuildConfig(outputDir, apps, workspaceApps, rootPage, sweepCrons) {
|
|
446
450
|
const routes = [
|
|
447
451
|
...vercelImmutableAssetHeaderRoutes(outputDir, apps),
|
|
448
452
|
{ handle: "filesystem" },
|
|
@@ -496,6 +500,7 @@ function writeVercelBuildConfig(outputDir, apps, workspaceApps, rootPage) {
|
|
|
496
500
|
const config = {
|
|
497
501
|
version: 3,
|
|
498
502
|
routes,
|
|
503
|
+
crons: sweepCrons,
|
|
499
504
|
};
|
|
500
505
|
fs.writeFileSync(path.join(outputDir, "config.json"), JSON.stringify(config, null, 2) + "\n");
|
|
501
506
|
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* Values are resolved server-side AFTER the model emits the tool call —
|
|
10
10
|
* the raw secret never enters the model's context.
|
|
11
11
|
*/
|
|
12
|
+
import { fail, isActionContractError } from "../action.js";
|
|
12
13
|
import { collectSecretValues, MAX_EXTENSION_PROXY_RESPONSE_SIZE, normalizeExtensionProxyMethod, readResponseBytesWithLimit, readResponseTextWithLimit, redactSecrets, redactString, sanitizeOutboundHeaders, } from "./proxy-security.js";
|
|
13
14
|
import { createSsrfSafeDispatcher, isBlockedExtensionUrlWithDns, } from "./url-safety.js";
|
|
14
15
|
import { formatWebContentResult, parseWebContentSearchOptions, processWebContent, } from "./web-content.js";
|
|
@@ -174,7 +175,7 @@ export function createFetchToolEntry(opts = {}) {
|
|
|
174
175
|
const rawUrl = String(args.url ?? "");
|
|
175
176
|
const method = normalizeExtensionProxyMethod(args.method || "GET");
|
|
176
177
|
if (!method) {
|
|
177
|
-
|
|
178
|
+
fail("Unsupported HTTP method. Allowed methods: GET, POST, PUT, PATCH, DELETE, HEAD.", { errorCode: "web_request_invalid_method" });
|
|
178
179
|
}
|
|
179
180
|
const rawHeaders = typeof args.headers === "string"
|
|
180
181
|
? args.headers
|
|
@@ -216,7 +217,9 @@ export function createFetchToolEntry(opts = {}) {
|
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
219
|
catch (err) {
|
|
219
|
-
|
|
220
|
+
fail(`Error resolving key references: ${err?.message ?? err}`, {
|
|
221
|
+
errorCode: "web_request_key_resolution_failed",
|
|
222
|
+
});
|
|
220
223
|
}
|
|
221
224
|
}
|
|
222
225
|
const secretValues = collectSecretValues(allSecretValues);
|
|
@@ -224,17 +227,21 @@ export function createFetchToolEntry(opts = {}) {
|
|
|
224
227
|
? allResolvedKeys
|
|
225
228
|
: undefined;
|
|
226
229
|
if (await isBlockedExtensionUrlWithDns(resolvedUrl)) {
|
|
227
|
-
|
|
230
|
+
fail(`Requests to private/internal addresses are not allowed: "${rawUrl}".`, { errorCode: "web_request_url_blocked" });
|
|
228
231
|
}
|
|
229
232
|
if (opts.validateUrl && allUsedKeys.length > 0) {
|
|
230
233
|
try {
|
|
231
234
|
const allowed = await opts.validateUrl(resolvedUrl, allUsedKeys, resolvedKeys);
|
|
232
235
|
if (!allowed) {
|
|
233
|
-
|
|
236
|
+
fail(`URL "${rawUrl}" is not in the allowlist for the referenced keys. Check your key settings.`, { errorCode: "web_request_url_blocked" });
|
|
234
237
|
}
|
|
235
238
|
}
|
|
236
239
|
catch (err) {
|
|
237
|
-
|
|
240
|
+
if (isActionContractError(err))
|
|
241
|
+
throw err;
|
|
242
|
+
fail(`URL validation error: ${err?.message ?? err}`, {
|
|
243
|
+
errorCode: "web_request_url_validation_failed",
|
|
244
|
+
});
|
|
238
245
|
}
|
|
239
246
|
}
|
|
240
247
|
let headers;
|
|
@@ -242,7 +249,9 @@ export function createFetchToolEntry(opts = {}) {
|
|
|
242
249
|
headers = sanitizeOutboundHeaders(JSON.parse(resolvedHeaders));
|
|
243
250
|
}
|
|
244
251
|
catch {
|
|
245
|
-
|
|
252
|
+
fail(`Invalid headers JSON: ${rawHeaders}`, {
|
|
253
|
+
errorCode: "web_request_invalid_headers",
|
|
254
|
+
});
|
|
246
255
|
}
|
|
247
256
|
headers = applyBrowserDefaults(headers);
|
|
248
257
|
const controller = new AbortController();
|
|
@@ -272,18 +281,23 @@ export function createFetchToolEntry(opts = {}) {
|
|
|
272
281
|
: null;
|
|
273
282
|
if (redirectUrl &&
|
|
274
283
|
(await isBlockedExtensionUrlWithDns(redirectUrl))) {
|
|
275
|
-
|
|
284
|
+
fail("Redirect to private/internal address blocked.", {
|
|
285
|
+
errorCode: "web_request_url_blocked",
|
|
286
|
+
});
|
|
276
287
|
}
|
|
277
288
|
if (redirectUrl && opts.validateUrl && allUsedKeys.length > 0) {
|
|
278
289
|
const allowed = await opts.validateUrl(redirectUrl, allUsedKeys, resolvedKeys);
|
|
279
290
|
if (!allowed) {
|
|
280
|
-
|
|
291
|
+
fail("Redirect URL is not in the allowlist for the referenced keys.", { errorCode: "web_request_url_blocked" });
|
|
281
292
|
}
|
|
282
293
|
}
|
|
283
|
-
|
|
294
|
+
fail(`HTTP ${response.status} ${response.statusText}\n\nRedirect: ${redirectUrl ? redactString(redirectUrl, secretValues) : "(none)"}`, { errorCode: `http_${response.status}` });
|
|
284
295
|
}
|
|
285
296
|
const contentType = response.headers.get("content-type")?.split(";")[0].trim() ??
|
|
286
297
|
"text/plain";
|
|
298
|
+
const httpErrorCode = response.ok
|
|
299
|
+
? undefined
|
|
300
|
+
: `http_${response.status}`;
|
|
287
301
|
const saveToFilePath = typeof args.saveToFile === "string"
|
|
288
302
|
? args.saveToFile.trim()
|
|
289
303
|
: "";
|
|
@@ -328,9 +342,17 @@ export function createFetchToolEntry(opts = {}) {
|
|
|
328
342
|
body = result.text;
|
|
329
343
|
}
|
|
330
344
|
catch {
|
|
331
|
-
|
|
345
|
+
fail("(could not read response body)", {
|
|
346
|
+
errorCode: httpErrorCode ?? "web_request_body_unreadable",
|
|
347
|
+
});
|
|
332
348
|
}
|
|
333
349
|
body = redactString(body, secretValues);
|
|
350
|
+
if (response.ok) {
|
|
351
|
+
const { providerApiResponseOutcomeForUrl } = await import("../provider-api/index.js");
|
|
352
|
+
const outcome = providerApiResponseOutcomeForUrl(resolvedUrl, response, body);
|
|
353
|
+
if (!outcome.ok)
|
|
354
|
+
fail(`HTTP ${response.status} ${outcome.statusText}\n\n${body.slice(0, maxChars)}`, { errorCode: "web_request_provider_failed" });
|
|
355
|
+
}
|
|
334
356
|
let displayBody;
|
|
335
357
|
let processedMode = "raw";
|
|
336
358
|
try {
|
|
@@ -350,7 +372,7 @@ export function createFetchToolEntry(opts = {}) {
|
|
|
350
372
|
displayBody = formatWebContentResult(processed);
|
|
351
373
|
}
|
|
352
374
|
catch (err) {
|
|
353
|
-
|
|
375
|
+
fail(`web-request post-processing error: ${err?.message ?? String(err)}`, { errorCode: httpErrorCode ?? "web_request_processing_failed" });
|
|
354
376
|
}
|
|
355
377
|
console.log(`[fetch-tool] ${method} ${rawUrl} → ${response.status} (${elapsed}ms, keys: ${allUsedKeys.join(",") || "none"})`);
|
|
356
378
|
if (saveToFilePath) {
|
|
@@ -375,6 +397,8 @@ export function createFetchToolEntry(opts = {}) {
|
|
|
375
397
|
});
|
|
376
398
|
const bytes = Buffer.byteLength(body, "utf8");
|
|
377
399
|
const preview = displayBody.slice(0, 2000);
|
|
400
|
+
if (!response.ok)
|
|
401
|
+
fail(`HTTP ${response.status} ${response.statusText}\n\n${displayBody}`, { errorCode: `http_${response.status}` });
|
|
378
402
|
return JSON.stringify({
|
|
379
403
|
savedToFile: true,
|
|
380
404
|
savedTo: saveToFilePath,
|
|
@@ -387,20 +411,32 @@ export function createFetchToolEntry(opts = {}) {
|
|
|
387
411
|
});
|
|
388
412
|
}
|
|
389
413
|
catch (saveErr) {
|
|
390
|
-
|
|
414
|
+
if (isActionContractError(saveErr))
|
|
415
|
+
throw saveErr;
|
|
416
|
+
fail(`saveToFile error: ${saveErr?.message ?? String(saveErr)}\n\nHTTP ${response.status} ${response.statusText}\n\n${body.slice(0, maxChars)}`, {
|
|
417
|
+
errorCode: httpErrorCode ?? "web_request_save_failed",
|
|
418
|
+
});
|
|
391
419
|
}
|
|
392
420
|
}
|
|
421
|
+
if (!response.ok)
|
|
422
|
+
fail(`HTTP ${response.status} ${response.statusText}\n\n${displayBody}`, { errorCode: `http_${response.status}` });
|
|
393
423
|
return `HTTP ${response.status} ${response.statusText}\n\n${displayBody}`;
|
|
394
424
|
}
|
|
395
425
|
catch (err) {
|
|
426
|
+
if (isActionContractError(err))
|
|
427
|
+
throw err;
|
|
396
428
|
const elapsed = Date.now() - startTime;
|
|
397
429
|
if (err?.name === "AbortError") {
|
|
398
430
|
console.log(`[fetch-tool] ${method} ${rawUrl} → TIMEOUT (${elapsed}ms)`);
|
|
399
|
-
|
|
431
|
+
fail(`Request timed out after ${timeoutMs}ms.`, {
|
|
432
|
+
errorCode: "web_request_timeout",
|
|
433
|
+
});
|
|
400
434
|
}
|
|
401
435
|
const message = redactSecrets(err?.message ?? String(err), secretValues);
|
|
402
436
|
console.log(`[fetch-tool] ${method} ${rawUrl} → ERROR: ${message} (${elapsed}ms)`);
|
|
403
|
-
|
|
437
|
+
fail(`Request failed: ${message}`, {
|
|
438
|
+
errorCode: "web_request_failed",
|
|
439
|
+
});
|
|
404
440
|
}
|
|
405
441
|
finally {
|
|
406
442
|
clearTimeout(timeout);
|
package/dist/file-upload/s3.js
CHANGED
|
@@ -201,7 +201,7 @@ async function deleteObject(config, key) {
|
|
|
201
201
|
if (response.ok)
|
|
202
202
|
return true;
|
|
203
203
|
if (response.status === 404)
|
|
204
|
-
return
|
|
204
|
+
return true;
|
|
205
205
|
const detail = await response.text();
|
|
206
206
|
throw new Error(`S3 DeleteObject failed (${response.status}): ${detail || response.statusText}`);
|
|
207
207
|
}
|
|
@@ -37,6 +37,7 @@ export interface FileUploadProvider {
|
|
|
37
37
|
*/
|
|
38
38
|
publicBaseUrlOptional?: boolean;
|
|
39
39
|
upload: (input: FileUploadInput) => Promise<FileUploadResult>;
|
|
40
|
+
/** Resolves true when the object was deleted or was already missing. */
|
|
40
41
|
delete?: (input: FileUploadDeleteInput) => Promise<boolean>;
|
|
41
42
|
resumable?: {
|
|
42
43
|
startSession(filename: string, mimeType: string, maxBytes: number): Promise<ResumableUploadSession>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { timingSafeEqual } from "node:crypto";
|
|
2
2
|
import { getHeader, readRawBody as h3ReadRawBody } from "h3";
|
|
3
|
+
import { fail } from "../../action.js";
|
|
3
4
|
import { getAppConfig } from "../../app-config/index.js";
|
|
4
5
|
import { getDbExec } from "../../db/client.js";
|
|
6
|
+
import { automationOutcomeMessagesForUser } from "../../localization/automation-outcome-messages.js";
|
|
5
7
|
import { resolveSecret } from "../../server/credential-provider.js";
|
|
6
8
|
import { sendEmail, isEmailConfigured, getEmailProvider, } from "../../server/email.js";
|
|
9
|
+
import { getRequestUserEmail } from "../../server/request-context.js";
|
|
7
10
|
import { getIntegrationConfig } from "../config-store.js";
|
|
8
11
|
const EMAIL_MAX_BODY_LENGTH = 15000;
|
|
9
12
|
const RATE_LIMIT_MAX = 20;
|
|
@@ -205,13 +208,14 @@ export function emailAdapter() {
|
|
|
205
208
|
async sendMessageToTarget(message, target) {
|
|
206
209
|
const agentAddress = await resolveSecret("EMAIL_AGENT_ADDRESS");
|
|
207
210
|
if (!agentAddress) {
|
|
208
|
-
|
|
209
|
-
|
|
211
|
+
fail("[email] EMAIL_AGENT_ADDRESS not configured", {
|
|
212
|
+
errorCode: "config_invalid",
|
|
213
|
+
});
|
|
210
214
|
}
|
|
211
215
|
const config = await getIntegrationConfig("email");
|
|
212
216
|
const displayName = config?.configData?.displayName || "Dispatch Agent";
|
|
213
217
|
try {
|
|
214
|
-
await sendEmail({
|
|
218
|
+
const outcome = await sendEmail({
|
|
215
219
|
to: target.destination,
|
|
216
220
|
from: `${displayName} <${agentAddress}>`,
|
|
217
221
|
subject: target.label || "Message from Dispatch Agent",
|
|
@@ -224,6 +228,10 @@ export function emailAdapter() {
|
|
|
224
228
|
}
|
|
225
229
|
: {}),
|
|
226
230
|
});
|
|
231
|
+
if (outcome.status !== "sent" || outcome.provider === "dev") {
|
|
232
|
+
const messages = await automationOutcomeMessagesForUser(getRequestUserEmail());
|
|
233
|
+
fail(messages.emailNotSent, { errorCode: "email_delivery_not_sent" });
|
|
234
|
+
}
|
|
227
235
|
}
|
|
228
236
|
catch (err) {
|
|
229
237
|
console.error("[email] Failed to send proactive message:", err);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getHeader } from "h3";
|
|
2
|
+
import { fail } from "../../action.js";
|
|
2
3
|
import { getAppConfig } from "../../app-config/index.js";
|
|
3
4
|
import { resolveSecret } from "../../server/credential-provider.js";
|
|
4
5
|
import { readBody } from "../../server/h3-helpers.js";
|
|
@@ -193,8 +194,9 @@ export function telegramAdapter() {
|
|
|
193
194
|
async sendMessageToTarget(message, target) {
|
|
194
195
|
const token = await resolveSecret("TELEGRAM_BOT_TOKEN");
|
|
195
196
|
if (!token) {
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
fail("[telegram] TELEGRAM_BOT_TOKEN not configured", {
|
|
198
|
+
errorCode: "config_invalid",
|
|
199
|
+
});
|
|
198
200
|
}
|
|
199
201
|
const chunks = splitMessage(message.text, TELEGRAM_MAX_LENGTH);
|
|
200
202
|
for (const chunk of chunks) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const AUTOMATION_NO_OP_TOOL = "automation-no-op";
|
|
3
|
+
export declare const automationNoOpSchema: z.ZodObject<{
|
|
4
|
+
reason: z.ZodString;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
declare const _default: import("../../action.js").ActionDefinition<{
|
|
7
|
+
reason: string;
|
|
8
|
+
}, {
|
|
9
|
+
status: "skipped";
|
|
10
|
+
reason: string;
|
|
11
|
+
}>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { defineAction } from "../../action.js";
|
|
3
|
+
import { AUTOMATION_OUTCOME_MESSAGES } from "../../localization/automation-outcome-messages.js";
|
|
4
|
+
export const AUTOMATION_NO_OP_TOOL = "automation-no-op";
|
|
5
|
+
export const automationNoOpSchema = z.object({
|
|
6
|
+
reason: z
|
|
7
|
+
.string()
|
|
8
|
+
.trim()
|
|
9
|
+
.min(1)
|
|
10
|
+
.max(500)
|
|
11
|
+
.describe(AUTOMATION_OUTCOME_MESSAGES["en-US"].noOpReason),
|
|
12
|
+
});
|
|
13
|
+
export default defineAction({
|
|
14
|
+
description: AUTOMATION_OUTCOME_MESSAGES["en-US"].noOpInstruction,
|
|
15
|
+
schema: automationNoOpSchema,
|
|
16
|
+
http: false,
|
|
17
|
+
agentTool: false,
|
|
18
|
+
readOnly: true,
|
|
19
|
+
run: async ({ reason }) => ({ status: "skipped", reason }),
|
|
20
|
+
});
|
|
@@ -11,9 +11,9 @@ declare const _default: import("../../action.js").ActionDefinition<{
|
|
|
11
11
|
enabled?: undefined;
|
|
12
12
|
nextRun?: undefined;
|
|
13
13
|
} | {
|
|
14
|
-
deleted?: undefined;
|
|
15
14
|
name: string;
|
|
16
15
|
enabled: boolean;
|
|
17
16
|
nextRun: string;
|
|
17
|
+
deleted?: undefined;
|
|
18
18
|
}>;
|
|
19
19
|
export default _default;
|
|
@@ -48,10 +48,16 @@ export interface BackgroundAutomationRunOptions {
|
|
|
48
48
|
/** The event this run handles; retries of one event move the streak once. */
|
|
49
49
|
eventId?: string;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
interface BackgroundAutomationRunOutput {
|
|
52
52
|
responseText: string;
|
|
53
53
|
runId: string;
|
|
54
54
|
}
|
|
55
|
+
export type BackgroundAutomationRunResult = BackgroundAutomationRunOutput & ({
|
|
56
|
+
status: "success";
|
|
57
|
+
} | {
|
|
58
|
+
status: "skipped";
|
|
59
|
+
reason: string;
|
|
60
|
+
});
|
|
55
61
|
/**
|
|
56
62
|
* `owner_missing` is permanent (the user or membership is gone);
|
|
57
63
|
* `owner_unverifiable` means the lookup itself failed and must be retried, not
|
|
@@ -119,3 +125,4 @@ export declare function checkBackgroundAutomationCredentials(identity: {
|
|
|
119
125
|
ok: false;
|
|
120
126
|
failure: AutomationFailure;
|
|
121
127
|
}>;
|
|
128
|
+
export {};
|