@agent-native/core 0.70.3 → 0.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +13 -0
- package/corpus/core/docs/content/multi-app-workspace.md +2 -2
- package/corpus/core/docs/design/durable-agent-runs.md +458 -4
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/durable-background.ts +192 -0
- package/corpus/core/src/agent/production-agent.ts +330 -13
- package/corpus/core/src/agent/run-manager.ts +66 -3
- package/corpus/core/src/agent/run-store.ts +129 -23
- package/corpus/core/src/agent/types.ts +20 -0
- package/corpus/core/src/client/AgentPanel.tsx +12 -9
- package/corpus/core/src/client/blocks/library/FileTreeBlock.tsx +72 -14
- package/corpus/core/src/deploy/build.ts +96 -0
- package/corpus/core/src/deploy/workspace-deploy.ts +121 -0
- package/corpus/core/src/mcp/build-server.ts +22 -13
- package/corpus/core/src/server/agent-chat-plugin.ts +133 -66
- package/corpus/templates/analytics/.agents/skills/dashboard-management/SKILL.md +19 -0
- package/corpus/templates/analytics/AGENTS.md +8 -0
- package/corpus/templates/analytics/actions/compose-dashboard.ts +317 -0
- package/corpus/templates/analytics/changelog/2026-06-23-build-large-first-party-analytics-dashboards-in-one-fast-cal.md +6 -0
- package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +574 -0
- package/corpus/templates/clips/changelog/2026-06-23-dragging-the-desktop-camera-bubble-now-glides-to-a-stop-at-t.md +6 -0
- package/corpus/templates/clips/chrome-extension/src/background.ts +130 -32
- package/corpus/templates/clips/chrome-extension/src/content-script.ts +163 -13
- package/corpus/templates/clips/chrome-extension/src/offscreen.ts +195 -34
- package/corpus/templates/clips/chrome-extension/src/overlay.css +73 -23
- package/corpus/templates/clips/chrome-extension/src/overlay.ts +82 -13
- package/corpus/templates/clips/chrome-extension/src/popup.html +62 -5
- package/corpus/templates/clips/chrome-extension/src/popup.ts +290 -1
- package/corpus/templates/clips/chrome-extension/src/styles.css +34 -0
- package/corpus/templates/clips/desktop/src/lib/audio-cue.ts +21 -16
- package/corpus/templates/clips/desktop/src/lib/recorder.ts +10 -17
- package/corpus/templates/clips/desktop/src/overlays/bubble.tsx +73 -23
- package/corpus/templates/clips/desktop/src/overlays/countdown.tsx +0 -6
- package/corpus/templates/clips/desktop/src/overlays/toolbar.tsx +56 -46
- package/corpus/templates/clips/desktop/src/styles.css +33 -5
- package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +113 -0
- package/corpus/templates/clips/desktop/src-tauri/src/lib.rs +3 -0
- package/dist/agent/durable-background.d.ts +60 -0
- package/dist/agent/durable-background.d.ts.map +1 -0
- package/dist/agent/durable-background.js +144 -0
- package/dist/agent/durable-background.js.map +1 -0
- package/dist/agent/production-agent.d.ts +20 -0
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +292 -14
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-manager.d.ts +48 -0
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js +45 -3
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/agent/run-store.d.ts +30 -1
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +124 -24
- package/dist/agent/run-store.js.map +1 -1
- package/dist/agent/types.d.ts +20 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +2 -2
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/blocks/library/FileTreeBlock.d.ts.map +1 -1
- package/dist/client/blocks/library/FileTreeBlock.js +37 -4
- package/dist/client/blocks/library/FileTreeBlock.js.map +1 -1
- package/dist/deploy/build.d.ts +29 -0
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +85 -0
- package/dist/deploy/build.js.map +1 -1
- package/dist/deploy/workspace-deploy.d.ts.map +1 -1
- package/dist/deploy/workspace-deploy.js +108 -0
- package/dist/deploy/workspace-deploy.js.map +1 -1
- package/dist/mcp/build-server.d.ts.map +1 -1
- package/dist/mcp/build-server.js +23 -9
- package/dist/mcp/build-server.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +68 -13
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/docs/content/multi-app-workspace.md +2 -2
- package/docs/design/durable-agent-runs.md +458 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-chat-plugin.d.ts","sourceRoot":"","sources":["../../src/server/agent-chat-plugin.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAsBtC,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAElB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,gBAAgB,EAcjB,MAAM,wBAAwB,CAAC;AAYhC,OAAO,EAQL,KAAK,OAAO,EACb,MAAM,IAAI,CAAC;AAGZ,OAAO,EAkBL,KAAK,UAAU,EAGhB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-chat-plugin.d.ts","sourceRoot":"","sources":["../../src/server/agent-chat-plugin.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAsBtC,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAElB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,gBAAgB,EAcjB,MAAM,wBAAwB,C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vB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,6BAA6B,EAAE,MAAM,CAAC;IACtC,4BAA4B,EAAE,MAAM,CAAC;CACtC,CAoKA;AAED,eAAO,MAAM,gCAAgC;;;;;;;CAczC,CAAC;AAEL;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,MAAM,EACb,OAAO,UAAQ,EACf,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAoLjB;AAsBD;;;;;;;;;;;GAWG;AACH,iBAAS,qBAAqB,CAC5B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACrC,IAAI,GAAE,KAAK,GAAG,MAAe,GAC5B,MAAM,CAoER;AA0KD,wBAAgB,sCAAsC,CAAC,KAAK,EAAE;IAC5D,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,GAAG,OAAO,CA2BV;AAED,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,cAAc,CA0sIhB;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,cAAwC,CAAC;AAa9E,yEAAyE;AACzE,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,IAAI,CAE7D"}
|
|
@@ -27,6 +27,7 @@ import { AGENT_TEAM_PROCESS_RUN_PATH, getCurrentDelegationDepth, processAgentTea
|
|
|
27
27
|
import { setProgressPreListHook } from "../progress/store.js";
|
|
28
28
|
import { verifyInternalToken, extractBearerToken, } from "../integrations/internal-token.js";
|
|
29
29
|
import { hasConfiguredA2ASecret, isA2AProductionRuntime, } from "../a2a/auth-policy.js";
|
|
30
|
+
import { AGENT_CHAT_PROCESS_RUN_PATH, prepareProcessRunRequest, } from "../agent/durable-background.js";
|
|
30
31
|
import { getBuilderBrowserConnectUrlForOwner, resolveBuilderBranchProjectId, } from "./builder-browser.js";
|
|
31
32
|
import { captureCliOutput } from "./cli-capture.js";
|
|
32
33
|
import { withConfiguredAppBasePath } from "./app-base-path.js";
|
|
@@ -6035,19 +6036,13 @@ Non-code requests are still fine on this surface: read data, navigate the UI, su
|
|
|
6035
6036
|
setResponseStatus(event, 405);
|
|
6036
6037
|
return { error: "Method not allowed" };
|
|
6037
6038
|
}));
|
|
6038
|
-
//
|
|
6039
|
-
//
|
|
6040
|
-
//
|
|
6041
|
-
//
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
const afterBase = url.slice(url.indexOf(routePath) + routePath.length);
|
|
6046
|
-
if (afterBase && afterBase !== "/" && !afterBase.startsWith("?")) {
|
|
6047
|
-
// Not for us — return 404 so h3 doesn't swallow the request
|
|
6048
|
-
setResponseStatus(event, 404);
|
|
6049
|
-
return { error: "Not found" };
|
|
6050
|
-
}
|
|
6039
|
+
// Shared per-request invocation: resolve auth/org/timezone context, then
|
|
6040
|
+
// pick the dev/prod/anonymous handler and run it inside the request
|
|
6041
|
+
// context. Used by the main chat POST and by the durable-background
|
|
6042
|
+
// `_process-run` processor route (which re-enters the same handler set as
|
|
6043
|
+
// the background worker), so both go through identical context + handler
|
|
6044
|
+
// selection.
|
|
6045
|
+
const invokeAgentChatHandler = async (event) => {
|
|
6051
6046
|
// Resolve per-request auth context
|
|
6052
6047
|
const ownerContext = await resolveOwnerContext(event);
|
|
6053
6048
|
const owner = ownerContext.owner;
|
|
@@ -6108,6 +6103,66 @@ Non-code requests are still fine on this surface: read data, navigate the UI, su
|
|
|
6108
6103
|
: prodHandler;
|
|
6109
6104
|
return handler(event);
|
|
6110
6105
|
});
|
|
6106
|
+
};
|
|
6107
|
+
// ─── Durable background agent-chat run processor ──────────────────────
|
|
6108
|
+
// Self-fire target for a long chat turn. The foreground POST claims the
|
|
6109
|
+
// run slot, inserts the run row, and `fireInternalDispatch`es here; this
|
|
6110
|
+
// route runs INSIDE the Netlify background function (15-min budget). It
|
|
6111
|
+
// HMAC-verifies the dispatch (same internal-token scheme as the agent-
|
|
6112
|
+
// teams / A2A / webhook processors), injects the background-run marker,
|
|
6113
|
+
// and re-enters the SAME agent-chat handler as the background worker,
|
|
6114
|
+
// which runs the full multi-step turn inline with the ~13min soft
|
|
6115
|
+
// timeout. With AGENT_CHAT_DURABLE_BACKGROUND off, the foreground never
|
|
6116
|
+
// dispatches here, so this route is never exercised.
|
|
6117
|
+
getH3App(nitroApp).use(AGENT_CHAT_PROCESS_RUN_PATH, defineEventHandler(async (event) => {
|
|
6118
|
+
if (getMethod(event) !== "POST") {
|
|
6119
|
+
setResponseStatus(event, 405);
|
|
6120
|
+
return { error: "Method not allowed" };
|
|
6121
|
+
}
|
|
6122
|
+
// Consume the body ONCE (h3 v2's web Request stream is single-use).
|
|
6123
|
+
let processBody;
|
|
6124
|
+
try {
|
|
6125
|
+
processBody = await readBody(event);
|
|
6126
|
+
}
|
|
6127
|
+
catch {
|
|
6128
|
+
setResponseStatus(event, 400);
|
|
6129
|
+
return { error: "Invalid request body" };
|
|
6130
|
+
}
|
|
6131
|
+
// Validate + HMAC-authenticate the self-dispatch and prepare the
|
|
6132
|
+
// background-worker body. Pure decision (unit-tested in
|
|
6133
|
+
// durable-background.spec.ts); the route only wires it to h3.
|
|
6134
|
+
const prepared = prepareProcessRunRequest(processBody, getHeader(event, "authorization"));
|
|
6135
|
+
if (!prepared.ok) {
|
|
6136
|
+
setResponseStatus(event, prepared.status);
|
|
6137
|
+
return { error: prepared.error };
|
|
6138
|
+
}
|
|
6139
|
+
// Stash the verified+augmented body for the handler — the body stream
|
|
6140
|
+
// is already consumed, so the handler reads this instead.
|
|
6141
|
+
event.context = event.context ?? {};
|
|
6142
|
+
event.context.__agentChatBackgroundBody = prepared.body;
|
|
6143
|
+
try {
|
|
6144
|
+
return await invokeAgentChatHandler(event);
|
|
6145
|
+
}
|
|
6146
|
+
catch (err) {
|
|
6147
|
+
console.error("[agent-chat] _process-run failed:", err);
|
|
6148
|
+
setResponseStatus(event, 500);
|
|
6149
|
+
return { error: "process-run failed" };
|
|
6150
|
+
}
|
|
6151
|
+
}));
|
|
6152
|
+
// Mount the main chat handler — delegates to dev or prod handler based on current mode.
|
|
6153
|
+
// This is mounted last because h3's use() is prefix-based, meaning /_agent-native/agent-chat
|
|
6154
|
+
// also matches /_agent-native/agent-chat/threads/... — we skip sub-path requests here so the
|
|
6155
|
+
// earlier-mounted handlers (mode, save-key, files, skills, mentions, threads) handle them.
|
|
6156
|
+
getH3App(nitroApp).use(routePath, defineEventHandler(async (event) => {
|
|
6157
|
+
// Skip sub-path requests — they're handled by earlier-mounted handlers
|
|
6158
|
+
const url = event.node?.req?.url || event.path || "";
|
|
6159
|
+
const afterBase = url.slice(url.indexOf(routePath) + routePath.length);
|
|
6160
|
+
if (afterBase && afterBase !== "/" && !afterBase.startsWith("?")) {
|
|
6161
|
+
// Not for us — return 404 so h3 doesn't swallow the request
|
|
6162
|
+
setResponseStatus(event, 404);
|
|
6163
|
+
return { error: "Not found" };
|
|
6164
|
+
}
|
|
6165
|
+
return invokeAgentChatHandler(event);
|
|
6111
6166
|
}));
|
|
6112
6167
|
// ─── Recurring Jobs Scheduler ──────────────────────────────────────
|
|
6113
6168
|
// Poll every 60 seconds for due recurring jobs and execute them.
|