@bastani/atomic 0.9.38-alpha.9 → 0.9.39-alpha.1
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/CHANGELOG.md +119 -0
- package/dist/builtin/intercom/CHANGELOG.md +16 -0
- package/dist/builtin/intercom/index.bundle.mjs +216 -2
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +16 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +16 -1
- package/dist/builtin/web-access/CHANGELOG.md +7 -0
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +74 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/durable/journal/resolution.d.ts +2 -15
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +532 -64
- package/dist/builtin/workflows/src/index.js +301 -27
- package/dist/cli.js +13 -6
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +4 -1
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +1 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +57 -15
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +1 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +2 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +13 -10
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +2 -0
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/context-types.d.ts +5 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/loader-api.d.ts.map +1 -1
- package/dist/core/extensions/loader-api.js +4 -0
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +1 -0
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +1 -0
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.js.map +1 -1
- package/dist/core/queued-input-admission.d.ts +20 -0
- package/dist/core/queued-input-admission.d.ts.map +1 -0
- package/dist/core/queued-input-admission.js +55 -0
- package/dist/core/queued-input-admission.js.map +1 -0
- package/dist/core/sdk-types.d.ts +7 -1
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.js +1 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +1 -0
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +12 -0
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/storage/provider.d.ts +14 -0
- package/dist/core/storage/provider.d.ts.map +1 -1
- package/dist/core/storage/provider.js.map +1 -1
- package/dist/core/storage/session/legacy-session-store.d.ts +4 -1
- package/dist/core/storage/session/legacy-session-store.d.ts.map +1 -1
- package/dist/core/storage/session/legacy-session-store.js +42 -2
- package/dist/core/storage/session/legacy-session-store.js.map +1 -1
- package/dist/core/storage/session/legacy-session-summary.d.ts +8 -0
- package/dist/core/storage/session/legacy-session-summary.d.ts.map +1 -1
- package/dist/core/storage/session/legacy-session-summary.js +42 -2
- package/dist/core/storage/session/legacy-session-summary.js.map +1 -1
- package/dist/extensions/mcp/client/transports/streamable-http.js +9 -8
- package/dist/extensions/mcp/client/transports/streamable-http.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts +4 -0
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.js +104 -30
- package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.js +1 -0
- package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.d.ts +4 -0
- package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.js +4 -0
- package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +4 -3
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +8 -2
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +4 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +4 -0
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js +8 -2
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
- package/dist/modes/interactive/interactive-queueing.js +94 -73
- package/dist/modes/interactive/interactive-queueing.js.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.js +1 -0
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/create-isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/create-isolated-runtime.js +2 -0
- package/dist/modes/interactive-engine/create-isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/engine-heap.d.ts +24 -0
- package/dist/modes/interactive-engine/engine-heap.d.ts.map +1 -0
- package/dist/modes/interactive-engine/engine-heap.js +88 -0
- package/dist/modes/interactive-engine/engine-heap.js.map +1 -0
- package/dist/modes/rpc/rpc-client-api.d.ts +1 -0
- package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-api.js +3 -0
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +7 -0
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +9 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/heap-relaunch.d.ts +14 -0
- package/dist/utils/heap-relaunch.d.ts.map +1 -0
- package/dist/utils/heap-relaunch.js +59 -0
- package/dist/utils/heap-relaunch.js.map +1 -0
- package/docs/environment-variables.md +2 -1
- package/docs/intercom/reference.md +1 -1
- package/docs/rpc/protocol.md +23 -0
- package/docs/sdk/web-server.md +1 -1
- package/docs/sdk.md +10 -1
- package/docs/session-format.md +1 -0
- package/docs/sessions.md +2 -0
- package/docs/settings.md +1 -1
- package/docs/usage.md +2 -0
- package/docs/workflows/api-reference.md +1 -1
- package/docs/workflows/operations.md +5 -1
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -41098,9 +41098,9 @@ function createStageControlRegistry() {
|
|
|
41098
41098
|
const _byRun = new Map;
|
|
41099
41099
|
const pendingDisposals = new Set;
|
|
41100
41100
|
const sessionStores = new Map;
|
|
41101
|
+
const releaseListeners = new Set;
|
|
41101
41102
|
let generation = 0;
|
|
41102
|
-
function rememberSessionStore(handle) {
|
|
41103
|
-
const store = handle.sessionStore;
|
|
41103
|
+
function rememberSessionStore(handle, store = handle.sessionStore) {
|
|
41104
41104
|
if (store === undefined)
|
|
41105
41105
|
return;
|
|
41106
41106
|
let stores = sessionStores.get(handle.runId);
|
|
@@ -41149,6 +41149,35 @@ function createStageControlRegistry() {
|
|
|
41149
41149
|
function disposeEntryInBackground(entry, message) {
|
|
41150
41150
|
disposeEntry(entry).catch((err) => console.warn(message, err));
|
|
41151
41151
|
}
|
|
41152
|
+
async function releaseIdleEntry(runId, stageId, entry) {
|
|
41153
|
+
const gate = entry.handle.releaseGate;
|
|
41154
|
+
if (gate === undefined || entry.disposal !== undefined)
|
|
41155
|
+
return;
|
|
41156
|
+
const epoch = entry.epoch;
|
|
41157
|
+
const savedIn = await gate.savedForReopen();
|
|
41158
|
+
if (savedIn === undefined)
|
|
41159
|
+
return;
|
|
41160
|
+
const runMap = _byRun.get(runId);
|
|
41161
|
+
if (runMap?.get(stageId) !== entry || entry.epoch !== epoch || entry.leases.size > 0)
|
|
41162
|
+
return;
|
|
41163
|
+
if (entry.disposal !== undefined || !gate.idle())
|
|
41164
|
+
return;
|
|
41165
|
+
const { stageName, sessionId } = entry.handle;
|
|
41166
|
+
rememberSessionStore(entry.handle, savedIn);
|
|
41167
|
+
runMap.delete(stageId);
|
|
41168
|
+
if (runMap.size === 0)
|
|
41169
|
+
_byRun.delete(runId);
|
|
41170
|
+
await disposeEntry(entry);
|
|
41171
|
+
if (sessionId === undefined)
|
|
41172
|
+
return;
|
|
41173
|
+
for (const listener of [...releaseListeners]) {
|
|
41174
|
+
try {
|
|
41175
|
+
listener({ runId, stageId, stageName, sessionId });
|
|
41176
|
+
} catch (error) {
|
|
41177
|
+
console.warn("atomic-workflows: released stage listener failed", error);
|
|
41178
|
+
}
|
|
41179
|
+
}
|
|
41180
|
+
}
|
|
41152
41181
|
function makeRunHandle(runId) {
|
|
41153
41182
|
return {
|
|
41154
41183
|
runId,
|
|
@@ -41208,7 +41237,8 @@ function createStageControlRegistry() {
|
|
|
41208
41237
|
handle,
|
|
41209
41238
|
controlsDependencies: true,
|
|
41210
41239
|
permanent: true,
|
|
41211
|
-
leases: new Set
|
|
41240
|
+
leases: new Set,
|
|
41241
|
+
epoch: 0
|
|
41212
41242
|
});
|
|
41213
41243
|
if (displaced !== undefined && displaced.handle !== handle && !displaced.permanent) {
|
|
41214
41244
|
disposeEntryInBackground(displaced, "atomic-workflows: displaced provisional stage handle dispose failed");
|
|
@@ -41230,6 +41260,7 @@ function createStageControlRegistry() {
|
|
|
41230
41260
|
const existing = runMap.get(stageId);
|
|
41231
41261
|
if (existing !== undefined && existing.handle.isDisposed !== true) {
|
|
41232
41262
|
existing.permanent = true;
|
|
41263
|
+
existing.epoch += 1;
|
|
41233
41264
|
return existing.handle;
|
|
41234
41265
|
}
|
|
41235
41266
|
if (existing !== undefined) {
|
|
@@ -41241,7 +41272,8 @@ function createStageControlRegistry() {
|
|
|
41241
41272
|
handle,
|
|
41242
41273
|
controlsDependencies: false,
|
|
41243
41274
|
permanent: true,
|
|
41244
|
-
leases: new Set
|
|
41275
|
+
leases: new Set,
|
|
41276
|
+
epoch: 0
|
|
41245
41277
|
});
|
|
41246
41278
|
return handle;
|
|
41247
41279
|
},
|
|
@@ -41258,11 +41290,13 @@ function createStageControlRegistry() {
|
|
|
41258
41290
|
handle: create(),
|
|
41259
41291
|
controlsDependencies: false,
|
|
41260
41292
|
permanent: false,
|
|
41261
|
-
leases: new Set
|
|
41293
|
+
leases: new Set,
|
|
41294
|
+
epoch: 0
|
|
41262
41295
|
};
|
|
41263
41296
|
runMap.set(stageId, entry);
|
|
41264
41297
|
}
|
|
41265
41298
|
const leasedEntry = entry;
|
|
41299
|
+
leasedEntry.epoch += 1;
|
|
41266
41300
|
const token = Symbol("detached-stage-handle-lease");
|
|
41267
41301
|
leasedEntry.leases.add(token);
|
|
41268
41302
|
let settled = false;
|
|
@@ -41315,8 +41349,10 @@ function createStageControlRegistry() {
|
|
|
41315
41349
|
},
|
|
41316
41350
|
claim(runId, stageId) {
|
|
41317
41351
|
const entry = _byRun.get(runId)?.get(stageId);
|
|
41318
|
-
if (entry !== undefined)
|
|
41352
|
+
if (entry !== undefined) {
|
|
41319
41353
|
entry.permanent = true;
|
|
41354
|
+
entry.epoch += 1;
|
|
41355
|
+
}
|
|
41320
41356
|
return entry?.handle;
|
|
41321
41357
|
},
|
|
41322
41358
|
get(runId, stageId) {
|
|
@@ -41366,6 +41402,21 @@ function createStageControlRegistry() {
|
|
|
41366
41402
|
_byRun.delete(runId);
|
|
41367
41403
|
}
|
|
41368
41404
|
await disposeEntries(entries);
|
|
41405
|
+
},
|
|
41406
|
+
async releaseIdle(runId) {
|
|
41407
|
+
for (const [stageId, entry] of [..._byRun.get(runId) ?? []]) {
|
|
41408
|
+
try {
|
|
41409
|
+
await releaseIdleEntry(runId, stageId, entry);
|
|
41410
|
+
} catch (error) {
|
|
41411
|
+
console.warn("atomic-workflows: completed stage session release failed", error);
|
|
41412
|
+
}
|
|
41413
|
+
}
|
|
41414
|
+
},
|
|
41415
|
+
onStageReleased(listener) {
|
|
41416
|
+
releaseListeners.add(listener);
|
|
41417
|
+
return () => {
|
|
41418
|
+
releaseListeners.delete(listener);
|
|
41419
|
+
};
|
|
41369
41420
|
}
|
|
41370
41421
|
};
|
|
41371
41422
|
}
|
|
@@ -45060,6 +45111,21 @@ function getDurableBackendProcessOwner() {
|
|
|
45060
45111
|
bag[DURABLE_BACKEND_PROCESS_OWNER_KEY] = created;
|
|
45061
45112
|
return created;
|
|
45062
45113
|
}
|
|
45114
|
+
async function releaseDurableBackendsHeldBy(holder) {
|
|
45115
|
+
const selected = getDurableBackendProcessOwner().selectedBackends;
|
|
45116
|
+
if (selected === undefined)
|
|
45117
|
+
return;
|
|
45118
|
+
const released = [];
|
|
45119
|
+
for (const [key, entry] of selected) {
|
|
45120
|
+
if (!entry.holders.delete(holder) || entry.holders.size > 0 || entry.pinned)
|
|
45121
|
+
continue;
|
|
45122
|
+
selected.delete(key);
|
|
45123
|
+
released.push(entry);
|
|
45124
|
+
}
|
|
45125
|
+
await Promise.all(released.map((entry) => entry.ready.then(() => entry.close?.(), () => {
|
|
45126
|
+
return;
|
|
45127
|
+
})));
|
|
45128
|
+
}
|
|
45063
45129
|
|
|
45064
45130
|
// dist/builtin/workflows/src/durable/journal/types.ts
|
|
45065
45131
|
import { StorageSchemaVersionError } from "@bastani/atomic/storage";
|
|
@@ -51294,27 +51360,66 @@ function enqueueTargetTurn(queues, key, deliver) {
|
|
|
51294
51360
|
return current;
|
|
51295
51361
|
}
|
|
51296
51362
|
async function deliverAsPostMortemTurn(event, resolveHandle, assertActive) {
|
|
51363
|
+
const handle = await reopenCompletedStage(event.workflowRunId, event.workflowStageId, resolveHandle, assertActive);
|
|
51364
|
+
for (const message of event.messages) {
|
|
51365
|
+
assertActive();
|
|
51366
|
+
if (handle.isStreaming)
|
|
51367
|
+
await handle.followUp(message.content);
|
|
51368
|
+
else
|
|
51369
|
+
await handle.prompt(message.content);
|
|
51370
|
+
}
|
|
51371
|
+
}
|
|
51372
|
+
async function reopenCompletedStage(runId, stageId, resolveHandle, assertActive) {
|
|
51297
51373
|
assertActive();
|
|
51298
|
-
const resolution = await resolveHandle(
|
|
51374
|
+
const resolution = await resolveHandle(runId, stageId);
|
|
51299
51375
|
assertActive();
|
|
51300
51376
|
if (resolution === undefined) {
|
|
51301
|
-
throw new Error(`Intercom ask target is unavailable: completed workflow stage ${
|
|
51377
|
+
throw new Error(`Intercom ask target is unavailable: completed workflow stage ${runId}/${stageId} was deleted or is no longer retained.`);
|
|
51302
51378
|
}
|
|
51303
51379
|
if (!resolution.ok) {
|
|
51304
|
-
throw new Error(unavailableReason(
|
|
51380
|
+
throw new Error(unavailableReason(runId, stageId, resolution.reason));
|
|
51305
51381
|
}
|
|
51306
51382
|
const handle = resolution.handle;
|
|
51307
51383
|
if (handle.status !== "completed" || handle.isDisposed === true) {
|
|
51308
|
-
throw new Error(`Intercom ask target is not resumable: workflow stage ${
|
|
51384
|
+
throw new Error(`Intercom ask target is not resumable: workflow stage ${runId}/${stageId} has no retained completed conversation.`);
|
|
51309
51385
|
}
|
|
51310
51386
|
await attachWithTimeout(handle);
|
|
51311
|
-
|
|
51312
|
-
|
|
51313
|
-
|
|
51314
|
-
|
|
51315
|
-
|
|
51316
|
-
|
|
51387
|
+
return handle;
|
|
51388
|
+
}
|
|
51389
|
+
function assistantMessageText(message) {
|
|
51390
|
+
if (message.role !== "assistant")
|
|
51391
|
+
return;
|
|
51392
|
+
let text = "";
|
|
51393
|
+
for (const block of message.content)
|
|
51394
|
+
if (block.type === "text")
|
|
51395
|
+
text += block.text;
|
|
51396
|
+
return text.trim().length > 0 ? text.trim() : undefined;
|
|
51397
|
+
}
|
|
51398
|
+
async function collectTurnReply(handle, content) {
|
|
51399
|
+
let reply;
|
|
51400
|
+
const unsubscribe = handle.subscribe((event) => {
|
|
51401
|
+
if (event.type !== "message_end")
|
|
51402
|
+
return;
|
|
51403
|
+
reply = assistantMessageText(event.message) ?? reply;
|
|
51404
|
+
});
|
|
51405
|
+
try {
|
|
51406
|
+
await handle.prompt(content);
|
|
51407
|
+
} finally {
|
|
51408
|
+
unsubscribe();
|
|
51317
51409
|
}
|
|
51410
|
+
return reply;
|
|
51411
|
+
}
|
|
51412
|
+
function createCompletedStageAnswerer(resolveHandle, assertActive = () => {}) {
|
|
51413
|
+
const queues = new Map;
|
|
51414
|
+
return (runId, stageId, content) => enqueueTargetTurn(queues, `${runId}:${stageId}`, async () => {
|
|
51415
|
+
const handle = await reopenCompletedStage(runId, stageId, resolveHandle, assertActive);
|
|
51416
|
+
if (handle.isStreaming) {
|
|
51417
|
+
throw new Error(`Completed workflow stage ${runId}/${stageId} is busy with another turn; ask again when it is idle.`);
|
|
51418
|
+
}
|
|
51419
|
+
const reply = await collectTurnReply(handle, content);
|
|
51420
|
+
assertActive();
|
|
51421
|
+
return reply ?? `Completed workflow stage ${runId}/${stageId} reopened but produced no text answer.`;
|
|
51422
|
+
});
|
|
51318
51423
|
}
|
|
51319
51424
|
async function attachWithTimeout(handle) {
|
|
51320
51425
|
let timeout;
|
|
@@ -58227,6 +58332,20 @@ class MemoryRunJournal {
|
|
|
58227
58332
|
|
|
58228
58333
|
// dist/builtin/workflows/src/durable/journal/journal-backend.ts
|
|
58229
58334
|
var PROCESS_HOLDER_ID = randomUUID4();
|
|
58335
|
+
var processExitCleanups = new Set;
|
|
58336
|
+
function runProcessExitCleanups() {
|
|
58337
|
+
for (const cleanup of processExitCleanups)
|
|
58338
|
+
cleanup();
|
|
58339
|
+
}
|
|
58340
|
+
function addProcessExitCleanup(cleanup) {
|
|
58341
|
+
if (processExitCleanups.size === 0)
|
|
58342
|
+
process.once("exit", runProcessExitCleanups);
|
|
58343
|
+
processExitCleanups.add(cleanup);
|
|
58344
|
+
}
|
|
58345
|
+
function removeProcessExitCleanup(cleanup) {
|
|
58346
|
+
if (processExitCleanups.delete(cleanup) && processExitCleanups.size === 0)
|
|
58347
|
+
process.off("exit", runProcessExitCleanups);
|
|
58348
|
+
}
|
|
58230
58349
|
function* invoke(action) {
|
|
58231
58350
|
try {
|
|
58232
58351
|
const result = action();
|
|
@@ -58853,7 +58972,7 @@ class JournalDurableBackend {
|
|
|
58853
58972
|
process.exitCode = 1;
|
|
58854
58973
|
});
|
|
58855
58974
|
};
|
|
58856
|
-
|
|
58975
|
+
addProcessExitCleanup(this.processExitCleanup);
|
|
58857
58976
|
}
|
|
58858
58977
|
async withWorkflowLease(runId, action) {
|
|
58859
58978
|
this.ensureOpen();
|
|
@@ -58921,7 +59040,7 @@ class JournalDurableBackend {
|
|
|
58921
59040
|
return this.closing;
|
|
58922
59041
|
this.state = "closing";
|
|
58923
59042
|
if (this.processExitCleanup !== undefined) {
|
|
58924
|
-
|
|
59043
|
+
removeProcessExitCleanup(this.processExitCleanup);
|
|
58925
59044
|
this.processExitCleanup = undefined;
|
|
58926
59045
|
}
|
|
58927
59046
|
if (this.timer !== undefined)
|
|
@@ -59462,28 +59581,33 @@ async function initializeDurableBackend(options = {}) {
|
|
|
59462
59581
|
projectTrusted: options.projectTrusted
|
|
59463
59582
|
}).getSettings() : undefined
|
|
59464
59583
|
});
|
|
59465
|
-
const
|
|
59584
|
+
const holder = options.holder;
|
|
59585
|
+
const key = "createRun" in selection ? selection : selection.kind === "memory" && choice !== undefined ? choice : selection.kind === "memory" && holder !== undefined ? holder : storageSelectionKey(selection, getAgentDir3());
|
|
59466
59586
|
const ownsJournal = choice === undefined || !("createRun" in choice);
|
|
59467
59587
|
owner.selectedBackends ??= new Map;
|
|
59468
59588
|
const selected = owner.selectedBackends;
|
|
59469
59589
|
const existing = selected.get(key);
|
|
59470
|
-
|
|
59471
|
-
|
|
59472
|
-
ready = existing.ready;
|
|
59473
|
-
} else {
|
|
59474
|
-
ready = openSelectedRunJournal(selection).then((journal) => JournalDurableBackend.open(journal, { ownsJournal })).then((opened) => {
|
|
59590
|
+
const entry = existing ?? {
|
|
59591
|
+
ready: openSelectedRunJournal(selection).then((journal) => JournalDurableBackend.open(journal, { ownsJournal })).then((opened) => {
|
|
59475
59592
|
if (ownsJournal)
|
|
59476
59593
|
opened.closeOnProcessExit();
|
|
59477
59594
|
entry.close = () => opened.close();
|
|
59478
59595
|
return opened;
|
|
59479
59596
|
}).catch((error) => {
|
|
59480
|
-
selected.
|
|
59597
|
+
if (selected.get(key) === entry)
|
|
59598
|
+
selected.delete(key);
|
|
59481
59599
|
throw error;
|
|
59482
|
-
})
|
|
59483
|
-
|
|
59600
|
+
}),
|
|
59601
|
+
holders: new Set,
|
|
59602
|
+
pinned: false
|
|
59603
|
+
};
|
|
59604
|
+
if (existing === undefined)
|
|
59484
59605
|
selected.set(key, entry);
|
|
59485
|
-
|
|
59486
|
-
|
|
59606
|
+
if (holder === undefined)
|
|
59607
|
+
entry.pinned = true;
|
|
59608
|
+
else
|
|
59609
|
+
entry.holders.add(holder);
|
|
59610
|
+
return withRunJournalConfigSource(selection, () => entry.ready);
|
|
59487
59611
|
}
|
|
59488
59612
|
|
|
59489
59613
|
// dist/builtin/workflows/src/shared/workflow-request-timeout.ts
|
|
@@ -60830,6 +60954,45 @@ function createDurableChildWorkflowPrimitive(input) {
|
|
|
60830
60954
|
};
|
|
60831
60955
|
}
|
|
60832
60956
|
|
|
60957
|
+
// dist/builtin/workflows/src/durable/run-result.ts
|
|
60958
|
+
var RUN_RESULT_CHECKPOINT_NAME = "workflow-run-result";
|
|
60959
|
+
var RUN_RESULT_CHECKPOINT_ID_PREFIX = "run-result:";
|
|
60960
|
+
function isOutputValues(value2) {
|
|
60961
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
60962
|
+
}
|
|
60963
|
+
function durableRunResult(backend, workflowId) {
|
|
60964
|
+
const output = backend.getToolOutput(workflowId, RUN_RESULT_CHECKPOINT_NAME);
|
|
60965
|
+
if (!isOutputValues(output))
|
|
60966
|
+
return;
|
|
60967
|
+
const result = output.result;
|
|
60968
|
+
return isOutputValues(result) ? result : undefined;
|
|
60969
|
+
}
|
|
60970
|
+
async function recordRunResultCheckpointAsync(backend, run) {
|
|
60971
|
+
const result = run.result;
|
|
60972
|
+
const hasResult = result !== undefined && Object.keys(result).length > 0;
|
|
60973
|
+
const recorded = backend.getToolCheckpoint(run.id, RUN_RESULT_CHECKPOINT_NAME);
|
|
60974
|
+
if (!hasResult && recorded === undefined)
|
|
60975
|
+
return false;
|
|
60976
|
+
if (backend.listCheckpoints(run.id).length === 0)
|
|
60977
|
+
return false;
|
|
60978
|
+
const output = hasResult ? { result } : {};
|
|
60979
|
+
if (recorded !== undefined && durableHash(recorded.output) === durableHash(output))
|
|
60980
|
+
return false;
|
|
60981
|
+
const previousSequence = Number(recorded?.checkpointId.slice(RUN_RESULT_CHECKPOINT_ID_PREFIX.length));
|
|
60982
|
+
const sequence = Number.isSafeInteger(previousSequence) ? previousSequence + 1 : 1;
|
|
60983
|
+
const completedAt = Math.max(Date.now(), recorded?.completedAt ?? 0);
|
|
60984
|
+
await backend.commitCheckpoint({
|
|
60985
|
+
kind: "tool",
|
|
60986
|
+
workflowId: run.id,
|
|
60987
|
+
checkpointId: `${RUN_RESULT_CHECKPOINT_ID_PREFIX}${sequence}`,
|
|
60988
|
+
name: RUN_RESULT_CHECKPOINT_NAME,
|
|
60989
|
+
argsHash: RUN_RESULT_CHECKPOINT_NAME,
|
|
60990
|
+
output,
|
|
60991
|
+
completedAt
|
|
60992
|
+
});
|
|
60993
|
+
return true;
|
|
60994
|
+
}
|
|
60995
|
+
|
|
60833
60996
|
// dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts
|
|
60834
60997
|
import { isAbsolute as isAbsolute9, join as join10, resolve as resolve10 } from "node:path";
|
|
60835
60998
|
import { CONFIG_DIR_NAME as CONFIG_DIR_NAME2 } from "@bastani/atomic";
|
|
@@ -66424,6 +66587,12 @@ async function finalizeDurableTerminalStatus(input) {
|
|
|
66424
66587
|
return;
|
|
66425
66588
|
const durableStatus = toDurableStatus(status);
|
|
66426
66589
|
if (durableStatus !== undefined) {
|
|
66590
|
+
try {
|
|
66591
|
+
await recordRunResultCheckpointAsync(input.durableBackend, input.runSnapshot);
|
|
66592
|
+
} catch (error) {
|
|
66593
|
+
if (input.runSnapshot.result !== undefined)
|
|
66594
|
+
throw error;
|
|
66595
|
+
}
|
|
66427
66596
|
if (durableStatus === "failed" || durableStatus === "blocked") {
|
|
66428
66597
|
await recordRunTimingCheckpointAsync(input.durableBackend, input.runSnapshot);
|
|
66429
66598
|
}
|
|
@@ -67646,6 +67815,7 @@ function createTrackedStageCaller(input) {
|
|
|
67646
67815
|
throw err;
|
|
67647
67816
|
}
|
|
67648
67817
|
const trackStageLifecycle = !runtime.state.stageFinalized;
|
|
67818
|
+
runtime.state.sessionCheckpointed = false;
|
|
67649
67819
|
let applyTerminalStageState;
|
|
67650
67820
|
let terminalStateIsSuccess = false;
|
|
67651
67821
|
let stageResultBeforeBudget;
|
|
@@ -67916,6 +68086,7 @@ function createTrackedStageCaller(input) {
|
|
|
67916
68086
|
} else if (runtime.state.stageClosedByWorkflowExit || runtime.exit.currentWorkflowExitAbortReason() !== undefined) {
|
|
67917
68087
|
await runtime.releaseLiveHandle().catch(() => {});
|
|
67918
68088
|
}
|
|
68089
|
+
runtime.state.sessionCheckpointed = finalizationError === undefined;
|
|
67919
68090
|
input.limiter.release();
|
|
67920
68091
|
if (finalizationError !== undefined)
|
|
67921
68092
|
throwFinalizationError(finalizationError.error);
|
|
@@ -68147,7 +68318,29 @@ function createStageControlHandle(runtime) {
|
|
|
68147
68318
|
toolExecutions.record(event);
|
|
68148
68319
|
queuedUserMessages.record(event);
|
|
68149
68320
|
});
|
|
68150
|
-
|
|
68321
|
+
let externalSubscribers = 0;
|
|
68322
|
+
const countSubscription = (unsubscribe) => {
|
|
68323
|
+
externalSubscribers += 1;
|
|
68324
|
+
let active = true;
|
|
68325
|
+
return () => {
|
|
68326
|
+
if (!active)
|
|
68327
|
+
return;
|
|
68328
|
+
active = false;
|
|
68329
|
+
externalSubscribers -= 1;
|
|
68330
|
+
unsubscribe();
|
|
68331
|
+
};
|
|
68332
|
+
};
|
|
68333
|
+
let activeOperations = 0;
|
|
68334
|
+
const tracked = async (operation) => {
|
|
68335
|
+
activeOperations += 1;
|
|
68336
|
+
try {
|
|
68337
|
+
return await operation();
|
|
68338
|
+
} finally {
|
|
68339
|
+
activeOperations -= 1;
|
|
68340
|
+
}
|
|
68341
|
+
};
|
|
68342
|
+
const sessionSaved = () => runtime.stageSnapshot.status === "completed" && runtime.state.stageFinalized && runtime.state.sessionCheckpointed && !runtime.state.liveHandleReleased && !runtime.state.stageClosedByWorkflowExit;
|
|
68343
|
+
const handle = {
|
|
68151
68344
|
runId: runtime.runId,
|
|
68152
68345
|
stageId: runtime.stageId,
|
|
68153
68346
|
stageName: runtime.name,
|
|
@@ -68318,18 +68511,41 @@ function createStageControlHandle(runtime) {
|
|
|
68318
68511
|
}
|
|
68319
68512
|
},
|
|
68320
68513
|
subscribe(listener) {
|
|
68321
|
-
return runtime.innerCtx.subscribe(listener);
|
|
68514
|
+
return countSubscription(runtime.innerCtx.subscribe(listener));
|
|
68322
68515
|
},
|
|
68323
68516
|
subscribeDeliveryActivity(listener) {
|
|
68324
|
-
return runtime.innerCtx.__subscribeDeliveryActivity(listener);
|
|
68517
|
+
return countSubscription(runtime.innerCtx.__subscribeDeliveryActivity(listener));
|
|
68325
68518
|
},
|
|
68326
68519
|
async dispose() {
|
|
68327
68520
|
unsubscribeStageEvents();
|
|
68328
68521
|
toolExecutions.clear();
|
|
68329
68522
|
queuedUserMessages.clear();
|
|
68330
68523
|
await runtime.releaseLiveHandle();
|
|
68524
|
+
},
|
|
68525
|
+
releaseGate: {
|
|
68526
|
+
async savedForReopen() {
|
|
68527
|
+
if (!sessionSaved())
|
|
68528
|
+
return;
|
|
68529
|
+
const store = runtime.innerCtx.__persistedSessionStore();
|
|
68530
|
+
const sessionId = runtime.innerCtx.__sessionMeta().sessionId ?? runtime.stageSnapshot.sessionId;
|
|
68531
|
+
if (store === undefined || sessionId === undefined)
|
|
68532
|
+
return;
|
|
68533
|
+
return await isReopenableSession(store, sessionId) ? store : undefined;
|
|
68534
|
+
},
|
|
68535
|
+
idle() {
|
|
68536
|
+
return sessionSaved() && externalSubscribers === 0 && activeOperations === 0 && stageQueuedUserMessageCount(queuedUserMessages.snapshot()) === 0 && !runtime.state.waitingForStageChatTurn && runtime.state.wakeWaitingForStageChatTurn === undefined && runtime.state.readinessController === undefined && runtime.state.resumeContinuationPending === false && runtime.innerCtx.__idleForRelease();
|
|
68537
|
+
}
|
|
68331
68538
|
}
|
|
68332
68539
|
};
|
|
68540
|
+
const { ensureAttached, sendUserMessage, prompt, steer, followUp, pause, resume } = handle;
|
|
68541
|
+
handle.ensureAttached = () => tracked(ensureAttached);
|
|
68542
|
+
handle.sendUserMessage = (text, options, beforeDelivery) => tracked(() => sendUserMessage(text, options, beforeDelivery));
|
|
68543
|
+
handle.prompt = (text) => tracked(() => prompt(text));
|
|
68544
|
+
handle.steer = (text) => tracked(() => steer(text));
|
|
68545
|
+
handle.followUp = (text) => tracked(() => followUp(text));
|
|
68546
|
+
handle.pause = () => tracked(pause);
|
|
68547
|
+
handle.resume = (message, beforeResume) => tracked(() => resume(message, beforeResume));
|
|
68548
|
+
return handle;
|
|
68333
68549
|
}
|
|
68334
68550
|
|
|
68335
68551
|
// dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts
|
|
@@ -68453,6 +68669,10 @@ function createReplayStageContext(input) {
|
|
|
68453
68669
|
return;
|
|
68454
68670
|
},
|
|
68455
68671
|
__pendingMessageCount: () => 0,
|
|
68672
|
+
__persistedSessionStore: () => {
|
|
68673
|
+
return;
|
|
68674
|
+
},
|
|
68675
|
+
__idleForRelease: () => false,
|
|
68456
68676
|
__modelFallbackMeta: () => ({
|
|
68457
68677
|
...replaySource.model !== undefined ? { model: replaySource.model } : {},
|
|
68458
68678
|
...replaySource.thinkingLevel !== undefined ? { thinkingLevel: replaySource.thinkingLevel } : {},
|
|
@@ -69107,6 +69327,9 @@ class StageMessageAdmission {
|
|
|
69107
69327
|
return this.runAdmitted(operation, admission);
|
|
69108
69328
|
return admission.then((release) => this.runAdmitted(operation, release));
|
|
69109
69329
|
}
|
|
69330
|
+
isBusy() {
|
|
69331
|
+
return this.tail !== undefined || this.starting !== undefined || this.owned !== undefined || this.startedGenerations.length > 0;
|
|
69332
|
+
}
|
|
69110
69333
|
isOwned(session) {
|
|
69111
69334
|
return this.session === session && this.owned?.state === "owned";
|
|
69112
69335
|
}
|
|
@@ -69766,6 +69989,10 @@ function asAgentSession(activeSession) {
|
|
|
69766
69989
|
}
|
|
69767
69990
|
return;
|
|
69768
69991
|
}
|
|
69992
|
+
function isStageSessionQuiescent(session) {
|
|
69993
|
+
const sdk = session;
|
|
69994
|
+
return !session.isStreaming && (session.pendingMessageCount ?? 0) === 0 && session.queuedMessagesPaused !== true && sdk.isCompacting !== true && sdk.isRetrying !== true && sdk.isBashRunning !== true && sdk.hasPendingBashMessages !== true;
|
|
69995
|
+
}
|
|
69769
69996
|
function normalizeSessionCreateResult(created) {
|
|
69770
69997
|
if ("session" in created)
|
|
69771
69998
|
return created;
|
|
@@ -70250,6 +70477,7 @@ class StageSessionController {
|
|
|
70250
70477
|
messageAdmission = new StageMessageAdmission;
|
|
70251
70478
|
deliveryActivity = new StageDeliveryActivity;
|
|
70252
70479
|
artifactCapture = new StageArtifactCapture;
|
|
70480
|
+
callerSessionManager;
|
|
70253
70481
|
beginOutputGeneration() {
|
|
70254
70482
|
this.artifactCapture.reset();
|
|
70255
70483
|
}
|
|
@@ -70705,6 +70933,25 @@ class StageSessionController {
|
|
|
70705
70933
|
pendingMessageCount() {
|
|
70706
70934
|
return typeof this.session?.pendingMessageCount === "number" ? this.session.pendingMessageCount : 0;
|
|
70707
70935
|
}
|
|
70936
|
+
persistedSessionStore() {
|
|
70937
|
+
return this.session === undefined ? undefined : this.callerSessionManager?.getSessionStore();
|
|
70938
|
+
}
|
|
70939
|
+
isIdleForRelease() {
|
|
70940
|
+
const session = this.session;
|
|
70941
|
+
if (session === undefined || this.disposed || this.pendingDisposal || this.disposalPromise !== undefined)
|
|
70942
|
+
return false;
|
|
70943
|
+
if (this.activeCreation !== undefined || this.ownedCreationPromise !== undefined)
|
|
70944
|
+
return false;
|
|
70945
|
+
if (this.sessionShutdownPromise !== undefined || this.replacement.retiringSession !== undefined)
|
|
70946
|
+
return false;
|
|
70947
|
+
if (this.pauseControl.isPaused())
|
|
70948
|
+
return false;
|
|
70949
|
+
if (this.thrownErrorRetryStates.size > 0)
|
|
70950
|
+
return false;
|
|
70951
|
+
if (this.messageAdmission.isBusy())
|
|
70952
|
+
return false;
|
|
70953
|
+
return isStageSessionQuiescent(session);
|
|
70954
|
+
}
|
|
70708
70955
|
bindAbortSignal() {
|
|
70709
70956
|
const { signal } = this.opts;
|
|
70710
70957
|
if (!signal)
|
|
@@ -71259,7 +71506,10 @@ class StageSessionController {
|
|
|
71259
71506
|
this.modelRoute?.assertCurrent();
|
|
71260
71507
|
if (this.modelRoute && candidate && (typeof candidate.value === "string" || !this.modelRoute.allowsModel(candidate.value, candidate.reasoningLevel)))
|
|
71261
71508
|
throw new Error("Workflow stage execution candidate is no longer eligible.");
|
|
71262
|
-
|
|
71509
|
+
const adapter = this.opts.adapters.agentSession ?? missingAdapter(consumer);
|
|
71510
|
+
const createOptions = await stripWorkflowOnlyOptions(stageOptions, this.opts.defaultSessionDir, this.meta, this.opts.pendingStageDelivery);
|
|
71511
|
+
this.callerSessionManager = createOptions.sessionManager;
|
|
71512
|
+
created = await adapter.create(createOptions, {
|
|
71263
71513
|
...this.meta,
|
|
71264
71514
|
startupSignal: this.startupWait.signal,
|
|
71265
71515
|
isFallbackAttempt: candidate !== undefined && candidate !== (await this.modelCandidates())[0],
|
|
@@ -71269,7 +71519,7 @@ class StageSessionController {
|
|
|
71269
71519
|
},
|
|
71270
71520
|
stageOptions,
|
|
71271
71521
|
...this.sharedOrchestrationContext !== undefined ? { orchestrationContext: this.sharedOrchestrationContext } : {}
|
|
71272
|
-
})
|
|
71522
|
+
});
|
|
71273
71523
|
} catch (error) {
|
|
71274
71524
|
if (error instanceof StageSessionBindingCleanupFailure) {
|
|
71275
71525
|
this.bindingCleanupFailure = error;
|
|
@@ -72079,6 +72329,12 @@ ${nextPrompt}`;
|
|
|
72079
72329
|
__pendingMessageCount() {
|
|
72080
72330
|
return controller.pendingMessageCount();
|
|
72081
72331
|
},
|
|
72332
|
+
__persistedSessionStore() {
|
|
72333
|
+
return controller.persistedSessionStore();
|
|
72334
|
+
},
|
|
72335
|
+
__idleForRelease() {
|
|
72336
|
+
return controller.isIdleForRelease();
|
|
72337
|
+
},
|
|
72082
72338
|
__modelFallbackMeta() {
|
|
72083
72339
|
return controller.currentModelFallbackMeta();
|
|
72084
72340
|
},
|
|
@@ -72250,6 +72506,7 @@ function createWorkflowStageFactory(input) {
|
|
|
72250
72506
|
liveHandleReleased: false,
|
|
72251
72507
|
stageClosedByWorkflowExit: false,
|
|
72252
72508
|
stageFinalized: false,
|
|
72509
|
+
sessionCheckpointed: false,
|
|
72253
72510
|
skippedForParallelFailFast: false,
|
|
72254
72511
|
stageControlDropped: false
|
|
72255
72512
|
};
|
|
@@ -72647,6 +72904,26 @@ class EngineRuntime {
|
|
|
72647
72904
|
}
|
|
72648
72905
|
}
|
|
72649
72906
|
|
|
72907
|
+
// dist/builtin/workflows/src/engine/session-closed-error.ts
|
|
72908
|
+
import { isStaleExtensionContextError as isStaleExtensionContextError5 } from "@bastani/atomic";
|
|
72909
|
+
var MAX_CAUSE_DEPTH = 8;
|
|
72910
|
+
function reportsClosedSession(error) {
|
|
72911
|
+
return "code" in error && error.code === "SessionClosed" || isStaleExtensionContextError5(error);
|
|
72912
|
+
}
|
|
72913
|
+
function isSessionClosedError(error) {
|
|
72914
|
+
let current = error;
|
|
72915
|
+
for (let depth = 0;depth < MAX_CAUSE_DEPTH && current !== undefined; depth++) {
|
|
72916
|
+
try {
|
|
72917
|
+
if (reportsClosedSession(current))
|
|
72918
|
+
return true;
|
|
72919
|
+
current = current.cause instanceof Error ? current.cause : undefined;
|
|
72920
|
+
} catch {
|
|
72921
|
+
return false;
|
|
72922
|
+
}
|
|
72923
|
+
}
|
|
72924
|
+
return false;
|
|
72925
|
+
}
|
|
72926
|
+
|
|
72650
72927
|
// dist/builtin/workflows/src/engine/workflow-activity.ts
|
|
72651
72928
|
import { runCallback as runCallback4 } from "@bastani/atomic";
|
|
72652
72929
|
function nextEventLoopTurn() {
|
|
@@ -73073,6 +73350,27 @@ async function executeRun(def, resolvedInputs, opts) {
|
|
|
73073
73350
|
toolNodes: [...runSnapshot.toolNodes]
|
|
73074
73351
|
};
|
|
73075
73352
|
};
|
|
73353
|
+
const suspendForClosedSession = async (reason) => {
|
|
73354
|
+
abandonInFlightAsCancelled(reason);
|
|
73355
|
+
const durable = durableBackend.getWorkflow(runId);
|
|
73356
|
+
let resumable;
|
|
73357
|
+
if (durable?.status === "running") {
|
|
73358
|
+
resumable = isDurableWorkflowResumable({ ...durable, status: "paused", resumable: true });
|
|
73359
|
+
await transitionDurableWorkflowStatus(durableBackend, runId, ["running"], "paused", undefined, resumable);
|
|
73360
|
+
await recordRunTimingCheckpointAsync(durableBackend, runSnapshot);
|
|
73361
|
+
}
|
|
73362
|
+
activeStore.recordRunPaused(runId, undefined, {
|
|
73363
|
+
exitReason: WORKFLOW_GRACEFUL_QUIT_EXIT_REASON,
|
|
73364
|
+
...resumable === undefined ? {} : { resumable }
|
|
73365
|
+
});
|
|
73366
|
+
return {
|
|
73367
|
+
runId,
|
|
73368
|
+
status: "paused",
|
|
73369
|
+
exitReason: WORKFLOW_GRACEFUL_QUIT_EXIT_REASON,
|
|
73370
|
+
stages: [...runSnapshot.stages],
|
|
73371
|
+
toolNodes: [...runSnapshot.toolNodes]
|
|
73372
|
+
};
|
|
73373
|
+
};
|
|
73076
73374
|
const resolvePromptNodeTopology = createDurableStageTopologyResolver(durableBackend, runId);
|
|
73077
73375
|
const priorPromptStageCheckpoints = durableBackend.listCheckpoints(runId).filter((checkpoint) => checkpoint.kind === "stage");
|
|
73078
73376
|
let promptNodeUi;
|
|
@@ -73435,8 +73733,10 @@ async function executeRun(def, resolvedInputs, opts) {
|
|
|
73435
73733
|
if (returned.status === "completed")
|
|
73436
73734
|
assertFrontierConsumed();
|
|
73437
73735
|
const recorded = activeStore.recordRunEnd(runId, returned.status, result, returned.error, returned.metadata);
|
|
73438
|
-
if (opts.parentRun === undefined)
|
|
73736
|
+
if (opts.parentRun === undefined) {
|
|
73439
73737
|
await recordRunTimingCheckpointAsync(durableBackend, runSnapshot);
|
|
73738
|
+
await recordRunResultCheckpointAsync(durableBackend, runSnapshot);
|
|
73739
|
+
}
|
|
73440
73740
|
await durableBackend.commitWorkflowStatus(runId, returned.status, undefined, returned.metadata?.resumable);
|
|
73441
73741
|
await appendRunEndWhenRecorded(opts.persistence, recorded, {
|
|
73442
73742
|
runId,
|
|
@@ -73464,8 +73764,14 @@ async function executeRun(def, resolvedInputs, opts) {
|
|
|
73464
73764
|
err = selectedTerminalEvent.error;
|
|
73465
73765
|
}
|
|
73466
73766
|
const gracefulQuit = observedQuitCancellation() ?? observedTaskTailQuit ?? findWorkflowGracefulQuit(err) ?? findWorkflowGracefulQuit(ownController.signal.reason);
|
|
73467
|
-
|
|
73767
|
+
const ownerClosing = opts.adapters?.ownerSessionClosing?.() === true;
|
|
73768
|
+
if (gracefulQuit !== undefined) {
|
|
73769
|
+
if (ownerClosing && gracefulQuit.runId !== runId)
|
|
73770
|
+
return await suspendForClosedSession(gracefulQuit);
|
|
73468
73771
|
return suspendForGracefulQuit(gracefulQuit);
|
|
73772
|
+
}
|
|
73773
|
+
if (ownerClosing && err instanceof Error && isSessionClosedError(err))
|
|
73774
|
+
return await suspendForClosedSession(err);
|
|
73469
73775
|
await admittedTools.closeAndDrain();
|
|
73470
73776
|
if (ownController.signal.aborted)
|
|
73471
73777
|
await Promise.allSettled([...pendingChildWorkflows]);
|
|
@@ -73569,6 +73875,8 @@ async function executeRun(def, resolvedInputs, opts) {
|
|
|
73569
73875
|
terminalEvents.dispose();
|
|
73570
73876
|
if (opts.stageControlRegistry === undefined && opts.executionMode !== "interactive" && isTerminalRunStatus(runSnapshot.status) && runSnapshot.resumable !== true) {
|
|
73571
73877
|
await stageRegistry.clear(runId);
|
|
73878
|
+
} else if (isTerminalRunStatus(runSnapshot.status)) {
|
|
73879
|
+
await stageRegistry.releaseIdle(runId);
|
|
73572
73880
|
}
|
|
73573
73881
|
}
|
|
73574
73882
|
}
|
|
@@ -74322,7 +74630,7 @@ async function prepareRuntimeDurableResumable(getBackend, workflowId) {
|
|
|
74322
74630
|
|
|
74323
74631
|
// dist/builtin/workflows/src/durable/completed-catalog.ts
|
|
74324
74632
|
function isReservedRunCheckpointHash(argsHash) {
|
|
74325
|
-
return [RUN_TIMING_CHECKPOINT_NAME, RUN_USAGE_CHECKPOINT_NAME].includes(argsHash) || argsHash === WORKFLOW_HEARTBEAT_ANCHOR_CHECKPOINT_NAME;
|
|
74633
|
+
return [RUN_TIMING_CHECKPOINT_NAME, RUN_USAGE_CHECKPOINT_NAME, RUN_RESULT_CHECKPOINT_NAME].includes(argsHash) || argsHash === WORKFLOW_HEARTBEAT_ANCHOR_CHECKPOINT_NAME;
|
|
74326
74634
|
}
|
|
74327
74635
|
function listCompletedFromBackend(backend) {
|
|
74328
74636
|
return backend.listCompletedWorkflows();
|
|
@@ -74386,6 +74694,7 @@ async function completedWorkflowRunSnapshots(backend, entry, sessionStore) {
|
|
|
74386
74694
|
...handle.failureRecoverability !== undefined ? { failureRecoverability: handle.failureRecoverability } : {},
|
|
74387
74695
|
...handle.failureDisposition !== undefined ? { failureDisposition: handle.failureDisposition } : {},
|
|
74388
74696
|
...handle.failedToolNodeId !== undefined ? { failedToolNodeId: handle.failedToolNodeId } : {},
|
|
74697
|
+
...runResultFields(backend, handle),
|
|
74389
74698
|
resumable: handle.resumable ?? false
|
|
74390
74699
|
};
|
|
74391
74700
|
return [root, ...runs.filter((_, index) => index !== rootIndex)];
|
|
@@ -74428,9 +74737,16 @@ function rootSnapshot(backend, handle, graph) {
|
|
|
74428
74737
|
...handle.failureRecoverability !== undefined ? { failureRecoverability: handle.failureRecoverability } : {},
|
|
74429
74738
|
...handle.failureDisposition !== undefined ? { failureDisposition: handle.failureDisposition } : {},
|
|
74430
74739
|
...handle.failedToolNodeId !== undefined ? { failedToolNodeId: handle.failedToolNodeId } : {},
|
|
74740
|
+
...runResultFields(backend, handle),
|
|
74431
74741
|
resumable: isDurableWorkflowResumable(handle)
|
|
74432
74742
|
};
|
|
74433
74743
|
}
|
|
74744
|
+
function runResultFields(backend, handle) {
|
|
74745
|
+
if (handle.status === "running" || handle.status === "paused")
|
|
74746
|
+
return {};
|
|
74747
|
+
const result = durableRunResult(backend, handle.workflowId);
|
|
74748
|
+
return result === undefined ? {} : { result };
|
|
74749
|
+
}
|
|
74434
74750
|
function durableNestedRunSnapshots(backend, rootWorkflowId) {
|
|
74435
74751
|
const handle = backend.getWorkflow(rootWorkflowId);
|
|
74436
74752
|
if (handle === undefined)
|
|
@@ -74879,6 +75195,7 @@ function createPostMortemStageHandle(runId, stage, sessionId, adapters, cwd, def
|
|
|
74879
75195
|
|
|
74880
75196
|
// dist/builtin/workflows/src/durable/completed-inspection.ts
|
|
74881
75197
|
var completedChatRegistrations = new WeakMap;
|
|
75198
|
+
var completedChatUnregisters = new WeakMap;
|
|
74882
75199
|
async function openCompletedDurableWorkflow(workflowId, deps, catalog) {
|
|
74883
75200
|
const selectedStore = await stageSessionStore({ sessionStore: deps.sessionStore ?? deps.adapters?.sessionStore, cwd: deps.cwd }, deps.defaultSessionDir);
|
|
74884
75201
|
const resolved = await resolveCompletedWorkflow(workflowId, deps.durableBackend, catalog, selectedStore);
|
|
@@ -74924,37 +75241,40 @@ function registerCompletedChatHandles(snapshot, deps, sessionStore) {
|
|
|
74924
75241
|
const registrations = completedChatRegistrations.get(registry) ?? new Map;
|
|
74925
75242
|
completedChatRegistrations.set(registry, registrations);
|
|
74926
75243
|
const desiredKeys = new Set(snapshot.stages.filter((stage) => stage.sessionId !== undefined).map((stage) => completedChatKey(snapshot.id, stage.id)));
|
|
74927
|
-
for (const
|
|
75244
|
+
for (const key of [...registrations.keys()]) {
|
|
74928
75245
|
if (!key.startsWith(`${snapshot.id}:`) || desiredKeys.has(key))
|
|
74929
75246
|
continue;
|
|
74930
|
-
removeCompletedChatRegistration(registrations, key
|
|
75247
|
+
removeCompletedChatRegistration(registrations, key);
|
|
74931
75248
|
}
|
|
74932
75249
|
for (const stage of snapshot.stages) {
|
|
74933
75250
|
if (stage.sessionId === undefined)
|
|
74934
75251
|
continue;
|
|
74935
75252
|
const key = completedChatKey(snapshot.id, stage.id);
|
|
74936
|
-
const registration = registrations.get(key);
|
|
75253
|
+
const registration = registrations.get(key)?.deref();
|
|
74937
75254
|
const existing = registry.claim(snapshot.id, stage.id);
|
|
74938
75255
|
if (existing?.sessionId === stage.sessionId && existing.sessionStore === sessionStore && !existing.isDisposed)
|
|
74939
75256
|
continue;
|
|
74940
75257
|
if (registration !== undefined) {
|
|
74941
|
-
removeCompletedChatRegistration(registrations, key
|
|
75258
|
+
removeCompletedChatRegistration(registrations, key);
|
|
74942
75259
|
} else if (existing !== undefined) {
|
|
74943
75260
|
disposeCompletedChatHandle(existing);
|
|
74944
75261
|
}
|
|
74945
75262
|
const handle = createPostMortemStageHandle(snapshot.id, stage, stage.sessionId, deps.adapters, deps.cwd, deps.defaultSessionDir, sessionStore);
|
|
74946
|
-
|
|
74947
|
-
registrations.set(key,
|
|
75263
|
+
completedChatUnregisters.set(handle, registry.register(handle));
|
|
75264
|
+
registrations.set(key, new WeakRef(handle));
|
|
74948
75265
|
registry.detachControl(snapshot.id, stage.id, handle);
|
|
74949
75266
|
}
|
|
74950
75267
|
}
|
|
74951
75268
|
function completedChatKey(runId, stageId) {
|
|
74952
75269
|
return `${runId}:${stageId}`;
|
|
74953
75270
|
}
|
|
74954
|
-
function removeCompletedChatRegistration(registrations, key
|
|
74955
|
-
|
|
75271
|
+
function removeCompletedChatRegistration(registrations, key) {
|
|
75272
|
+
const handle = registrations.get(key)?.deref();
|
|
74956
75273
|
registrations.delete(key);
|
|
74957
|
-
|
|
75274
|
+
if (handle === undefined)
|
|
75275
|
+
return;
|
|
75276
|
+
completedChatUnregisters.get(handle)?.();
|
|
75277
|
+
disposeCompletedChatHandle(handle);
|
|
74958
75278
|
}
|
|
74959
75279
|
function disposeCompletedChatHandle(handle) {
|
|
74960
75280
|
Promise.resolve(handle.dispose?.()).catch((error) => {
|
|
@@ -75617,10 +75937,14 @@ function registerWorkflowLifecycleHandlers(pi, deps) {
|
|
|
75617
75937
|
return confirmSessionSwitch(reason, ctx);
|
|
75618
75938
|
});
|
|
75619
75939
|
pi.on("session_before_fork", async (_event, ctx) => confirmSessionSwitch("fork", ctx));
|
|
75940
|
+
let notifiedDiscoveryDiagnostics = null;
|
|
75620
75941
|
const notifyDiscoveryDiagnostics = (ctx) => {
|
|
75621
75942
|
if (!ctx?.ui)
|
|
75622
75943
|
return;
|
|
75623
75944
|
const diagnostics = formatStartupDiagnostics(null, runtimeState.discoveryRef.current);
|
|
75945
|
+
if (diagnostics === notifiedDiscoveryDiagnostics)
|
|
75946
|
+
return;
|
|
75947
|
+
notifiedDiscoveryDiagnostics = diagnostics;
|
|
75624
75948
|
if (diagnostics !== null)
|
|
75625
75949
|
ctx.ui.notify?.(diagnostics, "warning");
|
|
75626
75950
|
};
|
|
@@ -75737,6 +76061,7 @@ function registerWorkflowLifecycleHandlers(pi, deps) {
|
|
|
75737
76061
|
if (reason === "startup")
|
|
75738
76062
|
lifetime.startupStarted = true;
|
|
75739
76063
|
startupResourcesDiscovered = false;
|
|
76064
|
+
notifiedDiscoveryDiagnostics = null;
|
|
75740
76065
|
runtimeState.resetWorkflowDiscoveryForSession();
|
|
75741
76066
|
await runtimeState.ensureWorkflowConfigLoaded();
|
|
75742
76067
|
if (stopsWorkflows) {
|
|
@@ -75813,6 +76138,7 @@ function registerWorkflowLifecycleHandlers(pi, deps) {
|
|
|
75813
76138
|
closeGeneration,
|
|
75814
76139
|
...lifetime.generations,
|
|
75815
76140
|
() => releasePausedRunsOfSession(sessionCaller, store),
|
|
76141
|
+
() => releaseDurableBackendsHeldBy(store),
|
|
75816
76142
|
() => {
|
|
75817
76143
|
lifetime.generations.clear();
|
|
75818
76144
|
}
|
|
@@ -82399,7 +82725,7 @@ async function openSqlRunJournal(source = workflowJournalPath(), options = {}) {
|
|
|
82399
82725
|
// dist/builtin/workflows/src/extension/wiring.ts
|
|
82400
82726
|
import { join as join28 } from "node:path";
|
|
82401
82727
|
import {
|
|
82402
|
-
isStaleExtensionContextError as
|
|
82728
|
+
isStaleExtensionContextError as isStaleExtensionContextError6,
|
|
82403
82729
|
ModelRuntime,
|
|
82404
82730
|
resolveRestoredModelReference
|
|
82405
82731
|
} from "@bastani/atomic";
|
|
@@ -82745,7 +83071,7 @@ function emitLateIntercomRoute(pi, meta, messages, options, batch) {
|
|
|
82745
83071
|
try {
|
|
82746
83072
|
pi.events.emit(LATE_STAGE_MESSAGE_EVENT2, event);
|
|
82747
83073
|
} catch (error) {
|
|
82748
|
-
if (!
|
|
83074
|
+
if (!isStaleExtensionContextError6(error))
|
|
82749
83075
|
throw error;
|
|
82750
83076
|
return Promise.reject(error);
|
|
82751
83077
|
}
|
|
@@ -82757,7 +83083,7 @@ function routeThroughStaleContextGuard(route) {
|
|
|
82757
83083
|
try {
|
|
82758
83084
|
return route();
|
|
82759
83085
|
} catch (error) {
|
|
82760
|
-
if (!
|
|
83086
|
+
if (!isStaleExtensionContextError6(error))
|
|
82761
83087
|
throw error;
|
|
82762
83088
|
return Promise.reject(error);
|
|
82763
83089
|
}
|
|
@@ -82975,6 +83301,7 @@ function buildRuntimeAdapters(builtWith, options = {}) {
|
|
|
82975
83301
|
}, options.sdk));
|
|
82976
83302
|
const broker = options.stageUiBroker ?? currentStageUiBroker();
|
|
82977
83303
|
const adapters = {
|
|
83304
|
+
...options.ownerSessionClosing === undefined ? {} : { ownerSessionClosing: options.ownerSessionClosing },
|
|
82978
83305
|
agentSession: {
|
|
82979
83306
|
async create(stageOptions, meta) {
|
|
82980
83307
|
const pi = resolveSurface();
|
|
@@ -84042,8 +84369,10 @@ function createExtensionRuntime(opts = {}) {
|
|
|
84042
84369
|
let ready;
|
|
84043
84370
|
const ensureReady = () => ready ??= (presetBackend === undefined ? initializeDurableBackend({
|
|
84044
84371
|
cwd: runtimeCwd,
|
|
84045
|
-
journal: opts.journal,
|
|
84046
|
-
|
|
84372
|
+
journal: opts.journal ?? opts.resolveJournal?.(),
|
|
84373
|
+
settings: opts.resolveJournalSettings?.(),
|
|
84374
|
+
projectTrusted: opts.isProjectTrusted?.(),
|
|
84375
|
+
holder: activeStore
|
|
84047
84376
|
}) : Promise.resolve(presetBackend)).then((backend) => {
|
|
84048
84377
|
backendRef.current = backend;
|
|
84049
84378
|
bindStoreDurableBackend(activeStore, backend);
|
|
@@ -85052,10 +85381,10 @@ function workflowModelCatalogFromContext(ctx, resolveLiveContext) {
|
|
|
85052
85381
|
}
|
|
85053
85382
|
|
|
85054
85383
|
// dist/builtin/workflows/src/extension/workflow-ports.ts
|
|
85055
|
-
import { isStaleExtensionContextError as
|
|
85384
|
+
import { isStaleExtensionContextError as isStaleExtensionContextError8 } from "@bastani/atomic";
|
|
85056
85385
|
|
|
85057
85386
|
// dist/builtin/workflows/src/extension/mcp.ts
|
|
85058
|
-
import { isStaleExtensionContextError as
|
|
85387
|
+
import { isStaleExtensionContextError as isStaleExtensionContextError7 } from "@bastani/atomic";
|
|
85059
85388
|
function setMcpScope(pi, opts) {
|
|
85060
85389
|
if (!pi.events)
|
|
85061
85390
|
return;
|
|
@@ -85067,7 +85396,7 @@ function setMcpScope(pi, opts) {
|
|
|
85067
85396
|
try {
|
|
85068
85397
|
pi.events.emit("mcp.scope.set", payload);
|
|
85069
85398
|
} catch (error) {
|
|
85070
|
-
if (!
|
|
85399
|
+
if (!isStaleExtensionContextError7(error))
|
|
85071
85400
|
throw error;
|
|
85072
85401
|
}
|
|
85073
85402
|
}
|
|
@@ -85082,7 +85411,7 @@ function clearMcpScope(pi, stageId) {
|
|
|
85082
85411
|
try {
|
|
85083
85412
|
pi.events.emit("mcp.scope.set", payload);
|
|
85084
85413
|
} catch (error) {
|
|
85085
|
-
if (!
|
|
85414
|
+
if (!isStaleExtensionContextError7(error))
|
|
85086
85415
|
throw error;
|
|
85087
85416
|
}
|
|
85088
85417
|
}
|
|
@@ -85092,7 +85421,7 @@ async function unlessStale(append) {
|
|
|
85092
85421
|
try {
|
|
85093
85422
|
return await append();
|
|
85094
85423
|
} catch (error) {
|
|
85095
|
-
if (
|
|
85424
|
+
if (isStaleExtensionContextError8(error))
|
|
85096
85425
|
return;
|
|
85097
85426
|
throw error;
|
|
85098
85427
|
}
|
|
@@ -85243,7 +85572,9 @@ function createWorkflowExtensionRuntimeState(pi, adapters, options = {}) {
|
|
|
85243
85572
|
stageControlRegistry,
|
|
85244
85573
|
toolControlRegistry,
|
|
85245
85574
|
stageUiBroker,
|
|
85246
|
-
isProjectTrusted: () => projectTrusted ?? pi.getResourceLoaderInheritanceSnapshot?.()?.projectTrusted ?? true
|
|
85575
|
+
isProjectTrusted: () => projectTrusted ?? pi.getResourceLoaderInheritanceSnapshot?.()?.projectTrusted ?? true,
|
|
85576
|
+
resolveJournal: () => pi.getWorkflowJournal?.(),
|
|
85577
|
+
resolveJournalSettings: () => pi.getSettings?.()
|
|
85247
85578
|
};
|
|
85248
85579
|
let contextCwd;
|
|
85249
85580
|
const resolveCwd = () => resolveHostCwd?.() ?? contextCwd ?? pi.sessionManager?.getCwd?.() ?? process.cwd();
|
|
@@ -85869,7 +86200,7 @@ function registerPendingStageIntercomBridge(pi, activeStore) {
|
|
|
85869
86200
|
if (!ownedRunIds.has(runId))
|
|
85870
86201
|
routeCompletions.delete(runId);
|
|
85871
86202
|
}
|
|
85872
|
-
sweepPromise = sweepPromise.then(() => settleUndeliverablePendingStageMessages(activeStore, notifyUndeliverable)).then(() => {
|
|
86203
|
+
sweepPromise = sweepPromise.then(() => outsideWorkflowExecutions(() => settleUndeliverablePendingStageMessages(activeStore, notifyUndeliverable))).then(() => {
|
|
85873
86204
|
return;
|
|
85874
86205
|
}).catch((error) => reportWarning(`atomic-workflows: pending stage delivery sweep failed: ${error.message}`));
|
|
85875
86206
|
};
|
|
@@ -86438,6 +86769,48 @@ function createPostMortemHandleResolver(deps) {
|
|
|
86438
86769
|
};
|
|
86439
86770
|
}
|
|
86440
86771
|
|
|
86772
|
+
// dist/builtin/workflows/src/extension/released-stage-intercom-route.ts
|
|
86773
|
+
var RELEASED_STAGE_EVENT = "atomic:workflow-released-stage";
|
|
86774
|
+
function announcementFor(store, released, answer) {
|
|
86775
|
+
const runs = store.runs();
|
|
86776
|
+
const run = runs.find((candidate) => candidate.id === released.runId);
|
|
86777
|
+
const stage = run?.stages.find((candidate) => candidate.id === released.stageId);
|
|
86778
|
+
if (run === undefined || stage?.pendingStageDeliveryAvailable !== true)
|
|
86779
|
+
return;
|
|
86780
|
+
const rootRunId = durableRootRunIdForRun(runs, run.id);
|
|
86781
|
+
if (rootRunId === undefined)
|
|
86782
|
+
return;
|
|
86783
|
+
const stageKeys = [released.stageId, released.stageName].filter((key) => !key.includes("/") && !key.includes("*"));
|
|
86784
|
+
return {
|
|
86785
|
+
runId: released.runId,
|
|
86786
|
+
stageId: released.stageId,
|
|
86787
|
+
stageName: released.stageName,
|
|
86788
|
+
sessionId: released.sessionId,
|
|
86789
|
+
group: stage.intercomGroup ?? workflowInvocationIntercomGroup(rootRunId),
|
|
86790
|
+
...stage.model === undefined ? {} : { model: stage.model },
|
|
86791
|
+
...stageKeys.length === 0 ? {} : { liveRoute: { stageKeys, capability: workflowPendingStageRouteCapability(store, run.id) } },
|
|
86792
|
+
answer
|
|
86793
|
+
};
|
|
86794
|
+
}
|
|
86795
|
+
function registerReleasedStageIntercomRoutes(pi, registry, store, resolveHandle) {
|
|
86796
|
+
let disposed = false;
|
|
86797
|
+
const answerAsCompletedStage = createCompletedStageAnswerer(resolveHandle, () => {
|
|
86798
|
+
if (disposed)
|
|
86799
|
+
throw new Error("Intercom ask target is unavailable: its owning session has closed.");
|
|
86800
|
+
});
|
|
86801
|
+
const unsubscribe = registry.onStageReleased((released) => {
|
|
86802
|
+
if (disposed)
|
|
86803
|
+
return;
|
|
86804
|
+
const announcement = announcementFor(store, released, (content) => answerAsCompletedStage(released.runId, released.stageId, content));
|
|
86805
|
+
if (announcement !== undefined)
|
|
86806
|
+
pi.events?.emit?.(RELEASED_STAGE_EVENT, announcement);
|
|
86807
|
+
});
|
|
86808
|
+
return () => {
|
|
86809
|
+
disposed = true;
|
|
86810
|
+
unsubscribe();
|
|
86811
|
+
};
|
|
86812
|
+
}
|
|
86813
|
+
|
|
86441
86814
|
// dist/builtin/workflows/src/extension/render-component.ts
|
|
86442
86815
|
function dynamicTextRenderComponent(renderText) {
|
|
86443
86816
|
return {
|
|
@@ -88318,6 +88691,60 @@ function createSessionRunControl(host) {
|
|
|
88318
88691
|
// dist/builtin/workflows/src/extension/workflow-tool.ts
|
|
88319
88692
|
import { getSupportedThinkingLevels } from "@bastani/pi-ai/compat";
|
|
88320
88693
|
|
|
88694
|
+
// dist/builtin/workflows/src/extension/workflow-status-digest.ts
|
|
88695
|
+
function promptMessage(prompt, request) {
|
|
88696
|
+
return prompt === undefined ? request?.questions[0]?.question : prompt.message;
|
|
88697
|
+
}
|
|
88698
|
+
function blockers(detail) {
|
|
88699
|
+
if (["completed", "skipped", "cancelled", "killed"].includes(detail.status))
|
|
88700
|
+
return [];
|
|
88701
|
+
const entries = [];
|
|
88702
|
+
for (const stage of detail.stages) {
|
|
88703
|
+
const awaitingInput = stage.status === "awaiting_input" || stage.pendingPrompt !== undefined || stage.inputRequest !== undefined;
|
|
88704
|
+
if (!awaitingInput && stage.status !== "failed" && stage.status !== "blocked")
|
|
88705
|
+
continue;
|
|
88706
|
+
const message = awaitingInput ? promptMessage(stage.pendingPrompt, stage.inputRequest) : stage.error;
|
|
88707
|
+
const promptId = stage.pendingPrompt?.id ?? stage.inputRequest?.id;
|
|
88708
|
+
entries.push({
|
|
88709
|
+
kind: awaitingInput ? "awaiting_input" : stage.status === "failed" ? "failed" : "blocked",
|
|
88710
|
+
node: "stage",
|
|
88711
|
+
id: stage.id,
|
|
88712
|
+
name: stage.name,
|
|
88713
|
+
...promptId === undefined ? {} : { promptId },
|
|
88714
|
+
...message === undefined ? {} : { message }
|
|
88715
|
+
});
|
|
88716
|
+
}
|
|
88717
|
+
for (const tool of detail.tools) {
|
|
88718
|
+
if (tool.status !== "failed")
|
|
88719
|
+
continue;
|
|
88720
|
+
entries.push({
|
|
88721
|
+
kind: "failed",
|
|
88722
|
+
node: "tool",
|
|
88723
|
+
id: tool.id,
|
|
88724
|
+
name: tool.name,
|
|
88725
|
+
...tool.error === undefined ? {} : { message: tool.error }
|
|
88726
|
+
});
|
|
88727
|
+
}
|
|
88728
|
+
return entries;
|
|
88729
|
+
}
|
|
88730
|
+
function buildWorkflowRunStatusDigest(detail) {
|
|
88731
|
+
return {
|
|
88732
|
+
runId: detail.runId,
|
|
88733
|
+
name: detail.name,
|
|
88734
|
+
status: detail.status,
|
|
88735
|
+
startedAt: detail.startedAt,
|
|
88736
|
+
...detail.endedAt === undefined ? {} : { endedAt: detail.endedAt },
|
|
88737
|
+
...detail.durationMs === undefined ? {} : { durationMs: detail.durationMs },
|
|
88738
|
+
...detail.result === undefined ? {} : { result: detail.result },
|
|
88739
|
+
...detail.error === undefined ? {} : { error: detail.error },
|
|
88740
|
+
...detail.exitReason === undefined ? {} : { exitReason: detail.exitReason },
|
|
88741
|
+
...detail.resumable === undefined ? {} : { resumable: detail.resumable },
|
|
88742
|
+
...detail.resumeGuidance === undefined ? {} : { resumeGuidance: detail.resumeGuidance },
|
|
88743
|
+
...detail.ownerActiveElsewhere === true ? { ownerActiveElsewhere: true } : {},
|
|
88744
|
+
blockers: blockers(detail)
|
|
88745
|
+
};
|
|
88746
|
+
}
|
|
88747
|
+
|
|
88321
88748
|
// dist/builtin/workflows/src/extension/workflow-status-summary.ts
|
|
88322
88749
|
var workflowStatusRenderRuns = new WeakMap;
|
|
88323
88750
|
function setWorkflowStatusRenderRuns(result, runs) {
|
|
@@ -88332,7 +88759,7 @@ function stageIsActive(stage) {
|
|
|
88332
88759
|
function stageAwaitingInput(stage) {
|
|
88333
88760
|
return stage.status === "awaiting_input" || stage.awaitingInputSince !== undefined || stage.pendingPrompt !== undefined || stage.inputRequest !== undefined;
|
|
88334
88761
|
}
|
|
88335
|
-
function
|
|
88762
|
+
function promptMessage2(prompt, request) {
|
|
88336
88763
|
if (prompt !== undefined)
|
|
88337
88764
|
return prompt.message;
|
|
88338
88765
|
return request?.questions[0]?.question;
|
|
@@ -88354,7 +88781,7 @@ function awaitingInputEntries(run) {
|
|
|
88354
88781
|
stageName: stage.name,
|
|
88355
88782
|
promptId: stage.pendingPrompt?.id ?? stage.inputRequest?.id,
|
|
88356
88783
|
promptKind: stage.pendingPrompt?.kind ?? stage.inputRequest?.kind,
|
|
88357
|
-
message:
|
|
88784
|
+
message: promptMessage2(stage.pendingPrompt, stage.inputRequest)
|
|
88358
88785
|
};
|
|
88359
88786
|
entries.push(entry);
|
|
88360
88787
|
}
|
|
@@ -88866,6 +89293,7 @@ function renderWorkflowToolContent(result, args) {
|
|
|
88866
89293
|
return renderStatusToolContent(result);
|
|
88867
89294
|
case "list":
|
|
88868
89295
|
case "statusDetail":
|
|
89296
|
+
case "statusSummary":
|
|
88869
89297
|
case "inputs":
|
|
88870
89298
|
case "get":
|
|
88871
89299
|
case "run":
|
|
@@ -89923,7 +90351,13 @@ function makeExecuteWorkflowTool(runtime, reloadWorkflowResources, ensureWorkflo
|
|
|
89923
90351
|
const durable = await awaitRequest(getRuntime().inspectDurableWorkflow(target));
|
|
89924
90352
|
if (durable.kind === "found")
|
|
89925
90353
|
await authorize(durable.detail.runId);
|
|
89926
|
-
|
|
90354
|
+
if (durable.kind !== "found")
|
|
90355
|
+
return { action: "statusDetail", runId: target, error: durable.message };
|
|
90356
|
+
return args.summary === true ? {
|
|
90357
|
+
action: "statusSummary",
|
|
90358
|
+
runId: durable.detail.runId,
|
|
90359
|
+
summary: buildWorkflowRunStatusDigest(durable.detail)
|
|
90360
|
+
} : { action: "statusDetail", runId: durable.detail.runId, detail: durable.detail };
|
|
89927
90361
|
}
|
|
89928
90362
|
if (!isResolvedRunId(resolved)) {
|
|
89929
90363
|
return { action: "statusDetail", runId: target, error: `run not found: ${target}` };
|
|
@@ -89933,6 +90367,13 @@ function makeExecuteWorkflowTool(runtime, reloadWorkflowResources, ensureWorkflo
|
|
|
89933
90367
|
if (!inspected.ok) {
|
|
89934
90368
|
return { action: "statusDetail", runId: target, error: `run not found: ${target}` };
|
|
89935
90369
|
}
|
|
90370
|
+
if (args.summary === true) {
|
|
90371
|
+
return {
|
|
90372
|
+
action: "statusSummary",
|
|
90373
|
+
runId: inspected.runId,
|
|
90374
|
+
summary: buildWorkflowRunStatusDigest(inspected.detail)
|
|
90375
|
+
};
|
|
90376
|
+
}
|
|
89936
90377
|
const detailResult = {
|
|
89937
90378
|
action: "statusDetail",
|
|
89938
90379
|
runId: inspected.runId,
|
|
@@ -90097,6 +90538,18 @@ function renderNotice(title, message, opts, themed) {
|
|
|
90097
90538
|
width
|
|
90098
90539
|
});
|
|
90099
90540
|
}
|
|
90541
|
+
function statusDigestNoticeText(digest) {
|
|
90542
|
+
const lines = [`${digest.name} ${digest.runId}: ${digest.status}`];
|
|
90543
|
+
if (digest.error !== undefined)
|
|
90544
|
+
lines.push(`error: ${digest.error}`);
|
|
90545
|
+
if (digest.result !== undefined)
|
|
90546
|
+
lines.push(`result: ${JSON.stringify(digest.result)}`);
|
|
90547
|
+
for (const blocker of digest.blockers) {
|
|
90548
|
+
lines.push(`${blocker.kind}: ${blocker.name}${blocker.message === undefined ? "" : ` — ${blocker.message}`}`);
|
|
90549
|
+
}
|
|
90550
|
+
return lines.join(`
|
|
90551
|
+
`);
|
|
90552
|
+
}
|
|
90100
90553
|
var TRANSCRIPT_NOTICE_ENTRY_LIMIT = 5;
|
|
90101
90554
|
var TRANSCRIPT_NOTICE_CHAR_LIMIT = 240;
|
|
90102
90555
|
function transcriptEntriesNoticeText(entries) {
|
|
@@ -90154,6 +90607,10 @@ function renderResultBody(result, opts) {
|
|
|
90154
90607
|
resolveBoundarySegments: (runId) => workflowBoundarySegments(allRuns, runId)
|
|
90155
90608
|
});
|
|
90156
90609
|
}
|
|
90610
|
+
case "statusSummary": {
|
|
90611
|
+
const { summary } = result;
|
|
90612
|
+
return renderNotice("WORKFLOW STATUS", statusDigestNoticeText(summary), opts, themed);
|
|
90613
|
+
}
|
|
90157
90614
|
case "statusDetail": {
|
|
90158
90615
|
if ("error" in result) {
|
|
90159
90616
|
const r = result;
|
|
@@ -90289,7 +90746,7 @@ function renderResultBody(result, opts) {
|
|
|
90289
90746
|
|
|
90290
90747
|
// dist/builtin/workflows/src/extension/workflow-prompts.ts
|
|
90291
90748
|
var WORKFLOW_SELECTION_GUIDANCE = "Unless the user explicitly chooses inline execution for this task, treat workflows as the default execution path for non-trivial tasks and requests with structure and a verifiable objective. Decide yourself whether a workflow fits the request. Use one for well-defined, authorized work that benefits from durable stages, checkpoints, dependencies, recovery, review loops or deliberate approval gates. Work inline for brainstorming, discussion, unclear goals, tiny deterministic low-risk answers or edits where tracking costs more than it adds, or when the user asks to work inline, directly, quickly or without a workflow. Judge the task's shape first, then refine the call with execution history and the user's stated or recorded preferences; missing, sparse, or mostly inline workflow history is not by itself a reason to work inline. Honor an explicit user request for a named workflow. To launch, inspect candidates with list/get/inputs, then call workflow run with the registered workflow name and inputs matching its input contract. Ask only for genuinely missing information.";
|
|
90292
|
-
var WORKFLOW_TOOL_DESCRIPTION = WORKFLOW_SELECTION_GUIDANCE + " " + "Run starts the named workflow and returns its runId; invalid inputs fail without launching. User /workflow commands launch directly and authored ctx.workflow(...) remains internal composition. " + "When workflow execution fits but another shape would better achieve the task, author a custom TypeScript workflow({...}) inline with normal coding tools, reload it, and run it; after successfully creating and reloading a newly authored custom workflow, report the folder containing its generated code as 'Custom workflow created. You can inspect its code at: <workflow-folder-path>'; do this only for newly created custom workflows, never builtin or pre-existing workflows; " + "discover with list/get/inputs/models, list session runs with status (no runId; statusFilter narrows the list), inspect status/stages/stage details, " + "answer pending prompts only while the root workflow is nonterminal, pause/resume/quit runs, and reload workflow resources. " + "When steering or communication is useful, use Intercom. Before steering a stage, join its invocation group. Use the Intercom `groups` action to discover it. Workflow invocation groups are named `workflow:<rootRunId>`. Then address the stage as `workflow:<rootRunId>/<segment>[/<segment>...]`; each segment may be a stage name, run id, or glob (`*` matches one segment and `**` any depth). Use `intercom list` inside the invocation group to see live, pending, and possible future targets. Live delivery is immediate; a known stage that has not started is queued and receives the message before its first model turn. Name and pattern sends remain sticky for every future matching stage until the root run terminates. When shared scope or acceptance criteria change, broadcast one authoritative update to `workflow:<rootRunId>/**` (or a narrower path pattern) rather than enumerating stages. A syntactically valid target outside the known set queues with a `notInKnownSet` warning and settles undeliverable at terminal only if never delivered. Use `ask` only for a reply-capable live session. " + "Treat a blocked run as continuable by default unless the user requests inline/no-workflow execution: then safely hold/stop it, reconcile completed work and in-flight side effects, and continue inline without duplication. Otherwise resume resumable blocks, answer pending prompts, steer past the obstacle, or start a follow-up workflow past a terminal block; resolve material ambiguity from user intent and repository evidence without bypassing safety or authorization. " + "For action 'run' and 'resume', budget accepts per-field duration, token, cost, and warning overrides; fields resolve over the workflow declaration and config, and 0 disables a field. Pass budget only for a user-specified limit; otherwise omit it and inherit. An estimate is not a budget. " + "For primitive prompt answers, use booleans or the documented confirm labels, exact case-insensitive select labels or 1-based indexes, and text strings for input/editor; an invalid answer remains pending and returns guidance instead of choosing a default. " + "For large stage handoffs, write context to files/artifacts, pass paths via reads, and prompt downstream agents to 'Read the file at <path>...' instead of injecting large previous text. " + "Wrap critical parts of run inputs and steering messages in <keepContext>...</keepContext> so compaction preserves them verbatim in the stages that inherit them; tag role constraints, prohibitions, must-hold criteria, and identifiers, not background or bulk reference material. " + "For transcripts, prefer status/stages/stage to get sessionFile/transcriptPath, " + "quote the exact path without rewriting separators (Windows backslashes are valid), " + "then search it with rg/grep and read small ranges; transcript is path-only by default when sessionFile/transcriptPath exists, explicit tail/limit returns bounded previews, and missing transcript paths fall back to a small preview. " + "Use action 'models' to inspect models in the configured catalog; the result is a configured-auth snapshot showing what's present in the registry with configured authentication, not proof of credentials, entitlements, OAuth freshness, or live provider access. " + "When a user delegates best-stage-model selection for a custom workflow, author model:'auto'; runtime selects from the actual interpolated stage prompt and supplied context. Preserve explicit user concrete model/effort and constraints.";
|
|
90749
|
+
var WORKFLOW_TOOL_DESCRIPTION = WORKFLOW_SELECTION_GUIDANCE + " " + "Run starts the named workflow and returns its runId; invalid inputs fail without launching. User /workflow commands launch directly and authored ctx.workflow(...) remains internal composition. " + "When workflow execution fits but another shape would better achieve the task, author a custom TypeScript workflow({...}) inline with normal coding tools, reload it, and run it; after successfully creating and reloading a newly authored custom workflow, report the folder containing its generated code as 'Custom workflow created. You can inspect its code at: <workflow-folder-path>'; do this only for newly created custom workflows, never builtin or pre-existing workflows; " + "discover with list/get/inputs/models, list session runs with status (no runId; statusFilter narrows the list), inspect status/stages/stage details (status with runId includes the final result; add summary:true for just status, result and blockers), " + "answer pending prompts only while the root workflow is nonterminal, pause/resume/quit runs, and reload workflow resources. " + "When steering or communication is useful, use Intercom. Before steering a stage, join its invocation group. Use the Intercom `groups` action to discover it. Workflow invocation groups are named `workflow:<rootRunId>`. Then address the stage as `workflow:<rootRunId>/<segment>[/<segment>...]`; each segment may be a stage name, run id, or glob (`*` matches one segment and `**` any depth). Use `intercom list` inside the invocation group to see live, pending, and possible future targets. Live delivery is immediate; a known stage that has not started is queued and receives the message before its first model turn. Name and pattern sends remain sticky for every future matching stage until the root run terminates. When shared scope or acceptance criteria change, broadcast one authoritative update to `workflow:<rootRunId>/**` (or a narrower path pattern) rather than enumerating stages. A syntactically valid target outside the known set queues with a `notInKnownSet` warning and settles undeliverable at terminal only if never delivered. Use `ask` only for a reply-capable live session. " + "Treat a blocked run as continuable by default unless the user requests inline/no-workflow execution: then safely hold/stop it, reconcile completed work and in-flight side effects, and continue inline without duplication. Otherwise resume resumable blocks, answer pending prompts, steer past the obstacle, or start a follow-up workflow past a terminal block; resolve material ambiguity from user intent and repository evidence without bypassing safety or authorization. " + "For action 'run' and 'resume', budget accepts per-field duration, token, cost, and warning overrides; fields resolve over the workflow declaration and config, and 0 disables a field. Pass budget only for a user-specified limit; otherwise omit it and inherit. An estimate is not a budget. " + "For primitive prompt answers, use booleans or the documented confirm labels, exact case-insensitive select labels or 1-based indexes, and text strings for input/editor; an invalid answer remains pending and returns guidance instead of choosing a default. " + "For large stage handoffs, write context to files/artifacts, pass paths via reads, and prompt downstream agents to 'Read the file at <path>...' instead of injecting large previous text. " + "Wrap critical parts of run inputs and steering messages in <keepContext>...</keepContext> so compaction preserves them verbatim in the stages that inherit them; tag role constraints, prohibitions, must-hold criteria, and identifiers, not background or bulk reference material. " + "For transcripts, prefer status/stages/stage to get sessionFile/transcriptPath, " + "quote the exact path without rewriting separators (Windows backslashes are valid), " + "then search it with rg/grep and read small ranges; transcript is path-only by default when sessionFile/transcriptPath exists, explicit tail/limit returns bounded previews, and missing transcript paths fall back to a small preview. " + "Use action 'models' to inspect models in the configured catalog; the result is a configured-auth snapshot showing what's present in the registry with configured authentication, not proof of credentials, entitlements, OAuth freshness, or live provider access. " + "When a user delegates best-stage-model selection for a custom workflow, author model:'auto'; runtime selects from the actual interpolated stage prompt and supplied context. Preserve explicit user concrete model/effort and constraints.";
|
|
90293
90750
|
var DEFAULT_PROMPT_GUIDANCE = [
|
|
90294
90751
|
WORKFLOW_SELECTION_GUIDANCE,
|
|
90295
90752
|
`**Workflow fit**:
|
|
@@ -90396,7 +90853,7 @@ var WorkflowParametersSchema = Type25.Object({
|
|
|
90396
90853
|
Type25.Literal("resume"),
|
|
90397
90854
|
Type25.Literal("reload")
|
|
90398
90855
|
], {
|
|
90399
|
-
description: "Workflow action: run/list/get/inputs/models/status, inspect stage metadata, answer pending prompts, pause/resume/quit runs, inspect the configured model catalog, or reload workflow resources. 'status' without runId lists every workflow run in the current session with concise per-run summaries (status, timing, active stages, awaiting-input prompts); filter the listing with statusFilter. 'status' with runId returns one run's full detail. For transcript inspection, prefer status/stages/stage first to get sessionFile/transcriptPath, quote the exact path without rewriting separators (Windows backslashes are valid), then search it with rg/grep and read small ranges; transcript is path-only by default when sessionFile/transcriptPath exists, explicit tail/limit returns bounded previews, and missing transcript paths fall back to a small preview."
|
|
90856
|
+
description: "Workflow action: run/list/get/inputs/models/status, inspect stage metadata, answer pending prompts, pause/resume/quit runs, inspect the configured model catalog, or reload workflow resources. 'status' without runId lists every workflow run in the current session with concise per-run summaries (status, timing, active stages, awaiting-input prompts); filter the listing with statusFilter. 'status' with runId returns one run's full detail, including its final outputs (result); add summary:true for a compact form without the stage history. For transcript inspection, prefer status/stages/stage first to get sessionFile/transcriptPath, quote the exact path without rewriting separators (Windows backslashes are valid), then search it with rg/grep and read small ranges; transcript is path-only by default when sessionFile/transcriptPath exists, explicit tail/limit returns bounded previews, and missing transcript paths fall back to a small preview."
|
|
90400
90857
|
})),
|
|
90401
90858
|
runId: Type25.Optional(Type25.String({
|
|
90402
90859
|
description: "Full 36-character run UUID or unique 8-character hexadecimal UUID prefix for status/stages/stage/transcript/answer/pause/resume/quit. Other truncated forms are rejected; ambiguous prefixes require the full UUID. Omit runId with action 'status' to list all session runs and their statuses. Use '--all' or all:true for supported bulk run-control actions."
|
|
@@ -90425,6 +90882,9 @@ var WorkflowParametersSchema = Type25.Object({
|
|
|
90425
90882
|
], {
|
|
90426
90883
|
description: "Filter stages (stages action) or listed runs (status action without runId) by status; 'all' (default) includes everything. For the status listing, run statuses match directly, 'awaiting_input' selects runs with at least one stage awaiting input or pending human prompt, and in-flight runs are listed first."
|
|
90427
90884
|
})),
|
|
90885
|
+
summary: Type25.Optional(Type25.Boolean({
|
|
90886
|
+
description: "Status with runId only: return the run's status, final outputs (result), error and blockers (failed, blocked or awaiting-input stages and tools) without the full stage and tool history. Use it to read what a finished run produced, including a run started by another session."
|
|
90887
|
+
})),
|
|
90428
90888
|
format: Type25.Optional(Type25.Union([Type25.Literal("text"), Type25.Literal("json")], {
|
|
90429
90889
|
description: "Agent-visible output format for data-bearing inspection actions (models, status, stages, stage, transcript); 'json' returns the full structured result."
|
|
90430
90890
|
})),
|
|
@@ -90602,9 +91062,15 @@ function factory(pi) {
|
|
|
90602
91062
|
};
|
|
90603
91063
|
}
|
|
90604
91064
|
const liveGeneration = trackLiveHostGeneration(pi);
|
|
91065
|
+
let hostSessionContext;
|
|
91066
|
+
pi.on?.("session_start", (_event, ctx) => {
|
|
91067
|
+
hostSessionContext = ctx;
|
|
91068
|
+
});
|
|
91069
|
+
const ownerSessionClosing = () => (hostSessionContext?.getCurrentSessionSignal?.() ?? hostSessionContext?.sessionSignal)?.aborted === true;
|
|
90605
91070
|
const adapters = buildRuntimeAdapters(pi, {
|
|
90606
91071
|
resolveSurface: () => liveGeneration()?.pi ?? pi,
|
|
90607
|
-
stageUiBroker: runState.stageUiBroker
|
|
91072
|
+
stageUiBroker: runState.stageUiBroker,
|
|
91073
|
+
ownerSessionClosing
|
|
90608
91074
|
});
|
|
90609
91075
|
const runtimeState = createWorkflowExtensionRuntimeState(pi, adapters, {
|
|
90610
91076
|
resolveLiveModelContext: () => liveGeneration()?.modelContext,
|
|
@@ -90619,11 +91085,13 @@ function factory(pi) {
|
|
|
90619
91085
|
const postMortemHandleResolver = createPostMortemHandleResolver(postMortemResolverDeps);
|
|
90620
91086
|
const disposeCompletedRoutes = registerCompletedStageIntercomAskRouter(pi, postMortemHandleResolver);
|
|
90621
91087
|
const disposePendingRoutes = registerPendingStageIntercomBridge(pi, store);
|
|
91088
|
+
const disposeReleasedRoutes = registerReleasedStageIntercomRoutes(pi, runState.stageControlRegistry, store, postMortemHandleResolver);
|
|
90622
91089
|
pi.on?.("session_start", (_event, ctx) => {
|
|
90623
91090
|
if (!ctx)
|
|
90624
91091
|
return;
|
|
90625
91092
|
registerExtensionContextRetirementEffect3(ctx, disposeCompletedRoutes);
|
|
90626
91093
|
registerExtensionContextRetirementEffect3(ctx, disposePendingRoutes);
|
|
91094
|
+
registerExtensionContextRetirementEffect3(ctx, disposeReleasedRoutes);
|
|
90627
91095
|
});
|
|
90628
91096
|
const overlay = buildWorkflowOverlay(pi, owner, postMortemHandleResolver, () => adapters.sessionStore);
|
|
90629
91097
|
const workflowCommands = new Map;
|