@agent-native/core 0.84.5 → 0.84.7

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.
Files changed (31) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/core/CHANGELOG.md +12 -0
  3. package/corpus/core/package.json +1 -1
  4. package/corpus/core/src/agent/production-agent.ts +97 -38
  5. package/corpus/core/src/agent/run-store.ts +17 -0
  6. package/corpus/core/src/client/agent-chat-adapter.ts +74 -2
  7. package/corpus/core/src/server/agent-chat-plugin.ts +57 -12
  8. package/corpus/templates/design/AGENTS.md +9 -7
  9. package/corpus/templates/design/actions/present-design-variants.ts +202 -10
  10. package/corpus/templates/design/app/hooks/use-question-flow.ts +2 -2
  11. package/corpus/templates/design/app/pages/DesignEditor.tsx +1 -1
  12. package/corpus/templates/design/changelog/2026-07-01-design-variants-can-now-be-generated-from-compact-directions.md +6 -0
  13. package/dist/agent/production-agent.d.ts +20 -0
  14. package/dist/agent/production-agent.d.ts.map +1 -1
  15. package/dist/agent/production-agent.js +65 -32
  16. package/dist/agent/production-agent.js.map +1 -1
  17. package/dist/agent/run-store.d.ts +14 -0
  18. package/dist/agent/run-store.d.ts.map +1 -1
  19. package/dist/agent/run-store.js +14 -0
  20. package/dist/agent/run-store.js.map +1 -1
  21. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  22. package/dist/client/agent-chat-adapter.js +63 -2
  23. package/dist/client/agent-chat-adapter.js.map +1 -1
  24. package/dist/collab/routes.d.ts +1 -1
  25. package/dist/observability/routes.d.ts +3 -3
  26. package/dist/progress/routes.d.ts +1 -1
  27. package/dist/server/agent-chat-plugin.d.ts +9 -0
  28. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  29. package/dist/server/agent-chat-plugin.js +20 -8
  30. package/dist/server/agent-chat-plugin.js.map +1 -1
  31. package/package.json +1 -1
@@ -48,11 +48,26 @@ const variantSchema = z.object({
48
48
  .string()
49
49
  .min(1)
50
50
  .describe("Short user-facing screen name, e.g. 'One-Line Focus'"),
51
+ description: z
52
+ .string()
53
+ .optional()
54
+ .describe(
55
+ "Short visual direction summary. Use this instead of a huge HTML payload when exploring variants quickly.",
56
+ ),
57
+ accentColor: z
58
+ .string()
59
+ .optional()
60
+ .describe("Optional CSS color used as this variant's primary accent."),
61
+ features: z
62
+ .array(z.string())
63
+ .max(8)
64
+ .optional()
65
+ .describe("Optional short feature/polish bullets to show in the variant."),
51
66
  content: z
52
67
  .string()
53
- .min(1)
68
+ .optional()
54
69
  .describe(
55
- "Complete self-contained HTML document for this variant. Keep it compact: one representative screen or directional snapshot, not a full multi-screen app. Inline the CSS needed for the preview; avoid relying on external CSS/script CDNs because app sandboxes may block them.",
70
+ "Optional complete self-contained HTML document for this variant. Keep it compact: one representative screen or directional snapshot, not a full multi-screen app. For faster exploration, omit this and provide label/description/features; Design will generate a compact representative screen.",
56
71
  ),
57
72
  width: z
58
73
  .number()
@@ -137,14 +152,17 @@ function boundedDimension(value: unknown, min: number, max: number) {
137
152
  : undefined;
138
153
  }
139
154
 
140
- function inferVariantSize(variant: z.infer<typeof variantSchema>) {
155
+ function inferVariantSize(
156
+ variant: z.infer<typeof variantSchema>,
157
+ prompt?: string,
158
+ ) {
141
159
  const explicitWidth = boundedDimension(variant.width, 240, 1920);
142
160
  const explicitHeight = boundedDimension(variant.height, 240, 3000);
143
161
  if (explicitWidth && explicitHeight) {
144
162
  return { width: explicitWidth, height: explicitHeight };
145
163
  }
146
164
 
147
- const content = variant.content;
165
+ const content = variant.content ?? "";
148
166
  const cssWidth =
149
167
  firstCssPixelValue(content, "width") ??
150
168
  firstCssPixelValue(content, "max-width") ??
@@ -167,7 +185,15 @@ function inferVariantSize(variant: z.infer<typeof variantSchema>) {
167
185
  };
168
186
  }
169
187
 
170
- const lowercase = content.toLowerCase();
188
+ const lowercase = [
189
+ content,
190
+ variant.label,
191
+ variant.description ?? "",
192
+ ...(variant.features ?? []),
193
+ prompt ?? "",
194
+ ]
195
+ .join(" ")
196
+ .toLowerCase();
171
197
  if (
172
198
  /\b(?:mobile|phone|iphone|android)\b/.test(lowercase) ||
173
199
  /\b(?:max-w-sm|max-w-md|w-\[(?:360|375|390|393|414)px\])\b/.test(lowercase)
@@ -190,6 +216,163 @@ function inferVariantSize(variant: z.infer<typeof variantSchema>) {
190
216
  };
191
217
  }
192
218
 
219
+ function escapeHtml(value: string) {
220
+ return value
221
+ .replace(/&/g, "&amp;")
222
+ .replace(/</g, "&lt;")
223
+ .replace(/>/g, "&gt;")
224
+ .replace(/"/g, "&quot;");
225
+ }
226
+
227
+ function colorForVariant(
228
+ variant: z.infer<typeof variantSchema>,
229
+ index: number,
230
+ ) {
231
+ const provided = variant.accentColor?.trim();
232
+ if (provided) return provided;
233
+ return ["#8b5cf6", "#06b6d4", "#10b981", "#f43f5e", "#f59e0b"][index % 5]!;
234
+ }
235
+
236
+ function fallbackVariantContent(
237
+ variant: z.infer<typeof variantSchema>,
238
+ index: number,
239
+ prompt?: string,
240
+ size: { width: number; height: number } = {
241
+ width: DESKTOP_WIDTH,
242
+ height: DESKTOP_HEIGHT,
243
+ },
244
+ ) {
245
+ const label = escapeHtml(variant.label.trim() || optionName(index));
246
+ const description = escapeHtml(
247
+ variant.description?.trim() ||
248
+ "A compact dark-mode product direction with a clear primary workflow, crisp hierarchy, and fast keyboard-first flow.",
249
+ );
250
+ const sourcePrompt = escapeHtml(
251
+ prompt?.trim() ||
252
+ "Generated app interface direction with a polished workflow and production-ready interaction model.",
253
+ );
254
+ const accent = escapeHtml(colorForVariant(variant, index));
255
+ const features =
256
+ variant.features && variant.features.length > 0
257
+ ? variant.features.slice(0, 6)
258
+ : [
259
+ "Primary workflow",
260
+ "Fast capture",
261
+ "Structured details",
262
+ "Status tracking",
263
+ "Inline editing",
264
+ "Shortcut hints",
265
+ ];
266
+ const safeFeatures = features.map((feature) => escapeHtml(feature));
267
+ const cardTitles = [
268
+ safeFeatures[0] ?? "Primary workflow",
269
+ safeFeatures[1] ?? "Structured details",
270
+ safeFeatures[2] ?? "Polished interactions",
271
+ safeFeatures[3] ?? "Status tracking",
272
+ safeFeatures[4] ?? "Review flow",
273
+ ];
274
+ const density =
275
+ index % 3 === 0 ? "spacious" : index % 3 === 1 ? "glass" : "dense";
276
+ const screenWidth = Math.round(size.width);
277
+ const screenHeight = Math.round(size.height);
278
+ const compact = screenWidth <= 560;
279
+ const tablet = screenWidth > 560 && screenWidth <= 900;
280
+
281
+ return `<!doctype html>
282
+ <html lang="en">
283
+ <head>
284
+ <meta charset="utf-8" />
285
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
286
+ <title>${label}</title>
287
+ <style>
288
+ :root { color-scheme: dark; --accent: ${accent}; --bg: #080a0f; --panel: rgba(18, 22, 33, 0.82); --line: rgba(255,255,255,.11); --muted: #94a3b8; }
289
+ * { box-sizing: border-box; }
290
+ body { margin: 0; width: ${screenWidth}px; min-height: ${screenHeight}px; overflow: hidden; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: #f8fafc; background:
291
+ radial-gradient(circle at 18% 8%, color-mix(in srgb, var(--accent) 42%, transparent), transparent 30%),
292
+ linear-gradient(140deg, #05070b 0%, #111827 48%, #05070b 100%); }
293
+ .shell { width: ${screenWidth}px; min-height: ${screenHeight}px; padding: ${compact ? "18" : "34"}px; display: grid; grid-template-columns: ${compact ? "1fr" : tablet ? "220px 1fr" : "258px 1fr 304px"}; gap: ${compact ? "14" : "22"}px; }
294
+ .panel { border: 1px solid var(--line); background: var(--panel); border-radius: ${density === "dense" ? "14" : "22"}px; box-shadow: 0 24px 80px rgba(0,0,0,.35); backdrop-filter: blur(${density === "glass" ? "26" : "10"}px); }
295
+ .sidebar { padding: 22px; display: flex; flex-direction: column; gap: 18px; }
296
+ .brand { display:flex; align-items:center; justify-content:space-between; gap:12px; }
297
+ .mark { width: 40px; height: 40px; border-radius: 14px; background: var(--accent); box-shadow: 0 0 32px color-mix(in srgb, var(--accent) 58%, transparent); display:grid; place-items:center; font-weight:800; color:#05070b; }
298
+ h1 { margin: 0; font-size: 32px; line-height: 1.05; letter-spacing: 0; }
299
+ h2 { margin: 0; font-size: 16px; letter-spacing: 0; }
300
+ p { margin: 0; color: var(--muted); line-height: 1.5; }
301
+ .nav, .tasks, .right { display: grid; gap: 12px; }
302
+ .nav div, .task, .metric, .calendar { border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.045); padding: 13px 14px; }
303
+ .nav div:first-child { color: #fff; background: color-mix(in srgb, var(--accent) 18%, rgba(255,255,255,.06)); border-color: color-mix(in srgb, var(--accent) 48%, var(--line)); }
304
+ .main { padding: 24px; display:flex; flex-direction:column; gap:18px; }
305
+ .top { display:flex; align-items:flex-start; justify-content:space-between; gap:18px; }
306
+ .badge { border:1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); color:#fff; background: color-mix(in srgb, var(--accent) 20%, transparent); padding:8px 11px; border-radius:999px; font-size:12px; }
307
+ .board { display:grid; grid-template-columns: ${compact ? "1fr" : "repeat(3, 1fr)"}; gap:14px; flex:1; min-height:0; }
308
+ .column { border:1px solid var(--line); border-radius:18px; background:rgba(255,255,255,.035); padding:14px; display:flex; flex-direction:column; gap:12px; }
309
+ .column header { display:flex; justify-content:space-between; align-items:center; color:#cbd5e1; font-size:13px; }
310
+ .task { display:grid; gap:10px; padding:14px; }
311
+ .task strong { font-size:14px; line-height:1.25; }
312
+ .meta { display:flex; flex-wrap:wrap; gap:7px; }
313
+ .chip { font-size:11px; color:#dbeafe; border:1px solid rgba(255,255,255,.12); background:rgba(255,255,255,.055); border-radius:999px; padding:5px 8px; }
314
+ .priority { color:#fff; background: color-mix(in srgb, var(--accent) 22%, rgba(255,255,255,.06)); border-color: color-mix(in srgb, var(--accent) 46%, var(--line)); }
315
+ .right { padding:22px; align-content:start; }
316
+ .metric { display:grid; gap:8px; }
317
+ .metric b { font-size:28px; }
318
+ .calendar { display:grid; grid-template-columns: repeat(7, 1fr); gap:7px; }
319
+ .calendar span { display:grid; place-items:center; height:32px; border-radius:10px; color:#cbd5e1; background:rgba(255,255,255,.04); font-size:12px; }
320
+ .calendar .hot { color:#05070b; background:var(--accent); font-weight:800; }
321
+ .features { display:flex; flex-wrap:wrap; gap:8px; }
322
+ .shortcut { margin-top:auto; border-top:1px solid var(--line); padding-top:14px; display:flex; justify-content:space-between; gap:10px; color:#cbd5e1; font-size:12px; }
323
+ ${tablet ? ".right { display: none; }" : ""}
324
+ ${compact ? ".sidebar { padding: 16px; } .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); } .nav div { padding: 10px; } .main { padding: 18px; } .top { display: grid; } .top .badge { width: fit-content; } h1 { font-size: 26px; } .right { display: none; } .column:nth-child(n+3) { display: none; }" : ""}
325
+ </style>
326
+ </head>
327
+ <body>
328
+ <main class="shell">
329
+ <aside class="panel sidebar">
330
+ <div class="brand"><div class="mark">${escapeHtml(String.fromCharCode(65 + index))}</div><span class="badge">${label}</span></div>
331
+ <div>
332
+ <h2>Direction</h2>
333
+ <p>${description}</p>
334
+ </div>
335
+ <div class="nav">
336
+ <div>Overview</div><div>Primary flow</div><div>Details</div><div>Timeline</div><div>Output</div>
337
+ </div>
338
+ <div class="features">${safeFeatures.map((feature) => `<span class="chip">${feature}</span>`).join("")}</div>
339
+ <div class="shortcut"><span>⌘K command</span><span>G then B</span></div>
340
+ </aside>
341
+ <section class="panel main">
342
+ <div class="top">
343
+ <div><h1>${label}</h1><p>${sourcePrompt}</p></div>
344
+ <span class="badge">${compact ? "Mobile" : tablet ? "Tablet" : "Desktop"} concept · live data</span>
345
+ </div>
346
+ <div class="board">
347
+ <section class="column"><header><span>Focus</span><b>4</b></header>
348
+ <article class="task"><strong>${cardTitles[0]}</strong><div class="meta"><span class="chip priority">Primary</span><span class="chip">Now</span><span class="chip">Fast path</span></div></article>
349
+ <article class="task"><strong>${cardTitles[1]}</strong><div class="meta"><span class="chip">Detail view</span><span class="chip">Shortcut E</span></div></article>
350
+ </section>
351
+ <section class="column"><header><span>Build</span><b>6</b></header>
352
+ <article class="task"><strong>${cardTitles[2]}</strong><div class="meta"><span class="chip priority">P2</span><span class="chip">Flow</span></div></article>
353
+ <article class="task"><strong>${cardTitles[3]}</strong><div class="meta"><span class="chip">Inline edit</span><span class="chip">Next</span></div></article>
354
+ </section>
355
+ <section class="column"><header><span>Ready</span><b>12</b></header>
356
+ <article class="task"><strong>${cardTitles[4]}</strong><div class="meta"><span class="chip">Complete</span><span class="chip">Motion ready</span></div></article>
357
+ </section>
358
+ </div>
359
+ </section>
360
+ <aside class="panel right">
361
+ <h2>Progress</h2>
362
+ <div class="metric"><p>Current flow</p><b>68%</b><p>Representative state for this direction</p></div>
363
+ <h2>Timeline</h2>
364
+ <div class="calendar">${Array.from({ length: 14 }, (_, day) => `<span class="${day === 4 || day === 9 ? "hot" : ""}">${day + 1}</span>`).join("")}</div>
365
+ <h2>Key moments</h2>
366
+ <div class="tasks">
367
+ <div class="task"><strong>${safeFeatures[0] ?? "Primary workflow"}</strong><div class="meta"><span class="chip priority">Hero</span><span class="chip">45m</span></div></div>
368
+ <div class="task"><strong>${safeFeatures[1] ?? "Polished interaction"}</strong><div class="meta"><span class="chip">Motion</span><span class="chip">⌘ Enter</span></div></div>
369
+ </div>
370
+ </aside>
371
+ </main>
372
+ </body>
373
+ </html>`;
374
+ }
375
+
193
376
  function placeVariantScreens(screens: VariantScreen[]) {
194
377
  const placements: CanvasFramePlacement[] = [];
195
378
  const columns = Math.min(MAX_COLUMNS, Math.max(1, screens.length));
@@ -228,7 +411,9 @@ export default defineAction({
228
411
  "exploration before follow-up refinement. After the user's choice, keep " +
229
412
  "the chosen screen, delete the other generated variant screens, and " +
230
413
  "continue from the kept screen. For complex apps, make each variant a " +
231
- "compact but complete representative screen; expand the chosen direction " +
414
+ "compact representative screen; pass concise labels/descriptions/features " +
415
+ "and omit content when full HTML would be too large. Design will render " +
416
+ "compact screens from the direction data. Expand the chosen direction " +
232
417
  "after the user picks.",
233
418
  schema: z.object({
234
419
  designId: z.string().describe("Design project ID to show variants for"),
@@ -241,7 +426,7 @@ export default defineAction({
241
426
  .min(2)
242
427
  .max(5)
243
428
  .describe(
244
- "2-5 concise, visually distinct generated design options to place as overview screens (3 is the sweet spot). Inline CSS so all options render in the app preview.",
429
+ "2-5 concise, visually distinct generated design options to place as overview screens (3 is the sweet spot). Prefer short label/description/features for each direction; include inline HTML content only when it is compact enough to finish.",
245
430
  ),
246
431
  }),
247
432
  mcpApp: {
@@ -280,18 +465,25 @@ export default defineAction({
280
465
  const preferredFilename = `variant-${slug}.html`;
281
466
  const filename = uniqueFilename(preferredFilename, usedFilenames);
282
467
  const fileId = nanoid();
283
- const { width, height } = inferVariantSize(variant);
468
+ const providedContent = variant.content?.trim();
469
+ const initialSize = inferVariantSize(variant, prompt);
470
+ const content =
471
+ providedContent ||
472
+ fallbackVariantContent(variant, index, prompt, initialSize);
473
+ const { width, height } = providedContent
474
+ ? inferVariantSize({ ...variant, content })
475
+ : initialSize;
284
476
 
285
477
  await db.insert(schema.designFiles).values({
286
478
  id: fileId,
287
479
  designId,
288
480
  filename,
289
481
  fileType: "html",
290
- content: variant.content,
482
+ content,
291
483
  createdAt: now,
292
484
  updatedAt: now,
293
485
  });
294
- await seedFromText(fileId, variant.content);
486
+ await seedFromText(fileId, content);
295
487
 
296
488
  screens.push({
297
489
  id: fileId,
@@ -41,7 +41,7 @@ export function useQuestionFlow(
41
41
  formattedAnswers,
42
42
  "",
43
43
  designId
44
- ? "Now continue the design. Honor any answer about variations: if the user asked to explore options, call present-design-variants with 2-5 compact, complete HTML directions - one representative screen per direction, not a full app per variant - wait for their chat pick, delete the unchosen variant screens, then continue from the kept screen; otherwise call generate-design with one complete, renderable index.html first. Do not ask another question unless a required decision is still genuinely missing."
44
+ ? "Now continue the design. Honor any answer about variations: if the user asked to explore options, call present-design-variants with 2-5 concise directions using label, description, accentColor, and feature bullets; omit large content HTML when needed because the action can render compact representative screens - wait for their chat pick, delete the unchosen variant screens, then continue from the kept screen; otherwise call generate-design with one complete, renderable index.html first. Do not ask another question unless a required decision is still genuinely missing."
45
45
  : "Now continue the design. Honor any answer about variations: use variants only if requested; otherwise generate one polished direction.",
46
46
  ]
47
47
  .filter(Boolean)
@@ -79,7 +79,7 @@ export function useQuestionFlow(
79
79
  formattedAnswers,
80
80
  "",
81
81
  designId
82
- ? "Now continue the design. Honor any answer about variations: if the user asked to explore options, call present-design-variants with 2-5 compact, complete HTML directions - one representative screen per direction, not a full app per variant - wait for their chat pick, delete the unchosen variant screens, then continue from the kept screen; otherwise call generate-design with one complete, renderable index.html first. Do not ask another question unless a required decision is still genuinely missing."
82
+ ? "Now continue the design. Honor any answer about variations: if the user asked to explore options, call present-design-variants with 2-5 concise directions using label, description, accentColor, and feature bullets; omit large content HTML when needed because the action can render compact representative screens - wait for their chat pick, delete the unchosen variant screens, then continue from the kept screen; otherwise call generate-design with one complete, renderable index.html first. Do not ask another question unless a required decision is still genuinely missing."
83
83
  : "Now continue the design. Honor any answer about variations: use variants only if requested; otherwise generate one polished direction.",
84
84
  ]
85
85
  .filter(Boolean)
@@ -1309,7 +1309,7 @@ function designGenerationDirectives(
1309
1309
  return [
1310
1310
  `Use the \`generate-design --designId="${designId}"\` action with exactly one complete, renderable \`index.html\` file first. The design already exists - DO NOT call create-design.`,
1311
1311
  ...designSystemGenerationDirectives(designSystemId),
1312
- "If the user asked to explore variations, call `present-design-variants` with 2-5 compact, complete HTML directions: one representative screen per direction, not a full app per variant. Wait for their chat pick, delete the unchosen variant screens, then continue from the kept screen. Otherwise generate one polished first direction.",
1312
+ "If the user asked to explore variations, call `present-design-variants` with 2-5 concise directions. Prefer label, description, accentColor, and feature bullets; omit large content HTML when needed because the action can render compact representative screens. Wait for their chat pick, delete the unchosen variant screens, then continue from the kept screen. Otherwise generate one polished first direction.",
1313
1313
  "Keep the first pass bounded enough to finish quickly: one self-contained Alpine.js + Tailwind CDN HTML document, polished but concise. Add 3-6 tweaks only when they naturally fit the design.",
1314
1314
  "After generate-design succeeds, stop and summarize what was created.",
1315
1315
  ];
@@ -0,0 +1,6 @@
1
+ ---
2
+ type: fixed
3
+ date: 2026-07-01
4
+ ---
5
+
6
+ Design variants can now be generated from compact directions, reducing long-running agent stalls.
@@ -5,6 +5,7 @@ import type { AgentEngine, EngineTool, EngineMessage, EngineContentPart } from "
5
5
  import { type Processor } from "./processors.js";
6
6
  import { subscribeToRun, getActiveRunForThread, getActiveRunForThreadAsync, getRun, abortRun } from "./run-manager.js";
7
7
  import type { ActiveRun } from "./run-manager.js";
8
+ import { insertRun, updateRunHeartbeat, claimBackgroundRun, recordRunDiagnostic } from "./run-store.js";
8
9
  import type { ActionTool, AgentChatAttachment, AgentChatEvent, AgentChatReference, AgentChatStructuredMessage } from "./types.js";
9
10
  export { PROVIDER_TO_ENV };
10
11
  /**
@@ -477,6 +478,25 @@ export declare function shouldChainBackgroundContinuation(opts: {
477
478
  run: ActiveRun;
478
479
  continuationCount: number;
479
480
  }): boolean;
481
+ export declare function claimBackgroundWorkerRunEarly(opts: {
482
+ runId: string;
483
+ threadId?: string | null;
484
+ markerTurnId?: string | null;
485
+ requestTurnId?: string | null;
486
+ continuationCount: number;
487
+ runsInBackgroundFunction: boolean;
488
+ deps?: {
489
+ recordRunDiagnostic?: typeof recordRunDiagnostic;
490
+ insertRun?: typeof insertRun;
491
+ claimBackgroundRun?: typeof claimBackgroundRun;
492
+ updateRunHeartbeat?: typeof updateRunHeartbeat;
493
+ };
494
+ }): Promise<{
495
+ claimed: true;
496
+ } | {
497
+ claimed: false;
498
+ skipped: string;
499
+ }>;
480
500
  export declare function createProductionAgentHandler(options: ProductionAgentOptions): H3EventHandler;
481
501
  export { getActiveRunForThread, getActiveRunForThreadAsync, getRun, abortRun, subscribeToRun, };
482
502
  //# sourceMappingURL=production-agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,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f,iBAAiB,EAAE,MAAM,CAAC;CAC3B,GAAG,OAAO,CAOV;AAED,wBAAsB,6BAA6B,CAAC,IAAI,EAAE;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,wBAAwB,EAAE,OAAO,CAAC;IAClC,IAAI,CAAC,EAAE;QACL,mBAAmB,CAAC,EAAE,OAAO,mBAAmB,CAAC;QACjD,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;QAC7B,kBAAkB,CAAC,EAAE,OAAO,kBAAkB,CAAC;QAC/C,kBAAkB,CAAC,EAAE,OAAO,kBAAkB,CAAC;KAChD,CAAC;CACH,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAqCnE;AA+BD,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,sBAAsB,GAC9B,cAAc,CAmrDhB;AAED,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,MAAM,EACN,QAAQ,EACR,cAAc,GACf,CAAC"}
@@ -3046,6 +3046,34 @@ export function shouldChainBackgroundContinuation(opts) {
3046
3046
  endsAtInternalContinuationBoundary(opts.run) &&
3047
3047
  opts.continuationCount < MAX_BACKGROUND_RUN_CONTINUATIONS);
3048
3048
  }
3049
+ export async function claimBackgroundWorkerRunEarly(opts) {
3050
+ const record = opts.deps?.recordRunDiagnostic ?? recordRunDiagnostic;
3051
+ const insert = opts.deps?.insertRun ?? insertRun;
3052
+ const claim = opts.deps?.claimBackgroundRun ?? claimBackgroundRun;
3053
+ const heartbeat = opts.deps?.updateRunHeartbeat ?? updateRunHeartbeat;
3054
+ const threadId = typeof opts.threadId === "string" && opts.threadId.trim()
3055
+ ? opts.threadId.trim()
3056
+ : opts.runId;
3057
+ const turnId = typeof opts.markerTurnId === "string" && opts.markerTurnId.trim()
3058
+ ? opts.markerTurnId.trim()
3059
+ : typeof opts.requestTurnId === "string" && opts.requestTurnId.trim()
3060
+ ? opts.requestTurnId.trim()
3061
+ : opts.runId;
3062
+ await record(opts.runId, RUN_DIAG_STAGE.workerEntered, `runsInBackgroundFunction=${opts.runsInBackgroundFunction} continuationCount=${opts.continuationCount}`).catch(() => { });
3063
+ if (opts.continuationCount > 0) {
3064
+ await insert(opts.runId, threadId, turnId, {
3065
+ dispatchMode: "background",
3066
+ }).catch(() => { });
3067
+ }
3068
+ const won = await claim(opts.runId);
3069
+ if (!won) {
3070
+ await record(opts.runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => { });
3071
+ return { claimed: false, skipped: "already-claimed" };
3072
+ }
3073
+ await record(opts.runId, RUN_DIAG_STAGE.workerClaimed).catch(() => { });
3074
+ await heartbeat(opts.runId).catch(() => { });
3075
+ return { claimed: true };
3076
+ }
3049
3077
  function progressStepFromAgentChatEvent(event) {
3050
3078
  switch (event.type) {
3051
3079
  case "activity":
@@ -3164,6 +3192,23 @@ export function createProductionAgentHandler(options) {
3164
3192
  Number.isFinite(backgroundRunMarker.continuationCount)
3165
3193
  ? Math.max(0, Math.floor(backgroundRunMarker.continuationCount))
3166
3194
  : 0;
3195
+ let backgroundRunClaimedEarly = false;
3196
+ if (isBackgroundWorker && bgRunId) {
3197
+ const earlyClaim = await claimBackgroundWorkerRunEarly({
3198
+ runId: bgRunId,
3199
+ threadId,
3200
+ markerTurnId: typeof backgroundRunMarker?.turnId === "string"
3201
+ ? backgroundRunMarker.turnId
3202
+ : null,
3203
+ requestTurnId,
3204
+ continuationCount: backgroundContinuationCount,
3205
+ runsInBackgroundFunction,
3206
+ });
3207
+ if (!earlyClaim.claimed) {
3208
+ return { ok: true, skipped: earlyClaim.skipped };
3209
+ }
3210
+ backgroundRunClaimedEarly = true;
3211
+ }
3167
3212
  // The foreground POST decides whether to dispatch into a background
3168
3213
  // function. The background worker itself never re-dispatches.
3169
3214
  const dispatchToBackground = !isBackgroundWorker &&
@@ -4061,40 +4106,28 @@ export function createProductionAgentHandler(options) {
4061
4106
  }
4062
4107
  }
4063
4108
  : undefined;
4064
- // Background worker: claim the pre-inserted run idempotently before
4065
- // executing. A duplicate Netlify delivery loses the claim and no-ops here,
4066
- // so the run can never be double-executed. Bump the heartbeat immediately
4067
- // on entry so a slow cold-start doesn't leave the row looking stale to the
4068
- // reaper before startRun's 1.5s heartbeat timer takes over.
4109
+ // Background worker: the run was claimed immediately after the authenticated
4110
+ // `_process-run` body was parsed, before owner/model/prompt/tool setup. That
4111
+ // early claim is what lets the foreground subscribe to the real background
4112
+ // worker instead of racing slow setup and falling back to the 40s inline
4113
+ // path. This late block is a defensive fallback for older/custom callers
4114
+ // that somehow reach here without the early claim.
4069
4115
  if (isBackgroundWorker) {
4070
- // DIAGNOSTIC: the re-entered handler recognized itself as the background
4071
- // worker. Record the runtime regime too — `isInBackgroundFunctionRuntime()`
4072
- // reads a globalThis marker set by the bg-fn entry, which may NOT be set in
4073
- // this isolate; recording the ACTUAL resolved value reveals whether the
4074
- // worker is on the 13-min `-background` budget or the 40s clamp. This is
4075
- // the proof the worker reached its own code (vs. dying at auth before it).
4076
- await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerEntered, `runsInBackgroundFunction=${runsInBackgroundFunction} continuationCount=${backgroundContinuationCount}`).catch(() => { });
4077
- // A chained continuation chunk's runId was minted by the prior chunk and
4078
- // never inserted, so insert its background row now (idempotently — a
4079
- // duplicate Netlify delivery that already inserted it just PK-collides and
4080
- // the claim below dedups). The first chunk's row was inserted by the
4081
- // foreground, so skip the insert there.
4082
- if (isChainedBackgroundContinuation) {
4083
- await insertRun(runId, effectiveThreadId, effectiveTurnId, {
4084
- dispatchMode: "background",
4085
- }).catch(() => { });
4086
- }
4087
- const won = await claimBackgroundRun(runId);
4088
- if (!won) {
4089
- // Already claimed by an earlier delivery — return a benign ack so
4090
- // Netlify doesn't retry a successful handoff.
4091
- await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => { });
4092
- return { ok: true, skipped: "already-claimed" };
4116
+ if (!backgroundRunClaimedEarly) {
4117
+ await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerEntered, `runsInBackgroundFunction=${runsInBackgroundFunction} continuationCount=${backgroundContinuationCount}`).catch(() => { });
4118
+ if (isChainedBackgroundContinuation) {
4119
+ await insertRun(runId, effectiveThreadId, effectiveTurnId, {
4120
+ dispatchMode: "background",
4121
+ }).catch(() => { });
4122
+ }
4123
+ const won = await claimBackgroundRun(runId);
4124
+ if (!won) {
4125
+ await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimLost).catch(() => { });
4126
+ return { ok: true, skipped: "already-claimed" };
4127
+ }
4128
+ await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimed).catch(() => { });
4129
+ await updateRunHeartbeat(runId).catch(() => { });
4093
4130
  }
4094
- // DIAGNOSTIC: this worker won the claim and now OWNS the run. If a run
4095
- // ever stalls at this stage it means the loop below failed to start.
4096
- await recordRunDiagnostic(runId, RUN_DIAG_STAGE.workerClaimed).catch(() => { });
4097
- await updateRunHeartbeat(runId).catch(() => { });
4098
4131
  }
4099
4132
  // DIAGNOSTIC-ONLY: build the pre-startRun setup-timing breakdown now (so the
4100
4133
  // marks reflect the work done BEFORE the loop), but EMIT it from inside