@tangle-network/agent-app 0.60.70 → 0.60.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-routes/index.js +4 -4
- package/dist/{chunk-JC7YSRBR.js → chunk-ISP6ZH3G.js} +8 -3
- package/dist/chunk-ISP6ZH3G.js.map +1 -0
- package/dist/{chunk-GIJZAJ5W.js → chunk-MBEJPQW6.js} +19 -11
- package/dist/{chunk-GIJZAJ5W.js.map → chunk-MBEJPQW6.js.map} +1 -1
- package/dist/{chunk-SH56N4PV.js → chunk-QE2NXMDZ.js} +2 -2
- package/dist/{chunk-5V6VTO5Q.js → chunk-Z4RD5UF7.js} +8 -2
- package/dist/chunk-Z4RD5UF7.js.map +1 -0
- package/dist/public-consultation/index.js +3 -3
- package/dist/sandbox/index.js +1 -1
- package/dist/stream/index.js +4 -2
- package/dist/stream/orphaned-turns.d.ts +2 -0
- package/dist/stream/turn-buffer.d.ts +2 -0
- package/dist/turn-stream/index.js +1 -1
- package/dist/workspace-export/index.d.ts +1 -0
- package/dist/workspace-export/index.js +29 -1
- package/dist/workspace-export/index.js.map +1 -1
- package/dist/workspace-export/sandbox.d.ts +38 -0
- package/package.json +1 -1
- package/dist/chunk-5V6VTO5Q.js.map +0 -1
- package/dist/chunk-JC7YSRBR.js.map +0 -1
- /package/dist/{chunk-SH56N4PV.js.map → chunk-QE2NXMDZ.js.map} +0 -0
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
createBufferedTurnTap,
|
|
30
30
|
replayTurnEvents,
|
|
31
31
|
stampReplaySeq
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-ISP6ZH3G.js";
|
|
33
33
|
|
|
34
34
|
// src/chat-routes/draft-persistence.ts
|
|
35
35
|
var CONTENT_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
@@ -1186,4 +1186,4 @@ export {
|
|
|
1186
1186
|
createChatTurnRoutes,
|
|
1187
1187
|
streamChatRouteAsSandboxEvents
|
|
1188
1188
|
};
|
|
1189
|
-
//# sourceMappingURL=chunk-
|
|
1189
|
+
//# sourceMappingURL=chunk-QE2NXMDZ.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_RUNNING_TURN_LEASE_MS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ISP6ZH3G.js";
|
|
4
4
|
|
|
5
5
|
// src/stream/turn-observation.ts
|
|
6
6
|
function parseTurnObservation(value) {
|
|
@@ -94,6 +94,7 @@ async function consumeTurnStream(body, options) {
|
|
|
94
94
|
|
|
95
95
|
// src/stream/orphaned-turns.ts
|
|
96
96
|
var ORPHANED_TURN_CODE = "turn.orphaned";
|
|
97
|
+
var FOLLOW_UP_CLAIM_STALE_AFTER_MS = 60 * 6e4;
|
|
97
98
|
var TAIL_EVENTS = 50;
|
|
98
99
|
var DEFAULT_LIMIT = 50;
|
|
99
100
|
async function settleOrphanedTurns(options) {
|
|
@@ -106,6 +107,10 @@ async function settleOrphanedTurns(options) {
|
|
|
106
107
|
const settled = [];
|
|
107
108
|
const owned = [];
|
|
108
109
|
for (const turn of stale) {
|
|
110
|
+
if (turn.leaseToken && now - turn.updatedAt < FOLLOW_UP_CLAIM_STALE_AFTER_MS) {
|
|
111
|
+
owned.push(turn.turnId);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
109
114
|
if (options.isOwned && await options.isOwned(turn)) {
|
|
110
115
|
owned.push(turn.turnId);
|
|
111
116
|
continue;
|
|
@@ -154,6 +159,7 @@ export {
|
|
|
154
159
|
observeTurnEvent,
|
|
155
160
|
consumeTurnStream,
|
|
156
161
|
ORPHANED_TURN_CODE,
|
|
162
|
+
FOLLOW_UP_CLAIM_STALE_AFTER_MS,
|
|
157
163
|
settleOrphanedTurns
|
|
158
164
|
};
|
|
159
|
-
//# sourceMappingURL=chunk-
|
|
165
|
+
//# sourceMappingURL=chunk-Z4RD5UF7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/stream/turn-observation.ts","../src/stream/orphaned-turns.ts"],"sourcesContent":["/** Read-side checkpoints for native chat NDJSON. This never submits or cancels work. */\nexport interface TurnObservation {\n schema: 'turn-observation-v1'\n streamId: string | null\n /** Replay ordinals only. Unsequenced live frames cannot advance this cursor. */\n lastSeq: number\n outcome: 'completed' | 'failed' | null\n replayStatus: string | null\n eventCount: number\n}\n\nexport function parseTurnObservation(value?: unknown): TurnObservation {\n if (value === undefined) return {\n schema: 'turn-observation-v1', streamId: null, lastSeq: 0,\n outcome: null, replayStatus: null, eventCount: 0,\n }\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new TypeError('Invalid turn observation')\n const v = value as Record<string, unknown>\n if (v.schema !== 'turn-observation-v1'\n || !(v.streamId === null || (typeof v.streamId === 'string' && /^[A-Za-z0-9_-]+$/.test(v.streamId)))\n || !Number.isSafeInteger(v.lastSeq) || Number(v.lastSeq) < 0\n || !Number.isSafeInteger(v.eventCount) || Number(v.eventCount) < 0\n || !(v.outcome === null || v.outcome === 'completed' || v.outcome === 'failed')\n || !(v.replayStatus === null || typeof v.replayStatus === 'string')\n || (v.streamId === null && Number(v.lastSeq) > 0)) throw new TypeError('Invalid turn observation')\n return {\n schema: 'turn-observation-v1', streamId: v.streamId as string | null,\n lastSeq: Number(v.lastSeq), outcome: v.outcome as TurnObservation['outcome'],\n replayStatus: v.replayStatus as string | null, eventCount: Number(v.eventCount),\n }\n}\n\nexport interface TurnObservationUpdate {\n checkpoint: TurnObservation\n /** False only for an already-checkpointed replay ordinal. */\n accepted: boolean\n event: Record<string, unknown>\n}\n\n/** Reduce an observed frame. Ordered replay gaps are errors, not silent lost work. */\nexport function observeTurnEvent(previous: TurnObservation, raw: unknown): TurnObservationUpdate {\n const checkpoint = parseTurnObservation(previous)\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw new TypeError('Turn frame must be an object')\n const outer = raw as Record<string, unknown>\n const inner = outer.kind === 'event' ? outer.event : outer\n if (!inner || typeof inner !== 'object' || Array.isArray(inner)) throw new TypeError('Invalid turn event envelope')\n const event = inner as Record<string, unknown>\n if (typeof event.type !== 'string' || !event.type) throw new TypeError('Turn frame requires a type')\n\n // Even a duplicate marker must not switch which execution we are observing.\n if (event.type === 'turn') {\n if (typeof event.turnId !== 'string' || !/^[A-Za-z0-9_-]+$/.test(event.turnId)) throw new TypeError('Invalid stream identity')\n if (checkpoint.streamId !== null && checkpoint.streamId !== event.turnId) throw new Error('Replay stream identity changed')\n checkpoint.streamId = event.turnId\n }\n const seq = outer.seq\n if (seq !== undefined && seq !== -1) {\n if (!Number.isSafeInteger(seq) || Number(seq) < 1) throw new TypeError('Invalid replay ordinal')\n if (checkpoint.streamId === null) throw new Error('Replay ordinal arrived before stream identity')\n if (Number(seq) <= checkpoint.lastSeq) return { checkpoint, accepted: false, event }\n if (Number(seq) !== checkpoint.lastSeq + 1) throw new Error('Replay has a gap; retain the checkpoint and inspect durable history')\n checkpoint.lastSeq = Number(seq)\n } else if (seq === -1 && event.type !== 'turn_status') {\n throw new TypeError('Only a turn-status sentinel may have ordinal -1')\n }\n\n if (event.type === 'error' || event.type === 'session.run.failed') checkpoint.outcome = 'failed'\n if (event.type === 'session.run.completed' && checkpoint.outcome !== 'failed') checkpoint.outcome = 'completed'\n if (event.type === 'turn_status') {\n if (typeof event.status !== 'string') throw new TypeError('Turn status requires a value')\n checkpoint.replayStatus = event.status\n if (['error', 'failed', 'aborted', 'cancelled'].includes(event.status)) checkpoint.outcome = 'failed'\n if (['complete', 'completed'].includes(event.status) && checkpoint.outcome !== 'failed') checkpoint.outcome = 'completed'\n }\n checkpoint.eventCount += 1\n return { checkpoint, accepted: true, event }\n}\n\nexport interface ConsumeTurnStreamOptions {\n checkpoint?: TurnObservation\n /** Commit evidence and its checkpoint durably before acknowledging this frame. */\n commit(update: TurnObservationUpdate): Promise<void>\n /** Bound untrusted frame memory, not total run duration or total transcript size. */\n maxFrameBytes?: number\n}\n\n/**\n * Consume one viewing connection. EOF without a terminal event stays incomplete.\n * A disconnect/abort propagates; the last committed checkpoint remains resumable.\n * The caller owns network observation windows separately from execution deadlines.\n */\nexport async function consumeTurnStream(\n body: AsyncIterable<Uint8Array>,\n options: ConsumeTurnStreamOptions,\n): Promise<TurnObservation> {\n const maxFrameBytes = options.maxFrameBytes ?? 4 * 1024 * 1024\n if (!Number.isSafeInteger(maxFrameBytes) || maxFrameBytes < 1) throw new RangeError('Frame byte limit must be positive')\n let state = parseTurnObservation(options.checkpoint)\n const decoder = new TextDecoder('utf-8', { fatal: true })\n let pending = ''\n let frameBytes = 0\n async function accept(line: string): Promise<void> {\n if (!line.trim()) return\n const update = observeTurnEvent(state, JSON.parse(line))\n if (update.accepted) await options.commit(update)\n state = update.checkpoint\n }\n for await (const chunk of body) {\n // Count bytes before decoding: a malicious unterminated frame cannot grow\n // without bound, and splitting UTF-8 characters across chunks stays valid.\n let start = 0\n for (let end = 0; end < chunk.length; end += 1) {\n if (chunk[end] !== 10) continue\n frameBytes += end - start\n if (frameBytes > maxFrameBytes) throw new RangeError('Turn frame exceeds byte limit')\n pending += decoder.decode(chunk.subarray(start, end + 1), { stream: true })\n await accept(pending)\n pending = ''; frameBytes = 0; start = end + 1\n }\n frameBytes += chunk.length - start\n if (frameBytes > maxFrameBytes) throw new RangeError('Turn frame exceeds byte limit')\n pending += decoder.decode(chunk.subarray(start), { stream: true })\n }\n pending += decoder.decode()\n await accept(pending)\n return state\n}\n","/**\n * Settle turn streams whose owner is gone.\n *\n * A running turn row is a lease: the buffer renews it every 30 s while a\n * producer lives, and a durable observer renews it on each pass. A row nothing\n * renewed past its lease has no producer left; the Worker that streamed it\n * died. Left alone it stays `running` forever: a reconnecting client waits on\n * it, discovery offers it, and reports count it as in flight. On 2026-10-10\n * GTM held 51 such rows, some for hours, and its failure notices arrived 8–11 h\n * after the turns had stopped.\n *\n * {@link settleOrphanedTurns} ends each one the way the buffer ends a failed\n * turn: a terminal `error` event naming the phase it stopped in, then status\n * `error`, written only while the row is still running and still stale, and\n * without moving its update time (reports place a stream by it). It returns\n * each turn's detection lag, the time from its lease expiring to this\n * settlement, so a product can report how late it noticed. Run it from its own\n * scheduled invocation at least every 15 minutes.\n */\nimport { DEFAULT_RUNNING_TURN_LEASE_MS, type BufferedTurnEvent, type StaleRunningTurn, type TurnEventStore } from './turn-buffer'\n\n/** The failure code carried by the terminal event of a settled orphan. */\nexport const ORPHANED_TURN_CODE = 'turn.orphaned'\n\n/** A plan follow-up claim's own staleness (`createD1PlanFollowUpGate`): it does not renew, and its gate re-admits it after this. */\nexport const FOLLOW_UP_CLAIM_STALE_AFTER_MS = 60 * 60_000\n\n/** How many tail events are read to name the phase a turn stopped in. */\nconst TAIL_EVENTS = 50\nconst DEFAULT_LIMIT = 50\n\nexport interface SettleOrphanedTurnsOptions {\n store: TurnEventStore\n now?: number\n /** A row older than this since its last renewal is orphaned. Default the running lease, 5 minutes. */\n staleAfterMs?: number\n /** Most rows settled per run; the next run takes the rest. Default 50. */\n limit?: number\n /**\n * Whether something still owns this turn although it stopped renewing the\n * row, such as an open completion admission with a live lease. An owned turn\n * is skipped. A product whose durable owner does not renew the row must\n * answer this, or its live turns are settled as orphans.\n */\n isOwned?: (turn: StaleRunningTurn) => Promise<boolean>\n}\n\nexport interface SettledOrphanedTurn {\n turnId: string\n scopeId: string | null\n /** Unix ms the row was last renewed. */\n lastRenewedAt: number\n /** From its lease expiring to this settlement. */\n detectionLagMs: number\n /** The run phase the stream last reported, when it reported one. */\n phase: string | null\n}\n\nexport interface SettleOrphanedTurnsResult {\n settled: SettledOrphanedTurn[]\n /** Stale rows an owner still held. */\n owned: string[]\n /** Most detection lag among the settled turns, in ms. */\n maxDetectionLagMs: number\n}\n\n/** End every running turn stream nothing has renewed past its lease. */\nexport async function settleOrphanedTurns(options: SettleOrphanedTurnsOptions): Promise<SettleOrphanedTurnsResult> {\n const { store } = options\n if (!store.listStaleRunning) throw new Error('settleOrphanedTurns needs a TurnEventStore with listStaleRunning (the D1 and memory stores have it)')\n const now = options.now ?? Date.now()\n const staleAfterMs = options.staleAfterMs ?? DEFAULT_RUNNING_TURN_LEASE_MS\n const cutoff = now - staleAfterMs\n const stale = await store.listStaleRunning(cutoff, options.limit ?? DEFAULT_LIMIT)\n const settled: SettledOrphanedTurn[] = []\n const owned: string[] = []\n for (const turn of stale) {\n // A follow-up claim does not renew its row; its gate owns it until its own staleness.\n if (turn.leaseToken && now - turn.updatedAt < FOLLOW_UP_CLAIM_STALE_AFTER_MS) {\n owned.push(turn.turnId)\n continue\n }\n if (options.isOwned && await options.isOwned(turn)) {\n owned.push(turn.turnId)\n continue\n }\n const tail = (await store.readTail?.(turn.turnId, TAIL_EVENTS)) ?? []\n const { seq, at, phase } = describeTail(tail)\n await store.append(turn.turnId, [{\n seq: seq + 1,\n event: JSON.stringify({\n type: 'error',\n data: { message: `The turn stopped without finishing during ${phase ?? 'the turn'}. Retry to send it again.`, code: ORPHANED_TURN_CODE, orphaned: true, retryable: true },\n _t: at,\n }),\n }])\n // Only a row still running and still stale: a producer that came back keeps its stream.\n await store.setStatus(turn.turnId, 'error', undefined, { preserveUpdatedAt: true, onlyIfRunningBefore: cutoff })\n settled.push({\n turnId: turn.turnId,\n scopeId: turn.scopeId,\n lastRenewedAt: turn.updatedAt,\n detectionLagMs: Math.max(0, now - (turn.updatedAt + DEFAULT_RUNNING_TURN_LEASE_MS)),\n phase,\n })\n }\n return { settled, owned, maxDetectionLagMs: settled.reduce((max, turn) => Math.max(max, turn.detectionLagMs), 0) }\n}\n\ninterface TailEvent {\n type?: unknown\n _t?: unknown\n data?: { phase?: unknown }\n}\n\nfunction describeTail(tail: readonly BufferedTurnEvent[]): { seq: number; at: number; phase: string | null } {\n let seq = 0\n let at = 0\n let phase: string | null = null\n for (const row of tail) {\n seq = Math.max(seq, row.seq)\n let event: TailEvent | null\n try {\n event = JSON.parse(row.event) as TailEvent | null\n } catch {\n continue\n }\n if (typeof event?._t === 'number') at = Math.max(at, event._t)\n if (phase === null && event?.type === 'session.run.phase' && typeof event.data?.phase === 'string') phase = event.data.phase\n }\n return { seq, at, phase }\n}\n"],"mappings":";;;;;AAWO,SAAS,qBAAqB,OAAkC;AACrE,MAAI,UAAU,OAAW,QAAO;AAAA,IAC9B,QAAQ;AAAA,IAAuB,UAAU;AAAA,IAAM,SAAS;AAAA,IACxD,SAAS;AAAA,IAAM,cAAc;AAAA,IAAM,YAAY;AAAA,EACjD;AACA,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,EAAG,OAAM,IAAI,UAAU,0BAA0B;AAC/G,QAAM,IAAI;AACV,MAAI,EAAE,WAAW,yBACZ,EAAE,EAAE,aAAa,QAAS,OAAO,EAAE,aAAa,YAAY,mBAAmB,KAAK,EAAE,QAAQ,MAC9F,CAAC,OAAO,cAAc,EAAE,OAAO,KAAK,OAAO,EAAE,OAAO,IAAI,KACxD,CAAC,OAAO,cAAc,EAAE,UAAU,KAAK,OAAO,EAAE,UAAU,IAAI,KAC9D,EAAE,EAAE,YAAY,QAAQ,EAAE,YAAY,eAAe,EAAE,YAAY,aACnE,EAAE,EAAE,iBAAiB,QAAQ,OAAO,EAAE,iBAAiB,aACtD,EAAE,aAAa,QAAQ,OAAO,EAAE,OAAO,IAAI,EAAI,OAAM,IAAI,UAAU,0BAA0B;AACnG,SAAO;AAAA,IACL,QAAQ;AAAA,IAAuB,UAAU,EAAE;AAAA,IAC3C,SAAS,OAAO,EAAE,OAAO;AAAA,IAAG,SAAS,EAAE;AAAA,IACvC,cAAc,EAAE;AAAA,IAA+B,YAAY,OAAO,EAAE,UAAU;AAAA,EAChF;AACF;AAUO,SAAS,iBAAiB,UAA2B,KAAqC;AAC/F,QAAM,aAAa,qBAAqB,QAAQ;AAChD,MAAI,CAAC,OAAO,OAAO,QAAQ,YAAY,MAAM,QAAQ,GAAG,EAAG,OAAM,IAAI,UAAU,8BAA8B;AAC7G,QAAM,QAAQ;AACd,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BAAmB,MAAM,qBAAqB,OAAO,CAAC;AAC/G,YAAQ,KAAK;AAAA,MACX,QAAQ,KAAK;AAAA,MACb,SAAS,KAAK;AAAA,MACd,eAAe,KAAK;AAAA,MACpB,gBAAgB,KAAK,IAAI,GAAG,OAAO,KAAK,YAAY,8BAA8B;AAAA,MAClF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,EAAE,SAAS,OAAO,mBAAmB,QAAQ,OAAO,CAAC,KAAK,SAAS,KAAK,IAAI,KAAK,KAAK,cAAc,GAAG,CAAC,EAAE;AACnH;AAQA,SAAS,aAAa,MAAuF;AAC3G,MAAI,MAAM;AACV,MAAI,KAAK;AACT,MAAI,QAAuB;AAC3B,aAAW,OAAO,MAAM;AACtB,UAAM,KAAK,IAAI,KAAK,IAAI,GAAG;AAC3B,QAAI;AACJ,QAAI;AACF,cAAQ,KAAK,MAAM,IAAI,KAAK;AAAA,IAC9B,QAAQ;AACN;AAAA,IACF;AACA,QAAI,OAAO,OAAO,OAAO,SAAU,MAAK,KAAK,IAAI,IAAI,MAAM,EAAE;AAC7D,QAAI,UAAU,QAAQ,OAAO,SAAS,uBAAuB,OAAO,MAAM,MAAM,UAAU,SAAU,SAAQ,MAAM,KAAK;AAAA,EACzH;AACA,SAAO,EAAE,KAAK,IAAI,MAAM;AAC1B;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createChatTurnRoutes,
|
|
3
3
|
streamChatRouteAsSandboxEvents
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-QE2NXMDZ.js";
|
|
5
5
|
import "../chunk-UTAIRVOK.js";
|
|
6
6
|
import "../chunk-RN4WPTBH.js";
|
|
7
7
|
import "../chunk-Q7WEEN7P.js";
|
|
@@ -10,12 +10,12 @@ import "../chunk-JBEFTXDO.js";
|
|
|
10
10
|
import "../chunk-ZVEEWGDK.js";
|
|
11
11
|
import "../chunk-6E7LKHYV.js";
|
|
12
12
|
import "../chunk-TXD5HXLE.js";
|
|
13
|
-
import "../chunk-
|
|
13
|
+
import "../chunk-Z4RD5UF7.js";
|
|
14
14
|
import "../chunk-YG66IHDU.js";
|
|
15
15
|
import "../chunk-XNKLQG26.js";
|
|
16
16
|
import "../chunk-LQYIBL3G.js";
|
|
17
17
|
import "../chunk-6VQCFJWP.js";
|
|
18
|
-
import "../chunk-
|
|
18
|
+
import "../chunk-ISP6ZH3G.js";
|
|
19
19
|
|
|
20
20
|
// src/public-consultation/index.ts
|
|
21
21
|
import { searchKnowledge } from "@tangle-network/agent-knowledge";
|
package/dist/sandbox/index.js
CHANGED
package/dist/stream/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
FOLLOW_UP_CLAIM_STALE_AFTER_MS,
|
|
2
3
|
ORPHANED_TURN_CODE,
|
|
3
4
|
consumeTurnStream,
|
|
4
5
|
observeTurnEvent,
|
|
5
6
|
parseTurnObservation,
|
|
6
7
|
settleOrphanedTurns
|
|
7
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-Z4RD5UF7.js";
|
|
8
9
|
import {
|
|
9
10
|
buildUserTextParts,
|
|
10
11
|
messageHasTurnId,
|
|
@@ -51,10 +52,11 @@ import {
|
|
|
51
52
|
pumpBufferedTurn,
|
|
52
53
|
replayTurnEvents,
|
|
53
54
|
stampReplaySeq
|
|
54
|
-
} from "../chunk-
|
|
55
|
+
} from "../chunk-ISP6ZH3G.js";
|
|
55
56
|
export {
|
|
56
57
|
DEFAULT_RUNNING_TURN_LEASE_MS,
|
|
57
58
|
DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,
|
|
59
|
+
FOLLOW_UP_CLAIM_STALE_AFTER_MS,
|
|
58
60
|
MISSING_TOOL_TERMINAL_ERROR,
|
|
59
61
|
MISSING_TOOL_TERMINAL_REASON,
|
|
60
62
|
ORPHANED_TURN_CODE,
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
import { type StaleRunningTurn, type TurnEventStore } from './turn-buffer';
|
|
21
21
|
/** The failure code carried by the terminal event of a settled orphan. */
|
|
22
22
|
export declare const ORPHANED_TURN_CODE = "turn.orphaned";
|
|
23
|
+
/** A plan follow-up claim's own staleness (`createD1PlanFollowUpGate`): it does not renew, and its gate re-admits it after this. */
|
|
24
|
+
export declare const FOLLOW_UP_CLAIM_STALE_AFTER_MS: number;
|
|
23
25
|
export interface SettleOrphanedTurnsOptions {
|
|
24
26
|
store: TurnEventStore;
|
|
25
27
|
now?: number;
|
|
@@ -71,6 +71,8 @@ export interface StaleRunningTurn {
|
|
|
71
71
|
scopeId: string | null;
|
|
72
72
|
/** Unix ms of the last status write. */
|
|
73
73
|
updatedAt: number;
|
|
74
|
+
/** Set on a plan follow-up claim (`createD1PlanFollowUpGate`), which keeps its own staleness and does not renew. */
|
|
75
|
+
leaseToken?: string | null;
|
|
74
76
|
}
|
|
75
77
|
/**
|
|
76
78
|
* Settling a stream nothing produces any more. A sweep that ends an orphaned
|
|
@@ -12,5 +12,6 @@ export { createExportEngine, MANIFEST_SCHEMA, type ExportEngine, type ExportEngi
|
|
|
12
12
|
export { createR2ExportStorage, createMemoryExportStorage, type ExportStorage, type R2ExportBucket } from './storage';
|
|
13
13
|
export { d1WorkspaceTables, type D1ExportDatabase, type D1TableCoverage, type D1WorkspaceTablesOptions } from './d1';
|
|
14
14
|
export { r2Files, kvFiles, type R2FilesBucket, type KVFilesNamespace } from './sources';
|
|
15
|
+
export { sandboxArchive, type ArchivableBox } from './sandbox';
|
|
15
16
|
export { createSecretScanner, isSecretName, isCredentialFile, REDACTED, type SecretScanner } from './secrets';
|
|
16
17
|
export type { ExportArchiveSource, ExportDataClass, ExportFile, ExportFilesSource, ExportJob, ExportJsonSource, ExportPlan, ExportPrincipal, ExportProgress, ExportRow, ExportRowsSource, ExportSource, ExportStatus, ExportUnit, StoredEntry, UnitStatus, } from './types';
|
|
@@ -1476,6 +1476,33 @@ function kvFiles(args) {
|
|
|
1476
1476
|
}
|
|
1477
1477
|
};
|
|
1478
1478
|
}
|
|
1479
|
+
|
|
1480
|
+
// src/workspace-export/sandbox.ts
|
|
1481
|
+
var GONE = /* @__PURE__ */ new Set(["deleted", "expired", "failed"]);
|
|
1482
|
+
function sandboxArchive(args) {
|
|
1483
|
+
return {
|
|
1484
|
+
kind: "archive",
|
|
1485
|
+
name: args.name,
|
|
1486
|
+
dataClass: args.dataClass ?? "sandbox",
|
|
1487
|
+
description: args.description,
|
|
1488
|
+
async open() {
|
|
1489
|
+
const box = await args.getBox();
|
|
1490
|
+
if (!box || GONE.has(box.status)) return null;
|
|
1491
|
+
const wasStopped = box.status === "stopped";
|
|
1492
|
+
if (wasStopped) await box.resume();
|
|
1493
|
+
if (box.status !== "running" || wasStopped) await box.waitFor("running", { timeoutMs: args.resumeTimeoutMs ?? 12e4 });
|
|
1494
|
+
const archive = await box.fs.openArchive(args.dir ?? ".");
|
|
1495
|
+
if (!wasStopped || !box.stop) return archive;
|
|
1496
|
+
const restore = () => box.stop().catch(() => {
|
|
1497
|
+
});
|
|
1498
|
+
return archive.pipeThrough(
|
|
1499
|
+
new TransformStream({
|
|
1500
|
+
flush: () => restore()
|
|
1501
|
+
})
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1479
1506
|
export {
|
|
1480
1507
|
MANIFEST_SCHEMA,
|
|
1481
1508
|
REDACTED,
|
|
@@ -1488,6 +1515,7 @@ export {
|
|
|
1488
1515
|
isCredentialFile,
|
|
1489
1516
|
isSecretName,
|
|
1490
1517
|
kvFiles,
|
|
1491
|
-
r2Files
|
|
1518
|
+
r2Files,
|
|
1519
|
+
sandboxArchive
|
|
1492
1520
|
};
|
|
1493
1521
|
//# sourceMappingURL=index.js.map
|