@vibes.diy/api-svc 14.2.6 → 14.2.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.
- package/create-handler.js +0 -6
- package/create-handler.js.map +1 -1
- package/index.d.ts +0 -2
- package/index.js +0 -2
- package/index.js.map +1 -1
- package/intern/agent-assembly.d.ts +0 -2
- package/intern/agent-assembly.js +1 -4
- package/intern/agent-assembly.js.map +1 -1
- package/intern/agent-first-turn-eligible.d.ts +1 -7
- package/intern/agent-first-turn-eligible.js +2 -5
- package/intern/agent-first-turn-eligible.js.map +1 -1
- package/intern/agent-router.d.ts +1 -3
- package/intern/agent-router.js +0 -16
- package/intern/agent-router.js.map +1 -1
- package/intern/agent-session-instruction.js.map +1 -1
- package/intern/agent-turn.d.ts +1 -4
- package/intern/agent-turn.js +4 -7
- package/intern/agent-turn.js.map +1 -1
- package/intern/agent-wake.d.ts +2 -3
- package/intern/agent-wake.js +2 -24
- package/intern/agent-wake.js.map +1 -1
- package/intern/codegen-build-lock.d.ts +0 -5
- package/intern/codegen-build-lock.js +0 -3
- package/intern/codegen-build-lock.js.map +1 -1
- package/intern/ensure-chat-id.js.map +1 -1
- package/intern/mint-decision.js.map +1 -1
- package/intern/mint-fire-core.js.map +1 -1
- package/intern/open-turn-store.d.ts +0 -4
- package/intern/open-turn-store.js +1 -6
- package/intern/open-turn-store.js.map +1 -1
- package/intern/open-turn-sweep.js +0 -1
- package/intern/open-turn-sweep.js.map +1 -1
- package/package.json +12 -12
- package/public/llm-dispatch.js +1 -3
- package/public/llm-dispatch.js.map +1 -1
- package/public/open-chat.js +3 -4
- package/public/open-chat.js.map +1 -1
- package/public/prompt-chat-section.js +275 -299
- package/public/prompt-chat-section.js.map +1 -1
- package/public/shared-mint.js +1 -1
- package/public/shared-mint.js.map +1 -1
- package/usage-report/codegen-delivery-alert-util.js.map +1 -1
- package/intern/agent-instruction.d.ts +0 -2
- package/intern/agent-instruction.js +0 -433
- package/intern/agent-instruction.js.map +0 -1
- package/intern/agent-lane-flag.d.ts +0 -21
- package/intern/agent-lane-flag.js +0 -10
- package/intern/agent-lane-flag.js.map +0 -1
|
@@ -27,12 +27,11 @@ import { bumpAppRecency } from "../intern/bump-app-recency.js";
|
|
|
27
27
|
import { waitChatPersistIdle } from "../intern/chat-persist-gate.js";
|
|
28
28
|
import { peekInFlightTurns } from "../intern/in-flight-turns.js";
|
|
29
29
|
import { acquireTurnBuildLock, peekBuildLockEntry, releaseTurnBuildLock } from "../intern/codegen-build-lock.js";
|
|
30
|
-
import { agentFirstTurnEnabled, agentLaneEnabled, agentSessionEnabled } from "../intern/agent-lane-flag.js";
|
|
31
30
|
import { deliverAgentSession } from "../intern/agent-session-runtime.js";
|
|
32
31
|
import { readAgentSession } from "../intern/agent-session-store.js";
|
|
33
32
|
import { runEditVibeTool } from "../intern/agent-build-tools.js";
|
|
34
33
|
import { claimFirstTurnMint, claimMintJob, getMintJob } from "../intern/mint-job-store.js";
|
|
35
|
-
import { codegenTurnLane,
|
|
34
|
+
import { codegenTurnLane, mintRowSaysFirstTurnIsAgents, routeAgentTurn } from "../intern/agent-router.js";
|
|
36
35
|
import { assembleAgentPayload } from "../intern/agent-assembly.js";
|
|
37
36
|
import { claimAgentAppContext, composeAgentRequest, isAppContextMessage, markJournalCacheTail, } from "../intern/agent-request-frame.js";
|
|
38
37
|
import { createAgentBelt } from "../intern/agent-belt.js";
|
|
@@ -159,9 +158,8 @@ export const promptChatSection = {
|
|
|
159
158
|
const agentWakeBudget = readAgentWakeBudget(orig.agentWakeBudget);
|
|
160
159
|
const agentWakeNoteRaw = orig.agentWakeNote;
|
|
161
160
|
const agentWakeNote = agentWakeTurn === true && typeof agentWakeNoteRaw === "string" ? agentWakeNoteRaw : undefined;
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
const nonInteractive = agentLane && orig.nonInteractive === true;
|
|
161
|
+
const firstTurnAgent = orig.firstTurnAgent === true;
|
|
162
|
+
const nonInteractive = orig.nonInteractive === true;
|
|
165
163
|
let agentFetchUrlContext;
|
|
166
164
|
await waitChatPersistIdle(vctx.connections, req.chatId, { logger: vctx.logger });
|
|
167
165
|
const rResChat = await getResChatFromMode(vctx, req, orig);
|
|
@@ -207,7 +205,6 @@ export const promptChatSection = {
|
|
|
207
205
|
}
|
|
208
206
|
}
|
|
209
207
|
const routeInput = {
|
|
210
|
-
agentLane,
|
|
211
208
|
codegenChatTurn: true,
|
|
212
209
|
dryRun: orig.dryRun === true,
|
|
213
210
|
directBuildRequested,
|
|
@@ -216,10 +213,8 @@ export const promptChatSection = {
|
|
|
216
213
|
firstTurnAgent,
|
|
217
214
|
};
|
|
218
215
|
let agentRoute = routeAgentTurn(routeInput);
|
|
219
|
-
const mintRowWorthReading =
|
|
220
|
-
|
|
221
|
-
((agentRoute.route === "codegen" && agentRoute.skip === "first-turn") ||
|
|
222
|
-
(agentRoute.route === "agent" && hasPriorTurn === true));
|
|
216
|
+
const mintRowWorthReading = (agentRoute.route === "codegen" && agentRoute.skip === "first-turn") ||
|
|
217
|
+
(agentRoute.route === "agent" && hasPriorTurn === true);
|
|
223
218
|
if (mintRowWorthReading) {
|
|
224
219
|
const rJob = await getMintJob(vctx, req.chatId);
|
|
225
220
|
if (rJob.isErr()) {
|
|
@@ -249,12 +244,11 @@ export const promptChatSection = {
|
|
|
249
244
|
appSlug: resChat.appSlug,
|
|
250
245
|
activatedUrls: activateWorkUrls(currentUserMessageText(orig.prompt.messages.filter(isChatMessage))),
|
|
251
246
|
});
|
|
252
|
-
const legacyHint = legacyVariantHint(orig.variant);
|
|
253
247
|
const buildInFlight = peekBuildLockEntry(vctx.connections, req.chatId);
|
|
254
|
-
const rSeenHead =
|
|
255
|
-
if (rSeenHead
|
|
248
|
+
const rSeenHead = await readAgentSession(vctx.sql, req.chatId);
|
|
249
|
+
if (rSeenHead.isErr())
|
|
256
250
|
vctx.logger.Warn().Err(rSeenHead).Str("chatId", req.chatId).Msg("agent-session-head-read-failed");
|
|
257
|
-
const lastSeenHeadFsId = rSeenHead
|
|
251
|
+
const lastSeenHeadFsId = rSeenHead.isOk() ? rSeenHead.Ok().snapshot?.headFsId : undefined;
|
|
258
252
|
const rAgent = await assembleAgentPayload(vctx, {
|
|
259
253
|
chatId: req.chatId,
|
|
260
254
|
userId: req._auth.verifiedAuth.claims.userId,
|
|
@@ -262,171 +256,167 @@ export const promptChatSection = {
|
|
|
262
256
|
ownerHandle: resChat.ownerHandle,
|
|
263
257
|
appSlug: resChat.appSlug,
|
|
264
258
|
newUserMessages: orig.prompt.messages.filter(isChatMessage),
|
|
265
|
-
...(legacyHint === undefined ? {} : { legacyHint }),
|
|
266
259
|
...(agentWakeNote === undefined ? {} : { wakeNote: agentWakeNote }),
|
|
267
260
|
...(buildInFlight === undefined ? {} : { buildInFlight: { promptId: buildInFlight.promptId } }),
|
|
268
261
|
...(agentFirstTurnMint ? { noAppYet: true } : {}),
|
|
269
262
|
...(nonInteractive ? { nonInteractive: true } : {}),
|
|
270
|
-
...(agentSessionEnabled(vctx) ? { session: true } : {}),
|
|
271
263
|
...(lastSeenHeadFsId === undefined ? {} : { lastSeenHeadFsId }),
|
|
272
264
|
});
|
|
273
265
|
if (rAgent.isErr())
|
|
274
266
|
return Result.Err(rAgent);
|
|
275
267
|
agentAssembled = { model: rAgent.Ok().model, messages: rAgent.Ok().messages };
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
268
|
+
const rawIncoming = orig.prompt.messages.filter(isUserChatMessage);
|
|
269
|
+
const newMessageCount = orig.prompt.messages.filter(isChatMessage).length;
|
|
270
|
+
const incoming = newMessageCount === 0 ? [] : rAgent.Ok().messages.slice(-newMessageCount).filter(isUserChatMessage);
|
|
271
|
+
const delivered = incoming.length === 0 && agentWakeTurn
|
|
272
|
+
? [
|
|
273
|
+
{
|
|
274
|
+
role: "user",
|
|
275
|
+
content: [
|
|
276
|
+
{
|
|
277
|
+
type: "text",
|
|
278
|
+
text: agentWakeNote ??
|
|
279
|
+
"[session resumed] Continue from your persisted context and pending results. Inspect outcomes before retrying interrupted tools.",
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
},
|
|
283
|
+
]
|
|
284
|
+
: incoming;
|
|
285
|
+
const acquired = await deliverAgentSession(vctx, {
|
|
286
|
+
chatId: req.chatId,
|
|
287
|
+
userId: req._auth.verifiedAuth.claims.userId,
|
|
288
|
+
ownerHandle: resChat.ownerHandle,
|
|
289
|
+
appSlug: resChat.appSlug,
|
|
290
|
+
}, { id: ctx.validated.tid, messages: delivered }, rAgent.Ok().messages.filter((message) => message.role === "system" || isAppContextMessage(message)));
|
|
291
|
+
if (acquired.isErr())
|
|
292
|
+
return Result.Err(acquired.Err());
|
|
293
|
+
const { live, created } = acquired.Ok();
|
|
294
|
+
const composedHead = rAgent.Ok().headFsId;
|
|
295
|
+
if (composedHead !== undefined) {
|
|
296
|
+
const noted = await live.session.observeHead(composedHead);
|
|
297
|
+
if (noted.isErr())
|
|
298
|
+
vctx.logger.Warn().Err(noted).Str("chatId", req.chatId).Msg("agent-session-head-note-failed");
|
|
299
|
+
}
|
|
300
|
+
if (created === false) {
|
|
301
|
+
const receiptId = vctx.sthis.nextId(12).str;
|
|
302
|
+
const receiptEvidence = createAgentEvidenceWriter({
|
|
295
303
|
chatId: req.chatId,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (noted.isErr())
|
|
307
|
-
vctx.logger.Warn().Err(noted).Str("chatId", req.chatId).Msg("agent-session-head-note-failed");
|
|
308
|
-
}
|
|
309
|
-
if (created === false) {
|
|
310
|
-
const receiptId = vctx.sthis.nextId(12).str;
|
|
311
|
-
const receiptEvidence = createAgentEvidenceWriter({
|
|
304
|
+
promptId: receiptId,
|
|
305
|
+
sessionId: live.promptId,
|
|
306
|
+
append: (evt, blockSeq) => appendBlockEvent({ ctx, vctx, req, promptId: receiptId, blockSeq, evt }),
|
|
307
|
+
});
|
|
308
|
+
const linked = await receiptEvidence({ kind: "active" });
|
|
309
|
+
if (linked.isErr())
|
|
310
|
+
return Result.Err(linked.Err());
|
|
311
|
+
await ctx.send.send(ctx, wrapMsgBase(ctx.validated, {
|
|
312
|
+
payload: {
|
|
313
|
+
type: "vibes.diy.res-prompt-chat-section",
|
|
312
314
|
chatId: req.chatId,
|
|
315
|
+
ownerHandle: resChat.ownerHandle,
|
|
316
|
+
appSlug: resChat.appSlug,
|
|
313
317
|
promptId: receiptId,
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
blockSeq: 1,
|
|
357
|
-
evt: {
|
|
358
|
-
type: "block.end",
|
|
359
|
-
streamId: receiptId,
|
|
360
|
-
blockId: receiptId,
|
|
361
|
-
blockNr: 0,
|
|
362
|
-
seq: 1,
|
|
363
|
-
timestamp: new Date(),
|
|
364
|
-
stats: {
|
|
365
|
-
toplevel: { lines: 0, bytes: 0 },
|
|
366
|
-
code: { lines: 0, bytes: 0 },
|
|
367
|
-
image: { lines: 0, bytes: 0 },
|
|
368
|
-
total: { lines: 0, bytes: 0 },
|
|
369
|
-
},
|
|
370
|
-
usage: { given: [], calculated: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 } },
|
|
318
|
+
outerTid: req.outerTid,
|
|
319
|
+
mode: req.mode,
|
|
320
|
+
},
|
|
321
|
+
tid: ctx.validated.tid,
|
|
322
|
+
src: "agentSession",
|
|
323
|
+
}));
|
|
324
|
+
const echo = await appendBlockEvent({
|
|
325
|
+
ctx,
|
|
326
|
+
vctx,
|
|
327
|
+
req,
|
|
328
|
+
promptId: receiptId,
|
|
329
|
+
blockSeq: 0,
|
|
330
|
+
evt: {
|
|
331
|
+
type: "prompt.req",
|
|
332
|
+
...(orig.mode === "codegen" && orig.source === "suggestion" ? { source: "suggestion" } : {}),
|
|
333
|
+
streamId: receiptId,
|
|
334
|
+
chatId: req.chatId,
|
|
335
|
+
seq: 0,
|
|
336
|
+
request: { messages: rawIncoming },
|
|
337
|
+
timestamp: new Date(),
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
if (echo.isErr())
|
|
341
|
+
return Result.Err(echo.Err());
|
|
342
|
+
const terminal = await appendBlockEvent({
|
|
343
|
+
ctx,
|
|
344
|
+
vctx,
|
|
345
|
+
req,
|
|
346
|
+
promptId: receiptId,
|
|
347
|
+
blockSeq: 1,
|
|
348
|
+
evt: {
|
|
349
|
+
type: "block.end",
|
|
350
|
+
streamId: receiptId,
|
|
351
|
+
blockId: receiptId,
|
|
352
|
+
blockNr: 0,
|
|
353
|
+
seq: 1,
|
|
354
|
+
timestamp: new Date(),
|
|
355
|
+
stats: {
|
|
356
|
+
toplevel: { lines: 0, bytes: 0 },
|
|
357
|
+
code: { lines: 0, bytes: 0 },
|
|
358
|
+
image: { lines: 0, bytes: 0 },
|
|
359
|
+
total: { lines: 0, bytes: 0 },
|
|
371
360
|
},
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
return Result.Err(terminal.Err());
|
|
375
|
-
const ended = await appendBlockEvent({
|
|
376
|
-
ctx,
|
|
377
|
-
vctx,
|
|
378
|
-
req,
|
|
379
|
-
promptId: receiptId,
|
|
380
|
-
blockSeq: 2,
|
|
381
|
-
evt: { type: "prompt.block-end", streamId: receiptId, chatId: req.chatId, seq: 2, timestamp: new Date() },
|
|
382
|
-
});
|
|
383
|
-
if (ended.isErr())
|
|
384
|
-
return Result.Err(ended.Err());
|
|
385
|
-
return Result.Ok(EventoResult.Continue);
|
|
386
|
-
}
|
|
387
|
-
agentSession = live;
|
|
388
|
-
agentEvidence = observeEvidenceLine(createAgentEvidenceWriter({
|
|
389
|
-
chatId: req.chatId,
|
|
390
|
-
promptId: live.promptId,
|
|
391
|
-
sessionId: live.promptId,
|
|
392
|
-
append: (evt, blockSeq) => appendBlockEvent({ ctx, vctx, req, promptId: live.promptId, blockSeq, evt }),
|
|
393
|
-
}), turnLatency);
|
|
394
|
-
const active = await agentEvidence({
|
|
395
|
-
kind: "active",
|
|
396
|
-
...(live.supersedes === undefined ? {} : { supersedes: live.supersedes }),
|
|
361
|
+
usage: { given: [], calculated: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 } },
|
|
362
|
+
},
|
|
397
363
|
});
|
|
398
|
-
if (
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
364
|
+
if (terminal.isErr())
|
|
365
|
+
return Result.Err(terminal.Err());
|
|
366
|
+
const ended = await appendBlockEvent({
|
|
367
|
+
ctx,
|
|
368
|
+
vctx,
|
|
369
|
+
req,
|
|
370
|
+
promptId: receiptId,
|
|
371
|
+
blockSeq: 2,
|
|
372
|
+
evt: { type: "prompt.block-end", streamId: receiptId, chatId: req.chatId, seq: 2, timestamp: new Date() },
|
|
373
|
+
});
|
|
374
|
+
if (ended.isErr())
|
|
375
|
+
return Result.Err(ended.Err());
|
|
376
|
+
return Result.Ok(EventoResult.Continue);
|
|
377
|
+
}
|
|
378
|
+
agentSession = live;
|
|
379
|
+
agentEvidence = observeEvidenceLine(createAgentEvidenceWriter({
|
|
380
|
+
chatId: req.chatId,
|
|
381
|
+
promptId: live.promptId,
|
|
382
|
+
sessionId: live.promptId,
|
|
383
|
+
append: (evt, blockSeq) => appendBlockEvent({ ctx, vctx, req, promptId: live.promptId, blockSeq, evt }),
|
|
384
|
+
}), turnLatency);
|
|
385
|
+
const active = await agentEvidence({
|
|
386
|
+
kind: "active",
|
|
387
|
+
...(live.supersedes === undefined ? {} : { supersedes: live.supersedes }),
|
|
388
|
+
});
|
|
389
|
+
if (active.isErr()) {
|
|
390
|
+
live.close();
|
|
391
|
+
return Result.Err(active.Err());
|
|
392
|
+
}
|
|
393
|
+
if (live.session.messages().length === 0) {
|
|
394
|
+
const initial = agentAssembled.messages.slice(0, agentAssembled.messages.length - newMessageCount - (agentWakeNote === undefined ? 0 : 1));
|
|
395
|
+
const saved = await live.session.checkpoint(initial);
|
|
425
396
|
if (saved.isErr()) {
|
|
426
397
|
live.close();
|
|
427
398
|
return Result.Err(saved.Err());
|
|
428
399
|
}
|
|
429
400
|
}
|
|
401
|
+
const events = await nextAgentSessionMessages(live.session, agentEvidence);
|
|
402
|
+
if (events.isErr()) {
|
|
403
|
+
live.close();
|
|
404
|
+
return Result.Err(events.Err());
|
|
405
|
+
}
|
|
406
|
+
agentAssembled = {
|
|
407
|
+
...agentAssembled,
|
|
408
|
+
messages: composeAgentRequest({
|
|
409
|
+
system: agentAssembled.messages.filter((message) => message.role === "system"),
|
|
410
|
+
journal: markJournalCacheTail(live.session.messages()),
|
|
411
|
+
context: agentAssembled.messages.filter(isAppContextMessage),
|
|
412
|
+
tail: events.Ok() ?? [],
|
|
413
|
+
}),
|
|
414
|
+
};
|
|
415
|
+
const saved = await live.session.checkpoint(agentAssembled.messages);
|
|
416
|
+
if (saved.isErr()) {
|
|
417
|
+
live.close();
|
|
418
|
+
return Result.Err(saved.Err());
|
|
419
|
+
}
|
|
430
420
|
}
|
|
431
421
|
else {
|
|
432
422
|
const rAssembled = await assemblePromptPayload(vctx, {
|
|
@@ -552,8 +542,10 @@ export const promptChatSection = {
|
|
|
552
542
|
}
|
|
553
543
|
else if (agentAssembled !== undefined && isReqPromptLLMChatSection(orig)) {
|
|
554
544
|
const agentPayload = agentAssembled;
|
|
545
|
+
const liveSession = agentSession;
|
|
546
|
+
if (liveSession === undefined)
|
|
547
|
+
return Result.Err("Agent turn has no session");
|
|
555
548
|
prompSectionAction = async (scope, blockSeq) => {
|
|
556
|
-
const liveSession = agentSession;
|
|
557
549
|
const rActor = await resolveAgentActor(vctx, {
|
|
558
550
|
userId: req._auth.verifiedAuth.claims.userId,
|
|
559
551
|
scope: agentFirstTurnMint
|
|
@@ -570,12 +562,9 @@ export const promptChatSection = {
|
|
|
570
562
|
appSlug: resChat.appSlug,
|
|
571
563
|
editBaseFsId: undefined,
|
|
572
564
|
});
|
|
573
|
-
if (
|
|
565
|
+
if (rVfs.isErr())
|
|
574
566
|
return Result.Err(rVfs.Err());
|
|
575
|
-
|
|
576
|
-
vctx.logger.Warn().Err(rVfs).Str("chatId", req.chatId).Msg("agent-turn-vfs-load-failed");
|
|
577
|
-
}
|
|
578
|
-
const vfs = new Map(rVfs.isOk() ? rVfs.Ok() : []);
|
|
567
|
+
const vfs = new Map(rVfs.Ok());
|
|
579
568
|
function extendDeadlineForAwaitedBuild(awaiting) {
|
|
580
569
|
void extendOpenTurnDeadline(vctx.sql, {
|
|
581
570
|
chatId: req.chatId,
|
|
@@ -600,15 +589,11 @@ export const promptChatSection = {
|
|
|
600
589
|
auth: orig.auth,
|
|
601
590
|
outerTid: req.outerTid,
|
|
602
591
|
handle: (dispatchCtx) => promptChatSection.handle(dispatchCtx),
|
|
603
|
-
wakeBudget:
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
extendDeadlineForAwaitedBuild(t.promptId);
|
|
609
|
-
return agentSession?.watch(t.promptId);
|
|
610
|
-
},
|
|
611
|
-
}),
|
|
592
|
+
wakeBudget: 0,
|
|
593
|
+
onPendingBuild: (t) => {
|
|
594
|
+
extendDeadlineForAwaitedBuild(t.promptId);
|
|
595
|
+
return liveSession.watch(t.promptId);
|
|
596
|
+
},
|
|
612
597
|
...(agentFirstTurnMint
|
|
613
598
|
? {
|
|
614
599
|
firstTurn: {
|
|
@@ -643,8 +628,8 @@ export const promptChatSection = {
|
|
|
643
628
|
: {}),
|
|
644
629
|
...(agentFetchUrlContext === undefined ? {} : { fetchUrl: agentFetchUrlContext }),
|
|
645
630
|
dispatcher,
|
|
646
|
-
|
|
647
|
-
|
|
631
|
+
queueEdit: (input) => liveSession.queue(input),
|
|
632
|
+
fileSession: liveSession,
|
|
648
633
|
onStyleApplied: async (applied) => {
|
|
649
634
|
await appendBlockEvent({
|
|
650
635
|
ctx,
|
|
@@ -666,7 +651,7 @@ export const promptChatSection = {
|
|
|
666
651
|
},
|
|
667
652
|
onDispatch: (dispatched) => {
|
|
668
653
|
liveAppSlug = dispatched.appSlug;
|
|
669
|
-
liveSession
|
|
654
|
+
liveSession.claimAppAddress(dispatched.appSlug);
|
|
670
655
|
firstTurnAppClaimed = true;
|
|
671
656
|
vctx.logger
|
|
672
657
|
.Info()
|
|
@@ -675,106 +660,104 @@ export const promptChatSection = {
|
|
|
675
660
|
},
|
|
676
661
|
});
|
|
677
662
|
turnToolsOffered = belt.definitions.map((d) => d.function.name);
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
message: "Call create_vibe first; there is no app to edit until it has been created.",
|
|
691
|
-
});
|
|
692
|
-
const currentActor = await resolveAgentActor(vctx, {
|
|
693
|
-
userId: rActor.Ok().userId,
|
|
694
|
-
requestedHandle: rActor.Ok().ownerHandle,
|
|
695
|
-
scope: rActor.Ok().scope,
|
|
663
|
+
await liveSession.bind((input) => runEditVibeTool(vctx, {
|
|
664
|
+
actor: rActor.Ok(),
|
|
665
|
+
chatId: req.chatId,
|
|
666
|
+
input,
|
|
667
|
+
dispatcher,
|
|
668
|
+
toolsOffered: belt.definitions.map((d) => d.function.name),
|
|
669
|
+
}), async (commit) => {
|
|
670
|
+
if (firstTurnAppClaimed === false)
|
|
671
|
+
return Result.Ok({
|
|
672
|
+
ok: false,
|
|
673
|
+
reason: "no-app-yet",
|
|
674
|
+
message: "Call create_vibe first; there is no app to edit until it has been created.",
|
|
696
675
|
});
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
676
|
+
const currentActor = await resolveAgentActor(vctx, {
|
|
677
|
+
userId: rActor.Ok().userId,
|
|
678
|
+
requestedHandle: rActor.Ok().ownerHandle,
|
|
679
|
+
scope: rActor.Ok().scope,
|
|
680
|
+
});
|
|
681
|
+
if (currentActor.isErr())
|
|
682
|
+
return Result.Err(currentActor.Err());
|
|
683
|
+
const scoped = await resolveChatApp(vctx, currentActor.Ok(), req.chatId);
|
|
684
|
+
if (scoped.isErr())
|
|
685
|
+
return Result.Err(scoped.Err());
|
|
686
|
+
const commitId = vctx.sthis.nextId(12).str;
|
|
687
|
+
const lock = acquireTurnBuildLock({
|
|
688
|
+
vctx,
|
|
689
|
+
chatId: req.chatId,
|
|
690
|
+
promptId: commitId,
|
|
691
|
+
movesFilesystem: true,
|
|
692
|
+
wakesOnTerminal: false,
|
|
693
|
+
});
|
|
694
|
+
if (lock.acquired === false)
|
|
695
|
+
return Result.Err("A build is running; the staged commit could not acquire the write lane.");
|
|
696
|
+
const committed = { promptBlockEndEmitted: false };
|
|
697
|
+
const saved = await exception2Result(() => handleFSPrompt({
|
|
698
|
+
scope,
|
|
699
|
+
vctx,
|
|
700
|
+
ctx,
|
|
701
|
+
promptId: commitId,
|
|
702
|
+
blockSeq: 0,
|
|
703
|
+
terminal: committed,
|
|
704
|
+
beginDirect: true,
|
|
705
|
+
resChat: { ...resChat, mode: "fs-update" },
|
|
706
|
+
req: {
|
|
707
|
+
type: "vibes.diy.req-prompt-chat-section",
|
|
708
|
+
mode: "fs-update",
|
|
709
|
+
auth: orig.auth,
|
|
710
|
+
_auth: req._auth,
|
|
705
711
|
chatId: req.chatId,
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
712
|
+
outerTid: req.outerTid,
|
|
713
|
+
agentFileCommit: commit,
|
|
714
|
+
fsUpdate: {
|
|
715
|
+
update: commit.changes.map((file) => ({
|
|
716
|
+
type: "code-block",
|
|
717
|
+
filename: file.path,
|
|
718
|
+
content: file.contents,
|
|
719
|
+
lang: langForFilename(file.path),
|
|
720
|
+
})),
|
|
721
|
+
remove: [],
|
|
722
|
+
},
|
|
723
|
+
},
|
|
724
|
+
})).finally(() => {
|
|
725
|
+
committed.releasePersistGate?.();
|
|
726
|
+
releaseTurnBuildLock(vctx, req.chatId, commitId);
|
|
727
|
+
});
|
|
728
|
+
if (saved.isErr()) {
|
|
729
|
+
const last = await maxPersistedBlockSeq(vctx.sql, { chatId: req.chatId, promptId: commitId });
|
|
730
|
+
if (last.isErr())
|
|
731
|
+
return Result.Err(last.Err());
|
|
732
|
+
const seq = (last.Ok() ?? -1) + 1;
|
|
733
|
+
await appendBlockEvent({
|
|
716
734
|
ctx,
|
|
735
|
+
vctx,
|
|
736
|
+
req,
|
|
717
737
|
promptId: commitId,
|
|
718
|
-
blockSeq:
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
req: {
|
|
723
|
-
type: "vibes.diy.req-prompt-chat-section",
|
|
724
|
-
mode: "fs-update",
|
|
725
|
-
auth: orig.auth,
|
|
726
|
-
_auth: req._auth,
|
|
738
|
+
blockSeq: seq,
|
|
739
|
+
evt: {
|
|
740
|
+
type: "prompt.error",
|
|
741
|
+
streamId: commitId,
|
|
727
742
|
chatId: req.chatId,
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
update: commit.changes.map((file) => ({
|
|
732
|
-
type: "code-block",
|
|
733
|
-
filename: file.path,
|
|
734
|
-
content: file.contents,
|
|
735
|
-
lang: langForFilename(file.path),
|
|
736
|
-
})),
|
|
737
|
-
remove: [],
|
|
738
|
-
},
|
|
743
|
+
seq,
|
|
744
|
+
timestamp: new Date(),
|
|
745
|
+
error: saved.Err().message,
|
|
739
746
|
},
|
|
740
|
-
})).finally(() => {
|
|
741
|
-
committed.releasePersistGate?.();
|
|
742
|
-
releaseTurnBuildLock(vctx, req.chatId, commitId);
|
|
743
|
-
});
|
|
744
|
-
if (saved.isErr()) {
|
|
745
|
-
const last = await maxPersistedBlockSeq(vctx.sql, { chatId: req.chatId, promptId: commitId });
|
|
746
|
-
if (last.isErr())
|
|
747
|
-
return Result.Err(last.Err());
|
|
748
|
-
const seq = (last.Ok() ?? -1) + 1;
|
|
749
|
-
await appendBlockEvent({
|
|
750
|
-
ctx,
|
|
751
|
-
vctx,
|
|
752
|
-
req,
|
|
753
|
-
promptId: commitId,
|
|
754
|
-
blockSeq: seq,
|
|
755
|
-
evt: {
|
|
756
|
-
type: "prompt.error",
|
|
757
|
-
streamId: commitId,
|
|
758
|
-
chatId: req.chatId,
|
|
759
|
-
seq,
|
|
760
|
-
timestamp: new Date(),
|
|
761
|
-
error: saved.Err().message,
|
|
762
|
-
},
|
|
763
|
-
});
|
|
764
|
-
return Result.Err(saved.Err());
|
|
765
|
-
}
|
|
766
|
-
if (committed.fsRef === undefined)
|
|
767
|
-
return Result.Err("The commit did not persist a version.");
|
|
768
|
-
const committedPaths = commit.changes.map((file) => file.path);
|
|
769
|
-
return Result.Ok({
|
|
770
|
-
ok: true,
|
|
771
|
-
saved: true,
|
|
772
|
-
fsRef: committed.fsRef,
|
|
773
|
-
paths: committedPaths,
|
|
774
|
-
entryTouched: classifyTurnReach(committedPaths).entryTouched,
|
|
775
747
|
});
|
|
748
|
+
return Result.Err(saved.Err());
|
|
749
|
+
}
|
|
750
|
+
if (committed.fsRef === undefined)
|
|
751
|
+
return Result.Err("The commit did not persist a version.");
|
|
752
|
+
const committedPaths = commit.changes.map((file) => file.path);
|
|
753
|
+
return Result.Ok({
|
|
754
|
+
ok: true,
|
|
755
|
+
saved: true,
|
|
756
|
+
fsRef: committed.fsRef,
|
|
757
|
+
paths: committedPaths,
|
|
758
|
+
entryTouched: classifyTurnReach(committedPaths).entryTouched,
|
|
776
759
|
});
|
|
777
|
-
}
|
|
760
|
+
});
|
|
778
761
|
const res = await handlerLlmRequest({
|
|
779
762
|
ctx,
|
|
780
763
|
blockSeq,
|
|
@@ -790,7 +773,7 @@ export const promptChatSection = {
|
|
|
790
773
|
observeEvidenceLine(createAgentEvidenceWriter({
|
|
791
774
|
chatId: req.chatId,
|
|
792
775
|
promptId,
|
|
793
|
-
|
|
776
|
+
sessionId: liveSession.promptId,
|
|
794
777
|
append: (evt, blockSeq) => appendBlockEvent({ ctx, vctx, req, promptId, blockSeq, evt }),
|
|
795
778
|
}), turnLatency);
|
|
796
779
|
let providerStream;
|
|
@@ -810,33 +793,29 @@ export const promptChatSection = {
|
|
|
810
793
|
stream: rSse.Ok(),
|
|
811
794
|
abort: res.abort,
|
|
812
795
|
onToolEvidence: ({ kind, call, text, round, epoch }) => evidence({ kind, callId: call.id, name: call.name, text, round, epoch }),
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
head: () => liveSession.session.head(),
|
|
832
|
-
dispatchBudgetMs: agentTotalBudgetMs(vctx),
|
|
833
|
-
},
|
|
834
|
-
}),
|
|
796
|
+
session: {
|
|
797
|
+
checkpoint: async (messages) => {
|
|
798
|
+
const saved = await liveSession.session.checkpoint(messages);
|
|
799
|
+
if (saved.isErr())
|
|
800
|
+
return saved;
|
|
801
|
+
const extended = await extendOpenTurnDeadline(vctx.sql, {
|
|
802
|
+
chatId: req.chatId,
|
|
803
|
+
promptId,
|
|
804
|
+
deadlineAtMs: Date.now() + agentTotalBudgetMs(vctx) + OPEN_TURN_AWAIT_BUILD_EXTENSION_MS,
|
|
805
|
+
});
|
|
806
|
+
if (extended.isErr())
|
|
807
|
+
return Result.Err(extended.Err());
|
|
808
|
+
return Result.Ok();
|
|
809
|
+
},
|
|
810
|
+
next: () => nextAgentSessionMessages(liveSession.session, evidence),
|
|
811
|
+
head: () => liveSession.session.head(),
|
|
812
|
+
dispatchBudgetMs: agentTotalBudgetMs(vctx),
|
|
813
|
+
},
|
|
835
814
|
dispatch: async ({ request, budget }) => {
|
|
836
815
|
const messages = agentFirstTurnMint && firstTurnAppClaimed
|
|
837
816
|
? claimAgentAppContext(request.messages, { ownerHandle: resChat.ownerHandle, appSlug: liveAppSlug })
|
|
838
817
|
: request.messages;
|
|
839
|
-
|
|
818
|
+
{
|
|
840
819
|
const latest = await loadWorkVfs(vctx, {
|
|
841
820
|
chatId: req.chatId,
|
|
842
821
|
ownerHandle: resChat.ownerHandle,
|
|
@@ -966,7 +945,6 @@ export const promptChatSection = {
|
|
|
966
945
|
const promptId = agentSession?.promptId ?? vctx.sthis.nextId(96 / 8).str;
|
|
967
946
|
const movesFilesystem = isSourceChangingMode(req.mode) && agentAssembled === undefined;
|
|
968
947
|
const wakesOnTerminal = decideAgentWake({
|
|
969
|
-
agentLane,
|
|
970
948
|
agentDispatched: agentDispatchedBuild,
|
|
971
949
|
movedFilesystem: movesFilesystem,
|
|
972
950
|
budget: agentWakeBudget,
|
|
@@ -1181,10 +1159,9 @@ export const promptChatSection = {
|
|
|
1181
1159
|
};
|
|
1182
1160
|
const { consumed } = settleTurnTerminal(vctx.connections, req.chatId, promptId, landingOutcome);
|
|
1183
1161
|
const wake = decideAgentWake({
|
|
1184
|
-
agentLane,
|
|
1185
1162
|
agentDispatched: agentDispatchedBuild,
|
|
1186
1163
|
movedFilesystem: movesFilesystem,
|
|
1187
|
-
budget:
|
|
1164
|
+
budget: 1,
|
|
1188
1165
|
});
|
|
1189
1166
|
if (consumed === true) {
|
|
1190
1167
|
vctx.logger
|
|
@@ -1201,7 +1178,7 @@ export const promptChatSection = {
|
|
|
1201
1178
|
outerTid: req.outerTid,
|
|
1202
1179
|
chatId: req.chatId,
|
|
1203
1180
|
budget: wake.budget,
|
|
1204
|
-
note: renderAgentWakeNote(landingOutcome
|
|
1181
|
+
note: renderAgentWakeNote(landingOutcome),
|
|
1205
1182
|
handle: (wakeCtx) => promptChatSection.handle(promptDispatchContext(ctx, wakeCtx.validated)),
|
|
1206
1183
|
});
|
|
1207
1184
|
}
|
|
@@ -1212,7 +1189,6 @@ export const promptChatSection = {
|
|
|
1212
1189
|
chatId: req.chatId,
|
|
1213
1190
|
promptId,
|
|
1214
1191
|
skip: wake.skip,
|
|
1215
|
-
agentLane,
|
|
1216
1192
|
agentDispatched: agentDispatchedBuild,
|
|
1217
1193
|
movedFilesystem: movesFilesystem,
|
|
1218
1194
|
budget: agentWakeBudget,
|